terrain looks terrible

Started by
24 comments, last by steg 21 years ago
Hi all, I am rendering some terrain using quads, the height map I have generated with PSP and loaded in as a raw file, set the y-vertices to the data in from the height map for each quad. After inspecting what I get from the height map it looks as followsnote this was for debug info) (x,y,z,diffuse color) {0,151.000000,0,D3DCOLOR_XRGB(0,255,0)}, {1,154.000000,0,D3DCOLOR_XRGB(0,255,0)}, {2,150.000000,0,D3DCOLOR_XRGB(0,255,0)}, {3,148.000000,0,D3DCOLOR_XRGB(0,255,0)}, {4,148.000000,0,D3DCOLOR_XRGB(0,255,0)}, {5,143.000000,0,D3DCOLOR_XRGB(0,255,0)}, {6,134.000000,0,D3DCOLOR_XRGB(0,255,0)}, {7,129.000000,0,D3DCOLOR_XRGB(0,255,0)}, {8,124.000000,0,D3DCOLOR_XRGB(0,255,0)}, {9,116.000000,0,D3DCOLOR_XRGB(0,255,0)}, etc.... The method I use for creating quads (storing in my vertex table): void CreateQuads() { for(int z=0; z<32; z++) // 32 is height size { for (int x=0; x<32; x++) // 32 is width { quadVertices[z][x].x = (float)x; quadVertices[z][x].z = (float)z; quadVertices[z][x].y = GetHeight(z,x); quadVertices[z][x].DiffuseColor = D3DCOLOR_XRGB (0,255,0); } } } Get height method: float GetHeight(int z, int x) { int pos = (32 * z) + x; float height = pData[pos]; return height; } pData contains the height map, now when I brute force render this it looks terrible (I am using Triangle strips). Anyone any ideas ? Kind regards, Steve

If it isn't working, take a bath, have a think and try again...

Advertisement
Maybe it has something to do with Triangle strips? I''ve noticed that not all of the quads are joined up ?

Any clues ?

Thanks

If it isn't working, take a bath, have a think and try again...

Your z values are all zero, you should increase your z values linearly, as you have with your x values otherwise your quads will all be rendered with the same z coordinate. This though seems a little unlikely, perhaps I''m misunderstanding the data you show that you get from the heightmap?
Cheers,SteveLiquidigital Online
Normally, you would have some sort of x,z scale, where you would do:

quadVertices[z][x].x = (float)x*ScaleX;
quadVertices[z][x].z = (float)z*ScaleZ;

Just to make the quads larger than 1 unit (unless that was the scale you were going for to begin with, which is unlikely). Also, using a single color isn''t going to look the greatest, because you can''t really tell the difference of depths very well. I think it''ll look a LOT better once you get that color thing figured out, any shading at all will help tremendously.

if (z<31 && x<31) //Can''t +1 to these, otherwise it goes beyond the bounds of our map!
{
float tmp1, tmp2;
tmp1 = quadVertices[z+1][x+1].x-quadVertices[z][x].x;
tmp2 = quadVertices[z+1][x+1].z-quadVertices[z][x].z;
tmp1*=tmp1;
tmp2*=tmp2;
tmp1 = sqrtf(tmp1+tmp2)/2.0f; //Return a number between 0 - 255 depending on the angle of incline/decline.
quadVertices[z][x].DiffuseColor = D3DCOLOR_XRGB (tmp,tmp,tmp);
}
Thanks guys,

Mephs, the Z-values aren''t all zero (just the example data I shown is misleading), they go up linearly like you mentioned, Example :

{0,116.000000,3,D3DCOLOR_XRGB(0,255,0)}
{1,117.000000,3,D3DCOLOR_XRGB(0,255,0)}
{2,119.000000,3,D3DCOLOR_XRGB(0,255,0)}
{etc...},
{etc...},
{31,107.000000,3,D3DCOLOR_XRGB(0,255,0)}
{0,114.000000,4,D3DCOLOR_XRGB(0,255,0)}
{1,114.000000,4,D3DCOLOR_XRGB(0,255,0)}
{2,116.000000,4,D3DCOLOR_XRGB(0,255,0)}
{3,118.000000,4,D3DCOLOR_XRGB(0,255,0)}

We see here that the x-values go up linearly by one, they y-values are from the height map and z is set to 3, this will increase to 4 the next time as shown.

Thanks Ready4Dis for the colour info and scale info.

Maybe I''m rendering the data wrong ?

I create the vertex buffer as shown (1024 is 32x32):
r = g_pDevice->CreateVertexBuffer(sizeof(MYVERTEX)*1024,0,CUSTOM_MYVERTEX,D3DPOOL_DEFAULT,&g_pVB,NULL);

Then I lock the buffer:
r = g_pVB->Lock(0,1024*16,(void**)&pVertices,0);

Then copy:
CopyMemory(pVertices,&quadVertices,1024*16);

and render with DrawPrimitive:
g_pDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 1020)

I''m not so sure about the 1020 I''ve put into the DrawPrimitive primitivecount parameter ?

Any more clues ?

Kindest regards,
Steve

If it isn't working, take a bath, have a think and try again...

It would help if you would explain ''looks terrible'' a little better. My best guess is that it is just ups and downs all over way too close to each other. Take a look at your y values. They are going up and down large amounts each vertex, with only 1 x/z space between each one. My suggestion is to divide the values you get from the height map to make the values not change so much. Try something between 8-16 to start with. See what happens.
Thanks AikonIV,

I''ll elaborate, some of the terrain looks correct while other parts of it has lines stretching across the screen, some not even connected ?

Having divided the height value it does look a little better but still some lines are stretching across the screen ?

Kind regards,
Steve

If it isn't working, take a bath, have a think and try again...

Hmm, you said you are using triangle strips. Are you doing using just one strip or are you using more than one? More specifically, are your strips spanning more than one Z value? If they are, make sure that they alternate the direction they go in every time Z increases. Otherwise you''ll have polygons going from the right side of the map over to the left side.

I would suggest trying it using triangle lists. If it works, what I described above may be the culprit. You could try using a seperate list for each Z value.
Thanks again AikonIV,

I''ll try it with Triangle lists, I''m thinking that it is the strips.
I''m also using untransformed vertices as I''m planning on later having the terrain move (I know I''ve a long way to go....quad trees etc...), guess this is correct ?

Kind regards,
Steve

If it isn't working, take a bath, have a think and try again...

In case you hadn''t guessed it, I recently finished implementing a basic terrain engine. My FVF is XYZ|NORMAL|TEX1. I should try using transformed vertices tho. Could potentially give a (desperatly needed ) speed increase.

If it turns out your triangle strips aren''t the problem tho, I don''t think I''ll be able to help much more. I''m just about out of ideas.

Also, are you using index buffers or just straight vertex buffers? If you aren''t using index buffers, seriously consider using them.

This topic is closed to new replies.

Advertisement