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

Is Backface culling actually two different concepts? and how to achieve them with XNA?

Last post 2/7/2008 11:30 AM by BlueSky. 4 replies.
  • 2/7/2008 4:47 AM

    Is Backface culling actually two different concepts? and how to achieve them with XNA?

    Hi everybody,

    when i read about backface culling it seems that there are actually two different concepts which are frequently mixed under this same name. Because this sometimes gets confusing i am writing this post to ask for clarification of these concepts and how to achieve them with the XNA framework (or maybe its just me who is confused :-).

    the first "backface culling" concept is the use of the CullMode renderstate where you can specify that only one side of every triangle is rendered depending on the winding order of the vertices. This is totally independent of the current view. A good example here would be all the interior sides of a cube which would never be visible.

    the other concept about "backface culling" is the culling of triangles which, dependend on the current view, are not visible at the moment (so to say backfacing from the viewer) and therefore don't need to be drawn. An example would be the 3 front sides of a cube not visible from the current view.

    My question is now how to best achieve this second form of backface culling (as the first one is quiet obvious)?
    Or is this already done automatically by the framework/Direct3D/driver etc? theoretically it would be easy to do with a simple dot product of the view direction and triangle normal but pratically awkward and probably inefficient to achieve with the CPU as the IndexBuffer would have to be updated or sorted every frame or view change.

    Thanks,

    BlueSky




  • 2/7/2008 6:19 AM In reply to

    Re: Is Backface culling actually two different concepts? and how to achieve them with XNA?

    The concepts are related. When you view a triangle from the 'back', the winding order is reversed so the triangle is culled. If you move the view point so the front of the triangle is visible then the winding order is correct and the triangle is not culled.

    For your example of a cube, the 3 sides that are visible from the viewer are front facing and therefore not culled, the other 3 sides are all back facing and so will be culled. Flipping the viewpoint to the other side of the cube would reverse that situation and so show the previously culled triangles.
  • 2/7/2008 7:58 AM In reply to

    Re: Is Backface culling actually two different concepts? and how to achieve them with XNA?

    Hi Leaf,

    thanks for your answer, what you say makes sense and if I understand you correctly, the GPU will figure out the actual winding order from the vertex positions when processing the triangles. But wouldn't that mean that the inside of the backfacing cube sides are drawn too because for the viewer these triangles are front-facing though never visible.
    If so, we wouldn't gain anything as there are still always six sides  (12 triangles) of the cube drawn.

    As I understood the CullMode renderstate it depends on the winding order of the triangles as stored in the Vertex/IndexBuffer no matter how these triangles are oriented to the viewer.

    Or did you mean that both concepts are applied together i.e. first the CullMode renderstate and the index/vertex definitions specify the potentially maximum number of visible triangles (all the 6 outer sides of the cube (12 triangles)) and then the GPU will perform a view dependent evaluation on these potentially visible set of triangles to cull out the backfacing ones (the 3 sides not pointing to the viewer (12 triangles), resulting in only 6 triangles actually drawn ?

    Just trying to understand this right. So there is practically nothing I need to code myself to draw only ever at most 6 triangles of a cube?

    BlueSky
  • 2/7/2008 9:00 AM In reply to

    Re: Is Backface culling actually two different concepts? and how to achieve them with XNA?

    Answer
    Reply Quote
    The triangle culling is basically done in 2D. Take the 3 vertices of a triangle and transform them to screen space, then you walk round the vertices in the order that the index buffer says. If you walk clockwise around the vertices and the cull mode is set to clockwise then the triangle should be culled. If that vertex order results in a counter clockwise walk then the triangle is not culled. So you can see that the view does affect which triangles are culled.

    In the case of the cube half the triangles are always backfacing, so you don't need to do anything.
  • 2/7/2008 11:30 AM In reply to

    Re: Is Backface culling actually two different concepts? and how to achieve them with XNA?

    Hi Leaf,

    very helpful explanation, now I see that both my statically defined facing direction and the current view are taken into account when culling without having to code anything, thats great!

    Thanks again,

    BlueSky
Page 1 of 1 (5 posts) Previous Discussion Next Discussion
var gDomain='m.webtrends.com'; var gDcsId='dcschd84w10000w4lw9hcqmsz_8n3x'; var gTrackEvents=1; var gFpc='WT_FPC'; /*<\/scr"+"ipt>");} /*]]>*/
DCSIMG