Sign in to follow this  
CyberSlag5k

Faces flickering lit and unlit

Recommended Posts

CyberSlag5k    514
My models are lit using vertex normals, which appear to work properly at first, but if the model is rotated at all, entire faces flicker on and off. I'm lighting each vertex based on the normal data provided for each vertex in my model editor's output file, and it looks like good surface lighting until you move the model. Moving the camera has no affect on the light (I set the light's position each frame, after orienting the camera), just rotating the object. It appears to only happen to the faces on the edge of the light (where the part of the model is in darkness), and as I said the entire face flickers on or off (depending on its mood, as it would seem). I've double checked the vertex normal data the model is being drawn with against the data in the file I'm using from the editor, and the values appear to be just fine. And as I said it looks to be properly lit via vertex normals, until the object is rotated (translations have no affect), at such time entire faces flicker (which is bizarre as I'm giving GL vertex normals). Might someone offer a reason for what is going on? More information will gladly supplied as needed. Thanks as always!

Share this post


Link to post
Share on other sites
Lutz    462
I'd bet every triangle actually exists twice:
Once with a front-facing normal and once with a back-facing normal.
Plus you have backface culling turned off.

When OpenGL tries to draw this, it depends on the mood of the z-buffer which of the two
triangles is actually drawn, because they have actually the same z-position (since they have
the same vertices). But due to rounding errors, both triangles are drawn once in a while
when you rotate the model. Since one normal faces front and the other back, one triangle
is lit, the other is not. This produces the flickering.

Either try eliminating the unnecessary triangles OR (easier) enable backface culling:
glEnable(GL_CULL_FACE);
Doing so, OpenGL only draws the front-facing triangles and ignores the back-facing ones.

Lutz




Share this post


Link to post
Share on other sites
CyberSlag5k    514
Hmm...I'll look into whether or not I'm drawing unnecessary triangles. I have made a few changes to the model class as of late, so something could have snuck in. Enabling cull facing has shown me that my faces are all being drawn backwards (the forward facing ones are getting culled while the rear-facing ones remain), so I'll need to fix that too. I used to remember how to do such a thing...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this