Banging my head against a heightmapped terrain.

Started by
7 comments, last by GameDev.net 18 years, 9 months ago
Hi, I am getting desperate! please help! :P I am building a terrain engine, and have come across a very strange problem. Here's how I build the terrain. Create a vertex buffer comprising of a grid of vertices representing the whole terrain, evenly spaced in a grid, offset by a value extracted from an image file, fairly standard stuff. Next create an index buffer. I build the index buffer in 'sectors', ie square chunks of terrain. All the sectors are consecutive in the same IB. (I can use frustrum culling to avoid drawing whole chunks, but ignore that, not a factor in my problem - ie, problem exists with culling enabled or not) This system worked with a terrain 64x64quads, split into 8x8 sectors. after getting them mechanics working I hoped I could simply upsize the terrain, but I have anomalies. I am now trying to use the system with a 256x256 terrain, and it nearly works. I have split the terrain into 16x16 quad chunks this time, and 15 out of the 16 rows of sectors draws fine. The final row all have weird errors. The sector, comprising 16x16 quads, only draws 14x16 in the correct place. One row of quads is missing and the final row is drawn at the other end of the map!!! Some polys stretch right across the map. One fills half the whole landscape as show here, I have re-rendered the offending poly in red : Looks like a blood bath! really its an incorrect poly! I have highlighted in blue where it is really supposed to be The generation code for vertex and index buffers is identical to all the other sectors, as is the call to render each sector. Rendering the whole landscape in one call does the same. I have debugged for two weeks and cannot find any problem. According to the coords held in the vertex buffer, the polys should draw in the correct place! Has anyone else come across a similar problem? I am at a loss..... Thanks for your time. Simon
Advertisement
My first instinct says that something is up with the index buffers, because it looks almost like another triangle is being rendered, using vertices from a few of the corners.


Edit: OR, you could change the poly's colour to blue and say it's water! [wink]
I would say, stop a little earlier, don't draw the entire buffer, if it's still there, draw less, or draw more if it disappeared. I'm betting on the indexbuffer being screwed in the end.


In the above screen shot, I hav drawn the whole terrain wireframe and normal colours,

The only red triangle in the poly which has these strange effects. There are other polys which produce other oddities but they are all along the far edge (deepest into the buffers).

Stepping thru the code seems to produce correct VB and IB values for these problem areas.

hmm

Si
You are drawing it as wireframe? How can the red area be solid then... you must be doing something else you aren't supposed to.

But as I said, have you narrowed it down? That is... first off, don't draw the terrain at all... is it really the terrain causing it?

Yes perhaps it is... do as I said earlier... just draw half the buffers, is it still there? Decrease again...

Suddenly you are down to a zero buffer... is it still there? Shouldn't be, step up.

Etc.

It's really hard to say anything from what you've told us, you could for all I know draw that quad down there yourself.


Sorry I know its hard to explain.

I drew the terrain wireframe, then redrew the offending poly in solid red.

I can step thru the polys I am drawing in red, to check each one is drawing ok.

The screenshot is taken when the offending poly is the one 'highlighted' in red. From this I can get the index of this poly, and from that check the coords of the vertices the three points refer to. All in order... or so it seems.


Thanks for tryin to help, it was a long shot. Guess my code is cranky!

Si
Hi there,
1) Make sure that your heightmap raw file conforms to the standard n^2+1 which means that if you want a heightmap of 512x512 your heightmap should be 513x513. The reason? The reason is that you have 513x513 vertices on each side and 512x512 primitives.

2)The number of vertices should be : numTerrainVertices = (terrainWidth) * (terrainHeight);
The number of primitives you need to render : numTerrainPrimitives = (terrainWidth - 1) * (terrainHeight - 1) * 2;
The terrainWidth and terrainHeight being 513 from our example above.
I agree with Armadon, I had similar problems with funky results and someetimes was due to that.

Something else, are you creatin a tri strip or seperate tris? If a strip, how are you connecting the strips?

When I did mine, I miscalculated that I had 4 extra tris on each row that were dummy tris. I originally thought it was only 2, so with each additional row rendered I got further and further off to the end where I only rendered 1 or 2 tris of the last row, and often they rendered wrong. The fix included numerous steps including: making sure the seam was right (it ended up only being two additional verticies, but 4 extra tris), getting the number of tris right (4 extra per line), and a few other various issues all of which I can't remember now.

Long story short, it in the code (or the math), it always is.

Break everything down and keep working at it. You'll get it. print one at a time and see what happens until you see the exact issue, maybe it isn't what you think it is.

just my opinion, good luck.
3DMUVE is an amateur game development team, and the designer and developer of a new gaming technology “MUVE” for the gaming industry.


Index range only goes upto 65k ??? (theres a mode to go higher than this...)

257x257 would exceed ??

Primitives limited to 65k cycles (triangles) ???

This topic is closed to new replies.

Advertisement