Sign in to follow this  

Do not draw behind camera.

This topic is 4215 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 Guys, i have an issue to resolve. My camera is built using two vectors. Camera.Viewat.x Camera.Viewat.y Camera.Viewat.z and Camera.ViewFrom.x Camera.ViewFrom.y Camera.ViewFrom.z Also i have a nice ammount of a terrain to render, but i would really like to render only those pieces of terrain that i see in front of my camera. Terrain is a Tile X,Y structure that goes as follows: Terrain[1].x; Terrain[2].y; Terrain[...].x; Terrain[....].y; Please could you help ? I cannot imagine how to do that ;/ With regards.

Share this post


Link to post
Share on other sites
You might want to read about Frustum Culling (see also GDNet article on the topic). From your camera settings along with your projection matrix, you can create a viewing frustum, which you clip your geometry against.

HTH,
Pat.

[edit]Spelling[lol][/edit]

[Edited by - darookie on July 2, 2006 7:50:57 AM]

Share this post


Link to post
Share on other sites
You may wish to do approximate frustum culling; either divide your landscape into blocks (of greater than 1x1 tile), or zones or something.

Then do the cheapest test you can; don't worry about drawing slightly more geometry than strictly necessary if it's easier to do an approximate cull.

The thing that Superpig pointed out to me (which is actually really bloody obvious when you think about it), is that if you spend more time culling than you save, then it's not worthwhile.

I guess this also counts for developer time to some extent, too.

Mark

Share this post


Link to post
Share on other sites
If you're not doing a serious game (ie. just a demo) you might not even need to do that kind of culling, if your terrain isn't using a lot of vertices, it probably won't slow down a bit to draw the extra tiles. Remember, modern video hardware is designed to do hundreds of millions of polygons per second.

Of course, that being said, never pass up an opportunity to learn something new, like culling.

Share this post


Link to post
Share on other sites
You should really look into real culling, but as a quick and dirty way to really only cull stuff behind you, you need:

The tiles center and the radius of a tile (should always be sqrt(width*width + height+height) anyway)

dot ( (tile.center-camera.position) , camera.direction)

If the result is smaller than -(tile.radius-near plane) it's far enough behind your camera, but only assuming your direction vector was unit length.

However, with very little extra work you could do real frustum culling and discard a lot more than just half the scene. Essentially instead of only testing against the near plane as above, you would repeat the test for far plane and the frustums 4 side planes.

Share this post


Link to post
Share on other sites

This topic is 4215 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this