Advertisement Jump to content
Sign in to follow this  
greenpig83

[Terrain] How to detect unseen triangles!

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

Hi, I'm having a very simple terrain map with tiles!

I can render them OK, but there are thousands of tiles , but not all of them are on screen, only a portion (that ahead of view)! So i'm doing a batch rendering, collect only tiles that appear on screen then Render them all in 1 call!

I try to use D3DXVec3Project to project vertex on World space to Screen space, then detect which triangle is on Screen, however this is very slow, call this for whole map take to 7ms (about 250x250 calls ). 

 

Right now i'm using iso view (D3DXMatrixOrthoLH), there is no camera or eye, when I want to move arround the map, I just translate the world!

 

I think this is a very common problem that all engine must face to optimize, but I cant search for it ! Is it visible detection , culling or clipping... ?

Thanks! Should I just render all the tiles on screen, and let DirectX auto clip for us ? (If I remember well, last time I try render them all, it's still very slow)

 

terrain2_zps24b77283.png

Edited by greenpig83

Share this post


Link to post
Share on other sites
Advertisement

Just because you are using an orthographic projection does not mean you don’t have a camera.  You do.

And from that orthographic projection matrix you can extract a frustum (there are many resources online on how to extract a frustum from any projection matrix, so I let you Google it).

 

Once that is done, the terrain should be broken into chunks of something like 32×32 or 64×64 or whatever.

Then each chunk should be given an AABB bounding box (many resources on this via Google).

 

Then you perform frustum culling (Google) on those chunks and only draw the ones that are inside or crossing the frustum.

 

 

L. Spiro

Share this post


Link to post
Share on other sites

Just because you are using an orthographic projection does not mean you don’t have a camera.  You do.

And from that orthographic projection matrix you can extract a frustum (there are many resources online on how to extract a frustum from any projection matrix, so I let you Google it).

 

Once that is done, the terrain should be broken into chunks of something like 32×32 or 64×64 or whatever.

Then each chunk should be given an AABB bounding box (many resources on this via Google).

 

Then you perform frustum culling (Google) on those chunks and only draw the ones that are inside or crossing the frustum.

 

 

L. Spiro

Thanks for your quick answer. I've just done a quick search about frustum, and it's not that's hard to understand. But I think it's main purpose is for meshes, or primitive, to check if it's inside our view or not. So the number of check is not so many. In my case there is only 1 mesh (all the vertex is connect into tiles). So if we check if vertex it's still the same as the approach i'm current doing (project the vertex to screen-space then check , after look at the code, I think call 1 project is faster than do frostum check or simpler). 

 

It seems i need to read about quadtree for better frustum culling, currently I'm just storing the map in a 2-size array, very simple! So many things to learn if u want to do from scratch :(

Thanks anyway!

http://www.flipcode.com/articles/article_geomipmaps.pdf   This article seems quite useful !

Share this post


Link to post
Share on other sites
You could also divide the terrain into chunks (meshes if you like), that way it should work and give you an improvement (depending on several factors like the size of the terrain etc.)

Share this post


Link to post
Share on other sites

I agree with L.Spiro. 

 

In my current project I've broken my world down into "zones", which are 32 tiles by 32 tiles. It's pretty easy to construct and store an AABB for each zone from its heightmap, and do a cheap test to determine if any part of the zone's AABB is visible. 

 

Testing the entire zone instead of the individual tiles reduces the number of visibility tests I have to do by a factor of 1024, which makes a huge difference.

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!