Jump to content
  • Advertisement
Sign in to follow this  
comfy chair

Optimizing top-down terrain

This topic is 2109 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

I am trying to optimize the terrain render part of my real time game, which uses a top-down perspective.

Currently, I create all vertices in the visible area each frame and send them to the GPU (dynamic buffer).

 

This is costly, so I wanted to try and use a static buffer instead, where all the vertices are allocated on the GPU on startup.

However, I got an out of memory exception on my larger maps. Apparently, there were too many vertices to fit in the video memory.
Any ideas for how to move on?

I also have an idea about rendering the terrain into bitmaps and displaying them as one or more big quads.
Is this a method that is commonly used? What is the best way to go about it?

Share this post


Link to post
Share on other sites
Advertisement

Hi there.
 
Well, since you were talking about static buffers, you could split your terrain up into a grid, lets say, 4x4.
 
x-> Terrain Slice
c-> Camera

 

EDIT. Replaced text with image.

k2y3ip.png
 
If you really want to see the old one, here you go. (Some formatting errors due to spoiler)
[spoiler]
x x x x
______
x | x x| x
| C |
x | x x| x
----------
x x x x
[/spoiler]
 
As you have a top down view, then I tried (beware the 'tried') to illustrate what area it can see from the camera. Now as we have split the terrain up into this beautiful grid, you could build a view frustum, meaning something like this: (And then remove the 'not seen' parts of the terrain to improve performance)
 
 

void M3DEngine::RenderMyTerrain() // M3DEngine -> My3DEngine
{
    for(int i = 0; i < mTerrainCount; i++)
    {
        if (!ViewFrustum::IntersectsBox(Camera.GetView(), Terrain[i].BoundingBox))
            continue; // Well, this entire terrain isn't visible

        for(int s = 0; s < Terrain[i].mSlices; s++)
        {
            if (!ViewFrustum::IntersectsBox(Camera.GetView(), Terrain[i].mSlice[s].BoundingBox))
                continue; // Well, this terrain slice wasn't visible

            DoMagicStuff();
            SendTerrainSlice(&Terrain[i].mSlice[s]);
            
            RenderThisBeauty(); // With the buffers sent and the shader set, render it.
            // PS. This last stuff completely depends on your engine architecture!
        }
    }
}

PS. This piece of code isn't found anywhere, it just came out of my head, so If you find any errors, tell me happy.png .

This is just one of the many ways, hope it helps!
-MIGI0027

Edited by Migi0027

Share this post


Link to post
Share on other sites

This looks useful...

 

So is it okay to create and destroy static buffers when scrolling? Or should I create the buffers once and change the contents when needed?

I am thinking that the slices could just as well key into rendered textures. That would be even faster.

Share this post


Link to post
Share on other sites

No you're not destroying any buffers, in the example above you have 16 different buffers. Then you choose which to use and which to not each frame, which is not a performance issue, it's actually really fast. smile.png

Share this post


Link to post
Share on other sites

No, you shouldn't, depending on your terrain size, you may need to dynamically load it.

 

But I am not the right person to answer this I'm afraid...

Edited by Migi0027

Share this post


Link to post
Share on other sites


Apparently, there were too many vertices to fit in the video memory.
Any ideas for how to move on?
Yes, Be sure to have an estimation of your memory footprint because, in theory, you should be paging if running vista or later!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!