Jump to content
  • Advertisement
Sign in to follow this  
CyberSlag5k

Faces flickering lit and unlit

This topic is 4730 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
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




Share this post


Link to post
Share on other sites
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
glFrontFace(GL_CCW) or
glFrontFace(GL_CW)
depending on whether you want clock-wise or counter-clock-wise.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!