Archived

This topic is now archived and is closed to further replies.

Do all HeightMapped terrains have Artifacts??

This topic is 4942 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi! i got a nice little scale height map terrain rendering system. Yesterday i implemented repeating textures on it, but i now when i take a closer look on my terrain system i see strange artifacts. There are more triangles being rendered above & below actual terrain. I have implemented many variations, like i first implemented the idea given at TwoKings tutorial then in the book "Introduction To Game Programming with DX9" but all give me those errors. If i disable culling i get very clearly seen distortion in my terrain please help it out. See the screen shot here: http://www.geocities.com/darkengine2d/terrainerror.jpg

Share this post


Link to post
Share on other sites
You need a z-buffer. A z-buffer will organize your polygons so that they''re drawn back-to-front (the proper way).

When you''re filling in your presentation paremeters, make sure you add one like so:


m_D3DPresentationParameters.AutoDepthStencilFormat = D3DFMT_D16;
m_D3DPresentationParameters.EnableAutoDepthStencil = TRUE;


Then enable it before drawing your heightmap.


pD3DDevice->SetRenderState(D3DRS_ZENABLE, TRUE);
pD3DDevice->SetRenderState(D3DRS_ZWRITEENABLE, TRUE);


And don''t forget to clear it when you''re clearing your scene.


pD3DDevice->Clear(0,0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);


Should fix that right up.




Share this post


Link to post
Share on other sites
Did you create one during initialisation when you filled in your presentation parameters too?

If you did, I have no idea then. That just SCREAMS z-buffer / z-fighting to me.

[edited by - GroZZleR on May 29, 2004 3:05:24 PM]

Share this post


Link to post
Share on other sites
Well, two things, first, are those other things multitextured? because that could do it i think, second, i have a radeon, and for wahtever reason, i get artifacts similar to that when playing ut2003, my friend on a geforce (a much lesser geforce i might add) does not get those same artifacts, maybe its got something to do with your card (oh by the way i think it was only with the dx implementation but im not sure)
-Dan

Share this post


Link to post
Share on other sites
Hi there,

unfortunately, the link to the screenshot isn't working, so I can only guess what your problem might be. What are your near/far plane settings? try to increase the near plane and see if that would help. If it doesn't, try using a 32 bit depth buffer.

So long!

[edited by - IH82W8 on May 30, 2004 5:09:44 AM]

Share this post


Link to post
Share on other sites
Are you multi-texturing that terrain? It looks like you might be rendering the terrain in more than one pass, using the same geometry but different textures. Have you tried one pass rendering? Perhaps some code or a link to a demo might be easier for people to see what''s going on.

---------------------------------------

Let''s struggle for our dream of Game!

http://andrewporritt.4t.com

Share this post


Link to post
Share on other sites
I''ve had a look, and it looks like when you''re drawing your triangles for your terrain and water, you are drawing too many traingles. The terrain and water look fine, except that around two sides, extra triangles are being drawn from the side to a point in the center (On my PC at least).


|--------------|
|\ /|
| \ / |
| \ / |
| \/ |
| \ |
| \ |
| \ |
| \|
|--------------|

The triangles come in from the sides like shown above, so it looks as if maybe when you generate your index buffer you are adding an extra row and column to your heightmap or providing some invalid vertex information.

Apart from that, it''s looking good. You could maybe turn texture filtering on, and say I stand at one corner of the map and look at the other, there is some z-fighting where the two walls of the valley meet. You might be able to fix this by tweaking the near and far z-clipping planes. Also, a wider FOV would make things easier to see, and if you run backwards you go really fast.

---------------------------------------

Let''s struggle for our dream of Game!

http://andrewporritt.4t.com

Share this post


Link to post
Share on other sites
Thanks for the info, very keen eyes indeed. Really it's the problem, more indices than needed, the run from one corner to another, on my PC also. So here's my index buffer filling loop:


bool HMapTerrain::ComputeIndices()
{
HRESULT hr = NULL;

hr = mpD3DDevice->CreateIndexBuffer( mNumTriangles * 3 *
sizeof(WORD), // 3 indices per triangle

D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED,
&mpIndexBuffer, 0 );

if ( FAILED( hr ) )
return false;

WORD* Indices = NULL;

hr = mpIndexBuffer->Lock( 0, 0, (void**)&Indices, 0 );

if ( FAILED( hr ) )
return false;
// index to start of a group of 6 indices that describe the

// two triangles that make up a quad

int baseIndex = 0;

// loop through and compute the triangles of each quad

for ( int i = 0; i < mNumCellsPerColumn; i++ )
{
for( int j = 0; j < mNumCellsPerRow; j++ )
{
Indices[baseIndex] = i * mNumVertsPerRow + j;
Indices[baseIndex + 1] = i * mNumVertsPerRow + j + 1;
Indices[baseIndex + 2] = (i+1) * mNumVertsPerRow + j;

Indices[baseIndex + 3] = (i+1) * mNumVertsPerRow + j;
Indices[baseIndex + 4] = i * mNumVertsPerRow + j + 1;
Indices[baseIndex + 5] = (i+1) * mNumVertsPerRow + j +1;
// next quad

baseIndex += 6;
}
}
hr = mpIndexBuffer->Unlock();

if( FAILED( hr ) )
return false;

return true;
}


This terrain system was implemented by following the one in book "Intro to Game Programming with DX" i thought my Terrain system is false, so i copied the system in that book it also got the same errors, i think the authors don't have much time testing their demo's.

