Advertisement

Why use normals?

Started by March 10, 2000 02:14 PM
3 comments, last by BeanDog 24 years, 9 months ago
Just on curiosity, I was wondering why everyone uses normals and all the floating point math to figure out if a polygon is facing you or not. A long time ago I read an article by a guy that was writing a 3d engine for his 286. He just used this really nifty and REALLY FAST routine to figure out the orientation of the points - if they switched orientation (clockwise vs. counterclockwise), then it was turned away. This seems like it could seriously speed up some really high-poly scene unless there''s something I don''t know about in my ignorance. PS my history teacher calls me his bubble boy. -Ben Dilts
To see if a triangle is facing the camera you only need to do the following:

VECTOR3D Camera, TriangleVertex, Normal;

if( DotProduct(Normal, TriangleVertex - Camera) >= 0 )
// The triangle is facing away from the camera
else
// Guess what?

This includes three subtracts + three multiplications + two additions + plus some assignments operations and the final test which is another subtraction. (Did I get everything?)

I don''t know of any faster way than this. If you or any other do then please enlighten me.
Advertisement
spellbound is right, the dotproduct vector method is much faster. finding out if something is clockwise or counterclockwise would be more difficult. You''d have to step through all vertecies and somehow (through at least 3 compares and jumps per vertex) determine if the order is clockwise. how was this comparison done that would be so fast?

remember that math ops (addition,multiplication, and assignment) are faster than jumps (what you get in a typical if() statement.

*oof*
*oof*
Maybe it doesn''t need to be said (or maybe I''m beating a
dead horse), but the efficiency payoff in using normals
to extract the gross angular relation between the poly face
and the camera view assumes that one has pre-computed the
normals for all of the poly faces, yes?

-pauli
Yes it does. Otherwise you would have to do a cross product for two of the edges, which would add 6 multiplications and 9 subtractions.

The above example is for backface culling before projection. You can also do the culling after projection, in which case you would compute the signed area of the triangle. The signed area is basically computed with a slightly modified crossproduct.

This topic is closed to new replies.

Advertisement