Jump to content
  • Advertisement
Sign in to follow this  
Geometrian

OpenGL Fixed-Function Light Flickering when dot(N,L)=0

This topic is 1928 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

Hi,

 

I have a bizarre problem. There is a simple OpenGL fixed-function light drawn at (0.0f,10.0f,-1.0f). There are several boxes that happen to have faces lying in the plane z=-1.0f. Consequently, the light vector and the normal are exactly orthogonal.

 

When this happens, instead of being black, the color flickers light and dark along that face, even when the camera is stationary. The draw settings are identical each frame. It's not a z-fighting effect; there's only one layer of polygons, and the flickering continues even when the camera is stationary. Each vertex of the face appears either lit or unlit, though it's unpredictable which a given vertex will be from frame to frame.

 

The light has no ambient, and by tweaking the light's diffuse and specular factors, I find that the problem only occurs when the light's specular coefficient is nonzero. Perturbing the light slightly along z fixes the problem; it's only when the light is exactly in line with the surface that the problem occurs. I can fix the problem better by just using a shader (which I plan to do anyway), but I'm wondering if anyone has encountered this before?

 

I suspect it may be some kind of driver bug.

Hardware: NVIDIA GeForce GTX 580M

Driver: 305.60

 

Thanks,

-G

Edited by Geometrian

Share this post


Link to post
Share on other sites
Advertisement

I'm not sure what effect you are trying to achieve doing this. Floating point numbers do not have infinite precision so the light is sometimes located in front of the face and sometimes behind it. If I remember correctly, DirectX do not have two sided lightning in the fixed pipeline, so you compute the specular color (the diffuse color is clearly mostly zero in both cases) in only one of the two cases and you thus have flickering. Shaders may helo fixing this, but I do not understand why you want a light located on a surface in this way.

Share this post


Link to post
Share on other sites

This just ended up happening accidentally; it seemed like undefined/wrong behavior. I was just trying to achieve basic fixed-function lighting.

 

When N dot L is 0.0, then R, the reflected light direction is the same no matter which way the normal faces. This is then dotted against the viewing ray to produce a specular term. This is raised to the power of the specular coefficient.

 

The only thing I can think of is that the driver is optimizing the case where N dot L < 0 and not computing any specular at all, causing variation among different vertices because of floating point precision. This is sorta plausible since even at extremely low angles, specular can still be strong. But it still doesn't explain why the variation can change each frame.

Share this post


Link to post
Share on other sites

The last time I used the fixed pipeline was years ago and I do not remember the details. What happen when you move the light behind the surface? If the polygon has no lightning, then lights behind a surface are ignored as I said in my last post. Since the light is located on the surface, any small change may cause the light to move between the two "states" (in front or behind the surface). I think you should simply try to avoid such cases (or use shaders to make it work as you wish).

Share this post


Link to post
Share on other sites

What happen when you move the light behind the surface?

Perturbing the light slightly along z fixes the problem

.

Since the light is located on the surface, any small change may cause the light to move between the two "states" (in front or behind the surface).

Yes, but the diffuse should be ~0.0 in either case, and while specular can jump, the only time it should be visible at all is at an extreme glancing angle (0.0, to be specific, in which case it's edge-on and not visible anyway).

The problem recurred in a shader, but I managed to solve it. It was related to the object's tangents for normalmapping (they weren't being passed in). This doesn't explain why the fixed function pipeline was being drawn incorrectly, however.

Share this post


Link to post
Share on other sites

Maybe some variable that is being applied to the lighting is not initialized. This will cause flickering. It might be present at other angles but washed out so you can only see it where the model is dark.

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!