Faces flickering lit and unlit

Started by
4 comments, last by CyberSlag5k 18 years, 8 months ago
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!
Without order nothing can exist - without chaos nothing can evolve.
Advertisement
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




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...
Without order nothing can exist - without chaos nothing can evolve.
Just tell OpenGL the widing or is clockwise instead of counter clockwise, that'll fix things with the backface culling [grin]
glFrontFace(GL_CCW) or
glFrontFace(GL_CW)
depending on whether you want clock-wise or counter-clock-wise.
Thanks guys :)
Without order nothing can exist - without chaos nothing can evolve.

This topic is closed to new replies.

Advertisement