Now i have Linear texture filter on, you want anisotropic? and i have 5000 as max draw distance, coz any lesser than this would clip my sky boxes. here's my projection matrix settings:
D3DXMatrixPerspectiveFovLH( &mD3DMatProj, D3DX_PI/4, 1.0f, 1.0f, 5000 );

Is there any other recommended setting for FOV?? in every book they say these are the common one, i haven't played with these settings much except max ZDistance, so i will give it a shot.
And fast back travelling is also removed.
Thanks for such nice comments apart from terrain f8k8 also, actually in so much intense engine programming i have little time to tweak my demo, some one joined me as demo programmer, he will use my engine to write show off demo's so i might have full time for engine only, this will fix things up.

For one's who have seen old demo here's new one which has a thunder effect hope you like it
http://thedivinelights.tripod.com/demov3.zip

[edited by - imDivineLight on May 30, 2004 9:40:50 PM]

Share this post


Link to post
Share on other sites
Maybe if you try your loops like this:


for(int i = 0; i < mNumCellsPerColumn - 1; i++)
{
for(int j = 0; j < mNumCellsPerRow - 1; j++) {
...
}
}


I''m not sure what your NumCellsPer... contain, but I have a feeling they contain the number of vertices in each direction, as opposed to the number of actual terrain cells. E.g.:

If you had a heightmap of 4 x 4, there would be a 4 x 4 grid of vertices, but only a 3 x 3 grid of "cells" (quads). Now, if you''re just filling the NumCellsPer... variables with the dimensions of the heightmap, you''re going to be putting invalid data into the index buffer because your dimensions will be 1 too big in either direction.

Hope this helps. Also, I tried to download your newest demo, but tripod says it is unavailable. Is this just maxed out bandwith? I''ll try again in a bit.

---------------------------------------

Let''s struggle for our dream of Game!

http://andrewporritt.4t.com

Share this post


Link to post
Share on other sites
Yes my index buffer filling loop got problem, actually it''s the same in the books so it''s also written wrong in the book, i thought books can''t be that much wrong .

here''s a fix now:

// loop through and compute the triangles of each quad

for ( int i = 1; i < mNumCellsPerColumn; i++ )
{
for( int j = 1; j < mNumCellsPerRow; j++ )
{
Indices[baseIndex] = (i-1) * mNumVertsPerRow + (j-1);
Indices[baseIndex + 1] = (i-1) * mNumVertsPerRow + j;
Indices[baseIndex + 2] = i * mNumVertsPerRow + (j-1);

Indices[baseIndex + 3] = i * mNumVertsPerRow + (j-1);
Indices[baseIndex + 4] = (i-1) * mNumVertsPerRow + j;
Indices[baseIndex + 5] = i * mNumVertsPerRow + j;

// next quad

baseIndex += 6;
}
}


the problem was that i was starting the loop index variable from 0, but it should start form 1, and i have changed the loop accordingly, and now i have smooth terrain, and also i got 3 more FPS.

Yeah i don''t know why my that tripod site is pulled down?? I have made a new one and here''s the link to the new demo:
http://68.49.148.212/DemoV3.zip

Thanks for the help of all!

Share this post


Link to post
Share on other sites
Just as a general thought, the computers were all created to start counting at 0, so I would adjust my loop math to start at 0 and end at max-1 instead of just starting at 1 to decrease iterations. You may have to change some of the internal arithmetic that used the loop variable, but overall this would make more sense to a lot of people.

--------------------------------------------------------------------------
The meaning of life is to live, and there''s only one way to do it wrong...
Michael Schuld - March 25, 2004

Share this post


Link to post
Share on other sites
Actually, I''m pretty sure the solution I gave produces exactly the same as yours. The books aren''t wrong at all, their loop is perfectly fine. Like I said, your NumCellsPer... variables are 1 too big. If you just subtract one from them, your old loop will work fine.

---------------------------------------

Let''s struggle for our dream of Game!

http://andrewporritt.4t.com

Share this post


Link to post
Share on other sites
quote:

Actually, I''m pretty sure the solution I gave produces exactly the same as yours. The books aren''t wrong at all, their loop is perfectly fine. Like I said, your NumCellsPer... variables are 1 too big. If you just subtract one from them, your old loop will work fine.



The num of cells in book is:

int NumOfCellsPerRow = NumOfVertexperRow - 1;
int NumOfCellsPerColumn = NumOfVertexperColumn - 1;


so if i have a heightmap of 128x128 dimensions, i have vertices 128x128, and cells 127x127.

So i have to start loop from 1, and end it at 127. or i have to start from 0 and end it at 126, in both cases i get 127 cells.

But if i have to start from 0 i have either to make this change:

int NumOfCellsPerRow = NumOfVertexperRow - 2;
int NumOfCellsPerColumn = NumOfVertexperColumn - 2;


or this one:

for ( int i = 0; i < (mNumCellsPerColumn-1); i++ )
{
for( int j = 0; j < (mNumCellsPerRow-1); j++ )
{


in both cases they look ackward, atleast to me, so starting from 1 is easy to understand for me. Yes the computers start from zero, examples are arrays, etc. but there''s no hard and fast rules for loops to start from zero, they have given us this option to start from any value, so we can adjust the loop we like. this doesn''t matters in case of loops, but if you have arrays in them it''s serious bug!

& have any downloaded the demo?? tell me is it running well? thanks for educating me though!

Share this post


Link to post
Share on other sites