Jump to content


Backface culling


3 replies to this topic

#1 Nawar

    New Member

  • Members
  • Pip
  • 5 posts

Posted 15 January 2009 - 01:43 AM

Hi

Iam looking into backface culling, most literature use the dot product between the surface normal and a point from the face to the camera to tell whether it is a back or front face, I found a couple of articles (which seems more logical to me) that use the dot product between the normal and the camera view vector (ie [0 0 1]) to tell whether it is a front or back face. Could anyone please explain why the majority use the first definition? Is that more "correct" and why?

Thanks for all your help
Nawar

#2 .oisyn

    DevMaster Staff

  • Moderators
  • 1842 posts

Posted 15 January 2009 - 02:00 AM

Yes, the first method is correct, the second isn't. Imagine a wall that is perpendicular to your view direction (so you're looking at the side of the wall). Suppose the wall's front is facing to your right. Then, if you move right, the front of the wall becomes visible. However, if you move to the left, the back of the wall becomes visible. And even though the visible features of the wall change as you move, both your and the wall's view direction stay the same. Therefore, using merely those two variables to determine whether to cull the wall must be incorrect.

In fact, you're not even interested in your own view direction. What matters is whether your location with respect to the wall is in front or behind it's plane. Even if you rotate, your position with respect to the wall's plane stays the same. So no matter your view direction, if the wall was facing you, it will continue to face you.
C++ addict
-
Currently working on: the 3D engine for Tomb Raider.

#3 Nick

    Senior Member

  • Members
  • PipPipPipPip
  • 1227 posts
  • LocationOttawa, Ontario, Canada

Posted 15 January 2009 - 12:07 PM

The second method is also correct, but only after projection, in 3D homogeneous space. You can even do it later, after homogeneous division, in screen space. :ninja:

As .oisyn pointed out though it's a very common mistake to use that method in 3D space before projection. It might look intuitive at first to compare the normal with the forward vector but that leads to incorrect results.

Anyway, none of the correct methods is "more" correct than the other. They are mathematically equivalent. They can however differ in performance and robustness. The optimal choice depends on what you're really doing.

#4 Nawar

    New Member

  • Members
  • Pip
  • 5 posts

Posted 16 January 2009 - 01:58 AM

Nick, .oisyn, Thank you both for your help and your quick response. Things make more sense now :-)

Cheers





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users