Advertisement

manual backface culling

Started by February 25, 2004 12:40 PM
9 comments, last by James Sioutis 21 years ago
hey im currently in the middle of a demo-like thing and ive been trying to put in backface culling, i already know OpenGL can do it but its too slow, and i already know that to check if something is back facing you just get the dot product of the view vector and the objects normal, but my question is how the hell do you get the camera''s view vector? ~aussie
[~aussie]
OpenGL backface culling is not slow. Doing this on CPU will be slower since you first have to check the if triabgle is backfacing and then create new indice buffer each frame. In modern engines you should never ever have to touch individual triangles.

You should never let your fears become the boundaries of your dreams.
You should never let your fears become the boundaries of your dreams.
Advertisement
well its not that OpenGL is slow, its just that i know my data better than OpenGL does, all it knows is a bunch of vertices, and if i had back face culling in the enormous for loops to render the data, i could cut down the size of the loops almost in half, so it would save sending data through glVertex3f and specifying the normal for it and also save OpenGL from doing an extra 5000 world-to-camera and culling calculations by itself

~aussie
[~aussie]
If so, you are getting overhead becouse of glVertex functions, not becouse of BF culling. First change your code to use certex arrays. Then you will see the whole point of CPU BF culling is pointless. It was a viable point 5 years ago, but not anymore. Plus, opengl-s x-to-y space calculations are faster than anything you can code (unless you are some kind of SSE wizard).
If you are still so determaind to do it, look at some hierarhical/clusterd BF culling.

You should never let your fears become the boundaries of your dreams.
You should never let your fears become the boundaries of your dreams.
you must be rendering a massive polygon count for opengl backface culling to slow down your app.

a good way to do backface culling is to calculate a plane for your face (ax+by+cz+d = 0). if your not familiar with the plane equation stop reading.

simply substitute the camera x, y, z location into the ax+by+cz+d equation where abcd make the plane. if the result is larger on equal to 0, that point (camera) is facing the plane, thus the face is facing the camera. works in 3dimentions.
The hardware is probably x10 times better than the CPU at doing backface culling, and is "virtually free" on all the graphics card i know of. And i think it''s a bit stupid to try implementing backface culling yourself in order to cut down the bandwidth costs, when you''re submitting your vertices in immediate mode. Your time would be better spent (if you care about performance) into investigating vertex arrays and VBOs.

Y.
Advertisement
Hey thanks for replying, i didnt mean to write that before about OpenGL being slow at BF culling, what i mean is that if i have something like this (for example):

for (int i=0; i<200; i++)
{
for (int j=0; j<200; j++)
{
if (CheckBackFace(.....))
continue;

(Render verts)
}
}

i thought that it would speed it up a little because its cutting down alot on the bandwidth, i had already implemented quadtrees and frustum culling etc so i was just tryin to take it one step further.
Also about the vertex arrays, ive been tryin to put in ROAM, and if im not mistaken, ROAM is all about removing vertices from a mesh to decrease the amount of detail for things really far away, but vertex arrays are sent to OpenGL at initialization, so would it be possible to use vertex arrays AND LOD at the same time??
[~aussie]
What about "Clustered backface culling"?
With this technique you use some kind of normal cones to determinte if a couple of surfaces are front facing or back facing. This technique could be done in software.

Here you have a short overview:
http://www.cs.vassar.edu/~ellman/old-courses/395-spring-2001/cs395-lecture21.pdf


--------------------------------------------------------

There is a theory which states that if ever anybody discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.

There is another theory which states that this has already happened...
--------------------------------------------------------There is a theory which states that if ever anybody discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.There is another theory which states that this has already happened...
quote:
well its not that OpenGL is slow, its just that i know my data better than OpenGL does, all it knows is a bunch of vertices,

Ah! Is your data organised in some way that would make backface culling easy? If your data is organised so that you can eliminate large chuncks of data at a time (Perhaps some sort of tree structure) then it could be very worth your while to do it yourself.

Off the top of my head I can''t think of a structure that would be good for this sort of thing, but I''m sure someone has come up with one. (Perhaps even in that paper linked it the post before mine. I don''t have time to look at it at the moment.)
Er, as for your actual question, what you''re going to want to do is use glGet to get your projection and modelview matrices.

I''m sure someone will correct me on this but isn''t the third column of the matrix the camera''s z-vector?

This topic is closed to new replies.

Advertisement