Thread: 3D rendering of only visible faces

  1. #1
    Registered User Zeeshan's Avatar
    Join Date
    Oct 2001
    Location
    London, United Kingdom
    Posts
    226

    3D rendering of only visible faces

    Hi,

    I am actually doing Computer Vision research and have no experience in 3D rendering.

    Given that, I have a 3D model and I know that the camera is looking at the model from a particular direction. I want to render only those faces that will be visible from that camera. Can someone please point me to some algorithms for calculating which faces would be visible and which won't be visible.

    Thanks a lot in advance.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User Zeeshan's Avatar
    Join Date
    Oct 2001
    Location
    London, United Kingdom
    Posts
    226
    Thanks a lot.

    One more question - for backface culling, do I have to read the values of surface normals from the 3D model file or is there someway to find it directly.

    I mean, ofcourse I can take a cross-product, but depending upon the ordering of the vertices, I can get two opposite directions. Is there any way to choose the 'right' one?

  4. #4
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Quote Originally Posted by Zeeshan View Post
    Thanks a lot.

    One more question - for backface culling, do I have to read the values of surface normals from the 3D model file or is there someway to find it directly.

    I mean, ofcourse I can take a cross-product, but depending upon the ordering of the vertices, I can get two opposite directions. Is there any way to choose the 'right' one?
    You can specify which face is the "front" and which face is the "back" relative to your vertex ordering, clockwise or counter-clockwise (glFrontFace(GL_CCW) or glFrontFace(GL_CW)).

  5. #5
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by Zeeshan View Post
    I mean, ofcourse I can take a cross-product, but depending upon the ordering of the vertices, I can get two opposite directions. Is there any way to choose the 'right' one?
    Not if there is no convention for vertex ordering. You need some convention, i.e. "Vertices are arrange clockwise/counter-clockwise w.r.t the outside face."

    Once you have backface culling, the next step is BSP (assuming your scene is static).
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  6. #6
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Culling on most modern hardware is implemented without dot products or any fancy math. The system knows that if you say your vertices are CCW then it knows that any vertices that are about to be drawn in CW order are not facing the camera and vice versa. It does not remove them from the vertex stream since this would be more expensive that just skipping them. APIs such as OGL and D3D will also auto flip flop the order when drawing triangle strips so the strip is visible but also works for backface culling. Strips break the ordering but they are the most efficient so this is an important optimization that is handled for you by the APIs and hardware.

    But the older methods used a simple dot product and used the result to determine which way the face was pointing.

    Even older methods did a pseudo-dot product which usually only worked for vertices that were very near the center of the screen and did not work so well for those on the edges.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Rendering 3d properties to bitmap
    By DrSnuggles in forum C++ Programming
    Replies: 6
    Last Post: 12-03-2007, 01:49 PM
  2. Replies: 0
    Last Post: 03-17-2006, 09:14 AM
  3. 3D starfield
    By VirtualAce in forum Game Programming
    Replies: 6
    Last Post: 06-26-2003, 12:40 PM
  4. 3D rendering and modeling with Linux?
    By MathFan in forum Tech Board
    Replies: 3
    Last Post: 03-05-2003, 04:42 PM
  5. 3d engines
    By Unregistered in forum Game Programming
    Replies: 7
    Last Post: 12-17-2001, 11:19 AM