rendering from height map

Started by
3 comments, last by steg 21 years, 1 month ago
Hi, I have a quad as shown below : VERTEX ZenVertices[] = { {-1.0, -1.0, 0.0, D3DCOLOR_XRGB(0,255,0)}, { 0.0, 1.0, 0.0, D3DCOLOR_XRGB(0,255,0)}, { 1.0, -1.0, 0.0, D3DCOLOR_XRGB(0,255,0)}, { 2.0, 1.0, 0.0, D3DCOLOR_XRGB(0,255,0)}, }; I draw this as a triangle strip as follows: g_pDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); This gives me a quad, how do I take information from a height map and apply it to the height of this quad ? Do I need to set the y value in ZenVertices to that of the height from the height map ? Kind regards, Steve

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

Advertisement
"Do I need to set the y value in ZenVertices to that of the height from the height map?"

pretty much.

load the data from a file/bitmap, and then place the height in the Y value.

you''ll need more than 1 quad though - I have a grid of 256x256 quads for my terrain engine.

Jack

DirectX 4 VB: All you need for multimedia programming in Visual Basic
Formula 1 Championship Manager, My Game Project.

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

Thanks Jack,

Take it I will need a vertex buffer with more than one quad then?

So :

VERTEX ZenVertices[] =
{
{-1.0, -1.0, 0.0, D3DCOLOR_XRGB(0,255,0)},
{ 0.0, 1.0, 0.0, D3DCOLOR_XRGB(0,255,0)},
{ 1.0, -1.0, 0.0, D3DCOLOR_XRGB(0,255,0)},
{ 2.0, 1.0, 0.0, D3DCOLOR_XRGB(0,255,0)},
};

Would be generated on the fly so to speak with more than the one quad as shown in the structure above ?

Steve

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

If you''re trying to create a terrain engine, you''ve got a longer road ahead of you than you think. That is, if you''re after performance. If you tried drawing your terrain 1 quad at a time, you''re going to end up calling DrawPrimitive calls so often, that you''ll be asking yourself why you get 10fps w/ only 1000 quads showing. It''s far slower to call DrawPrimitive 100 times to draw 100 quads than it is to draw 100 quads in a single call.

In order to achieve performance, you need to draw your quads in mass and only draw the ones that are visible. You might draw the entire terrain all in one DrawPrimitive call, but the performance of that would be pretty bad too.

There are countless terrain tutorials, I''m sure. The good ones will teach you how to optimize rendering quite a bit using visibility checks, rendering tricks, etc.
Thanks FlaXen,

I guess you would use DrawPrimitive using the starting and ending index''s into your vertex buffer to draw the ''portion'' of quads that are visible ? I have read about using quad trees for spatial division and I know I would have to implement this or something similiar to get any performance. Just trying to walk before I can run at the moment, taking one step at a time so to speak.

Thanks again for your comments, I much appreciate them.

Steve

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

This topic is closed to new replies.

Advertisement