backface remove

Started by
6 comments, last by kslam 17 years, 5 months ago
Hi All, I draw a polycon and compute the Normal of this polycon. How I know the direction of the Normal is face UP or face Down ? Thank You.
Advertisement
I assume you're talking about standard backface culling, please correct me if not.

What I think you want to do is check if the normal of the polygon is pointing towards the view. A simple way to do this, considering you already have the normal, is by dot product. A dot product gives the cosine of the angle between two vectors. One vector you will use is the normal of the polygon. The other is a vector from the view to one of the vertices of the polygon (vertex - view). Or if you really do want to check if it's face up or down, you could use a vector pointing up or down. If the cosine of the angle between the two vectors is greater than 0, the angle is less than 90 degrees and the polygon should be drawn. So some pseudo code is:
if (dot(normal, vertex[0] - view) > 0)   draw polygon;

I should mention that the result of the dot product is only actually the cosine of the angle if unit length vectors are used, otherwise it is scaled. But in this case it doesn't matter, we only want to check if it's greater than 0.

If you are using one of the common api's (opengl, direct3d or even a game engine) then there will be a simple setting to enable backface culling. Use that setting, it is easier and performs much better.
___________________________________________________David OlsenIf I've helped you, please vote for PigeonGrape!
Assume that I draw a box which got 6 face. I view from the above, I can see 3 faces of the box. If without backface remove, I can see 6 faces. Now I want to remove 3 faces (behind Left and Right face, Bottom face). If the Direction of the Normal face up, the Top Face of the box's Dot product is < 90 degree. But if like this, the Bottom Face' Dot product < 90 degree. Top Face same like Bottom face. It is incorrect.(Normal Direction Top Face and Bottom Face is same, they face up, as I know all Normal Direction of the polycon is face UP??)

If the Normal Direction of the Bottom Face is face down(the DP > 90 degree) , then it is correct, I can remove the Bottom face.
My question is, how do I know the direction of the Normal is face up or face down ?(Direction Normal of the Top Face is UP, the Bottom Face is DOWN)

As I know that the polycon on the Top Face and the polycon at the Bottom Face is same, the different is, one on top the other one at bottom of the box.
How to control the Normal direction of the polycon to face up or face down ?

Beside that, how about the behind Left and Right face, their Direction Normal will face to left or right ?
Yes, the top and bottom faces of a cube must point in the opposite directions for backface culling to work.

Quote:how do I know the direction of the Normal is face up or face down ?


facenormal(vertex v0, vertex v1, vertex v2){ edge A = v1-v0 edge B = v2-v0 return(normalize(crossproduct(A,B)))}


Now if you call

facenormal( {1,0,0} , {0,1,0} , {-1,0,0} ) ,

you will get {0,0,1}. If you reverse the vertex order and call

facenormal( {-1,0,0}, {0,1,0} , {1,0,0} ) ,

you will get {0,0,-1} which points in the opposite direction. So the direction the triangle is facing depends on the order of the vertices in your data. Just be constistent and the dot product- based backface culling algorithm will work fine. Typically though, unless you're implementing your own software engine, the APIs will take care of backface culling for you.

[Edited by - ruistola on October 26, 2006 8:55:11 AM]
If all the vertex are positive value ?

For example :
Bottom Polycon A, vertex v0=(10, 10, 10), v1=(20, 10, 10), v2=(15, 10, 20)
Top Polycon B, vertex v0= (10, 30, 10), v1=(20, 30, 10), v2=(15, 30, 20)

I'm not using APIs.

you need to understand about faces. The order in which you define your vertices determines which way the normal will point. The Top and Bottom faces of the cube have vectors that point in exact opposite directions. Usually, you define your faces in clockwise order, 3 vertices per face. After you have all your faces, then you can calculate a normal for each face. If you define each face in a clockwise order, then the normals of parallel faces that face in opposite direction will also be opposite.
Quote:If all the vertex are positive value ?


The values themselves don't matter, the vertex ordering will determine the direction of the face normal.

Quote:Bottom Polycon A, vertex v0=(10, 10, 10), v1=(20, 10, 10), v2=(15, 10, 20)
Top Polycon B, vertex v0= (10, 30, 10), v1=(20, 30, 10), v2=(15, 30, 20)


facenormal({10,10,10},{20,10,10},{15,10,20}) = {0,-1,0} // bottom
facenormal({10,30,10},{20,30,10},{15,30,20}) = {0,-1,0} // top

Backfaces won't get culled correctly, because you have defined the polygons to face the same direction. You need consistent vertex winding throughout your modeling data in order for backface culling to work. Now if you reverse, say, the bottom polygon vertex ordering, you will get

facenormal({15,10,20},{20,10,10},{10,10,10}) = {0,1,0} // bottom
facenormal({10,30,10},{20,30,10},{15,30,20}) = {0,-1,0} // top

and now backface culling will work just fine -- and you just defined your backfaces in the positive direction of the face normals.
Thank you.

This topic is closed to new replies.

Advertisement