Xbox LIVE Indie Games
Sort Discussions: Previous Discussion Next Discussion
Page 1 of 1 (4 posts)

XNA has built in frustum culling?

Last post 12/24/2008 5:23 AM by MJP. 3 replies.
  • 12/24/2008 12:12 AM

    XNA has built in frustum culling?

    Does XNA have built in frustum culling of some sort? I ask because in my scene I have lots of objects, when I move the camera to look away from them, such as looking at the floor or up at the sky my framerate shoots up and I don't have any culling code as of yet. So does XNA have some auto culling or why does this happen, and would it be still beneficial for me to code my own culling functions?


  • 12/24/2008 12:25 AM In reply to

    Re: XNA has built in frustum culling?

    GPUs always cull out triangles beyond the view frustum. So you won't see any pixel shader expense for those triangles. However you will take a hit for whatever geometry and textures are sent over the bus and any vertex setup/shader costs.

    XNA framework will not do any frustum culling for you - it could not becuase it has no clue where anything will actually end up. All the transformations are done o nthe GPU and could be a custom shader.

    So if there is a lot of stuff you know won't be drawn and you have spare CPU cycles then it can be worthshile to write your own.
  • 12/24/2008 12:29 AM In reply to

    Re: XNA has built in frustum culling?

    Frustum culling makes it so that the graphics hardware doesn't need to work at all on things you can't see. There is nothing built in like that, because neither XNA Framework nor the graphics driver can know what the vertices will look like after your possibly custom vertex shader has processed them, so there's no way of knowing what the bounding shape of your data would be when rendered. You, however, have this knowledge, so you can do frustum culling if you want.

    However, there are other kinds of culling. The hardware does back-face culling, where triangles facing away from the camera are not drawn. The rasterizer also does guard band clipping, where triangles (or parts of triangles) that are outside the visible area of the screen are not rendered outside the screen. Finally, there is depth clipping, where triangles in front of the near clip plane (hither), or beyond the far clip plane (yon) are not rasterized. If your objects have a high rasterization cost (i e, "fill rate cost") then whether the object is on screen or off will change the frame rate significantly, even if the transform hardware has to transform the object even when it's not visible, because transforming vertices is often quite cheap compared to filling pixels.

  • 12/24/2008 5:23 AM In reply to

    Re: XNA has built in frustum culling?

    What you're probably thinking of is the BoundingFrustum class.  This class can make frustum culling significantly easier by allowing you test whether a BoundingSphere or BoundingBox is visible for a given view * projection matrix.
Page 1 of 1 (4 posts) Previous Discussion Next Discussion