Alternate Back face culling
Okay, I'd like to have your opinion on this before I go on with its implementation.
I have a data structure to draw models using flat lighting ( mainly for rendering buildings ). So each vertex in the model can have different normals depending on wich triangle is being drawn.
The data structure is composed of a big vertex array, and a number of index arrays.
Each index array is associated with a normal. ( all triangles with a given normal get drawn all at once ). So drawing is done with the follwoing:
So I figured that , since I know the normal for a ( potentially VERY big ) number of triangles, I could take the normal, tranform it in the ModelView matrix, and if the z component of the result if greater than the cosine of the FOV ( well, that's not exactly mathematicaly correct, but you get the idea ), I can discard all those triangles. Resulting in more efficient back face culling... However, I have a strange feeling that I'm overlooking something here
So my question is: Is this making sense?
Edit: great, I double checked my post, but managed to make a typo in the thread title
I have a data structure to draw models using flat lighting ( mainly for rendering buildings ). So each vertex in the model can have different normals depending on wich triangle is being drawn.
The data structure is composed of a big vertex array, and a number of index arrays.
Each index array is associated with a normal. ( all triangles with a given normal get drawn all at once ). So drawing is done with the follwoing:
Code:
for( unsigned int i = 0 ; i < mNumOfSets ; i++ )
{
{
glNormal3fv( mVertexSets[i].normal ) ;
glDrawElements( GL_TRIANGLES ,
mVertexSets[i].mNumVertices ,
GL_UNSIGNED_SHORT ,
mVertexSets[i].mVerticesIndexes ) ;
}
}So I figured that , since I know the normal for a ( potentially VERY big ) number of triangles, I could take the normal, tranform it in the ModelView matrix, and if the z component of the result if greater than the cosine of the FOV ( well, that's not exactly mathematicaly correct, but you get the idea ), I can discard all those triangles. Resulting in more efficient back face culling... However, I have a strange feeling that I'm overlooking something here
So my question is: Is this making sense?

Edit: great, I double checked my post, but managed to make a typo in the thread title
Usually one would just take the dot product between your camera direction and the normal of the polygon. If the result is negative then that face is back-facing and you can throw it out. However much you optimize this operation, letting your video card handle it for you will almost certainly be faster though.
Back face culling ( by the video card ) is done depending in wich direction the poly is wound. That means that GL has to tranform all the poly's vertices before it can determine if the poly is culled or not.
Also, normals are a vertex attribute, not a poly one.
By batch doing the operation on the normal for a bunch of polygons ( in my case, about 500 polys for certain normals ). I save a lot of trouble, or at least I think so.
Note however, that this is meant to complement, not replace, GL's standard back face culling.
Also , your dot-product would work if the only matrix operations were the camera. Rotating an object would likely screw everything up.
It's not a question of how to do it. ( pretty simple actually ), but wether the whole idea makes sense or not.
Also, normals are a vertex attribute, not a poly one.
By batch doing the operation on the normal for a bunch of polygons ( in my case, about 500 polys for certain normals ). I save a lot of trouble, or at least I think so.
Note however, that this is meant to complement, not replace, GL's standard back face culling.
Also , your dot-product would work if the only matrix operations were the camera. Rotating an object would likely screw everything up.
It's not a question of how to do it. ( pretty simple actually ), but wether the whole idea makes sense or not.
This will work provided the triangles you are grouping together are coplanar.
why? I don't see how this would be a problem, since a normal is just a direction.
Ahh, I think I understand what you mean, I forgot to mention, the normals passed are the actual polygon normals.
Ahh, I think I understand what you mean, I forgot to mention, the normals passed are the actual polygon normals.
I'm sorry, you are correct. One first has to transform the normal by the modelview matrix... And I see that I misinterpreted your original post as well (sorry, was distracted when I first answered). If you can discard a large number of backfacing poly's that would be good, and the method you describe sounds like it will work to me.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Calculate face direction from bvh or 3d skeleton data | harisz | 3 | 395 |
May 29, 2013 10:50 AM Last Post: OneSadCookie |
|
| OpenGL ES2 matrix setup (humbly crawling back) | Fenris | 2 | 5,329 |
Aug 31, 2011 06:47 AM Last Post: Fenris |
|
| The tabbing on a word playing back the recorded voice | itcreate | 0 | 2,010 |
Jun 25, 2010 02:06 PM Last Post: itcreate |
|
| glDrawElements and Face indices | Ashford | 8 | 8,264 |
Nov 11, 2009 03:03 PM Last Post: Ashford |
|
| Simple ray-face intersect optimization | NYGhost | 8 | 4,772 |
Aug 17, 2007 12:01 PM Last Post: NYGhost |
|

