Do all HeightMapped terrains have Artifacts??

Started by
15 comments, last by imDivineLight 19 years, 10 months ago
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
Advertisement
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]
::- Hear the beauty of silence -::
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
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!
::- Hear the beauty of silence -::
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
--------------------------------------------------------------------------Michael Schuld
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
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!
::- Hear the beauty of silence -::

This topic is closed to new replies.

Advertisement