Back-face culling

Started by
5 comments, last by paulcoz 23 years, 3 months ago
I hate to do this to everyone because I normally search through the other posts for help before I make one of my own, but the search dialog doesn't seem to work at the moment - I get an error about the full-text index not available(?). I know this topic has been discussed over and over. I've always relied on my 3D-card to do back-face culling in my program. Now, I need to learn it myself (eg. do it in software). If I have a number of vertices and the order they were selected from the screen by the user, how do I work out whether the order the points were selected in, was clockwise or counter-clockwise? I know it has something to do with the plane normal (and I know how to get that) but I don't know what to do with the plane normal once I have it (align the plane with the camera's x/y axis plane and test the z direction?). I need a more detailed description. Thanks, Paulcoz. Edited by - paulcoz on January 9, 2001 6:37:14 PM
Advertisement
(normal|one_of_the_vertices - cammera_pos)>0 ? cull
The above won''t work as you expect because the you are testing to
see if the plane is back-culled against your entire screen, not
just a single camera point. You need more than one test to test
the entire frustum area.
Fortunately for me I only need to know whether the shape made by the vertices was drawn clockwise or counter-clockwise when the user is drawing it on the screen. That's a lot easier because in the standard left, behind, and above views (it's for a level editor) you are aligned with the world axes and all of the vertices are on the same axis-aligned plane (have the same camera depth).

I've had a chance to think about this now, and what I am going to do is this:

(a) Calculate the x and y difference between the first point and the second point in camera space.

(b) Calculate the x and y difference between the first point and the last point in camera space.

(c) Get the z value (which is the only one I need in this case) of the normal for the intersection point made by these two vectors by:

1.Multiplying the x value in (a) by the y value in (b).
2,Multiplying the x value in (b) by the y value in (a).
Subtract 2 from 1 to get the z value.
(I used a determinant to get the order)

(d) Check the z value - a negative value indicates clockwise order, a positive value indicates counter-clockwise order.

It worked on paper anyway, and is accurate enough for my purposes.
Paulcoz.

Edited by - paulcoz on January 11, 2001 1:36:24 AM
Sorry, that reply was for a perspective view, not an ortho one.
What you generally want to do, is to get rid of polygons in as early stage in rendering pipeline as possible. The method you descriped performs backface culling (BFC) in very late state whatfor you have to perform alot of unnecessary operations.

The earliest stage you can perform the BFC is before any transforms has been made (in object space) by first transforming view point to object space with the inverse transform and then computing dot products between face normals and view vectors like anonymous poster descriped. This way you get rid of bunch of vertices before transform stage and therefore save save ~50% of your transforming operations.

The same technique should be applied to the lighting of the object which let you have static object data and you get rid of transforming normals of the model completely.

Cheers, Altair


"Only two things are infinite, the universe and human stupidity, and I''m not sure about the former." - Albert Einstein
"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." - Albert Einstein
And yes, the same thing also applies to orthogonal projection. Only difference is that you don''t need to compute view vector for each polygon you test for backfacing, because in orthogonal projection all view vectors does have same direction.

About the efficiency of performing BFC in object space I would like to point out that if you have stored polygon normals along with polygon data, computing dot product takes 3 muls and 2 adds and computing the view vector takes 3 subs, so it''s very efficient.

Cheers, Altair


"Only two things are infinite, the universe and human stupidity, and I''m not sure about the former." - Albert Einstein
"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." - Albert Einstein

This topic is closed to new replies.

Advertisement