How to detect unseen triangles on screen

463 views Asked by At

I'm having a very simple terrain map with tiles! All the tiles are same size, just different height (z value) ! 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)

img : http://i1335.photobucket.com/albums/w666/greenpig83/terrain2_zps24b77283.png

1

There are 1 answers

0
Ivan Aksamentov - Drop On

Yes, in complex scenes, typically, we must cull invisible geometry to achieve interactive frame-rates. Of course it greatly depends on scene itself, capabilities of API, and target hardware.

Here are first steps of a good terrain renderer (in order of complexity):

  • Frustum culling - test for collision between camera's frustum (visible volume) and objects (such as meshes and terrain tiles). No collision means object is invisible. Based on collision detection algorithms. Of course, you will need camera (view and projection matrices) for that. Also you will need a good math lib.
  • Spatial partitioning (ex: "Quad tree" in case of terrain) - grouping objects to a specific data structures, which allows avoid collision tests which are known being impossible in advance. Incredibly speeds up frustum culling. For example, we don't need to test all tiles that are behind the camera.
  • Level of Detail (LOD) - different techniques which allows render objects, that are far away from camera, less detailed, reducing resources consumption. Allows render amazing, realistic, detailed scenes with huge terrains.

Now you know what to ask Google for ;) , but still I'll add some links.

For beginners:

Advanced:

  • vterrain.org - source of infinite knowledge about terrain rendering (articles, papers, links to implementations)
  • Mr. Hoppe's papers on progressive meshes

Hope it helps =)