View Full Version : Specular Lighting Problems
08-13-2010, 12:42 PM
In order to compensate for meshes that sometimes have reversed normals(vertex ordering is out of my control), I am lighting my model with two lights (one at 0,0,1 and one at 0,0,-1). I am using the fixed functionality pipeline.
This works for diffuse lighting with quads in the mesh that have incorrect normals because the light at 0,0,-1 lights the quads that have the reverse normal.
My problem is that not specular lighting appears for the reversed normals and when I disable the light at 0,0,1 I see no specular lighting. Why is this different than diffuse???
Shouldn't the quads that are reversed by light with specular lighting from the light at 0,0,-1?
08-13-2010, 02:31 PM
After gaining a better understanding of the formulas for calculating specular lighting I see that the eye vector is used in the calculation. So if there is something like:
dot_product = max(dot(normal, gl_LightSource.halfVector.xyz), 0);
where the half vector is the eye vector - light vector then specular light will be zero for all normals facing away from the eye vector.
Does anyone know the exact formula used by the fixed functionality pipeline? Is there a way around this or do I have to write a shader?
By the way, I came to the conclusions above by using the GLSL tutorial for directional lights at lighthouse3d (http://www.lighthouse3d.com/opengl/glsl/index.php?ogldir2) and verified I saw the same behavior with the vertex shader. Then I modified it to not use the light vector instead of the half vector and I got the lighting I wanted.
08-13-2010, 04:46 PM
After gaining a better understanding of the formulas for calculating specular lighting I see that the eye vector is used in the calculation.
Does anyone know the exact formula used by the fixed functionality pipeline?
It's in the Lighting chapter in the OpenGL Programming Guide (link (http://glprogramming.com/red/chapter05.html#name7)). Look toward the end in The Mathematics of Lighting section.
Also google ShaderGen for source code that'll generate GLSL shaders to mimic the function of the fixed-function pipeline, including lighting.
Is there a way around this or do I have to write a shader?
With the fixed-function pipeline, you don't have much/any control over the "form" of the lighting equation, but merely control over how its terms are computed. You can chose to have specular or not. You can choose whether the eye is considered infinitely-far away or "local" to the object (LIGHT_MODEL_LOCAL_VIEWER). You can chose whether specular is added on after texturing or before (SEPARATE_SPECULAR_COLOR).
But AFAIK, you don't have much control on the equation used to compute specular. This doesn't really change.
Of course with a shader, you can do whatever you want.
08-13-2010, 04:49 PM
In order to compensate for meshes that sometimes have reversed normals ... My problem is that not specular lighting appears for the reversed normals and when I disable the light at 0,0,1 I see no specular lighting.
I should have read your first post first.
Have you tried LIGHT_MODEL_TWO_SIDE?
You might have to play with glFrontFace/CULL_FACE to get what you want.
If you're setting materials, make sure to set them FRONT_AND_BACK.
08-16-2010, 09:15 AM
Thanks for the suggestions!
I have tried LIGHT_MODEL_TWO_SIDE but it just calculates back side normals and because of some normals facing forward and some facing back (again, I am stuck with this out of my control for the time being or I would fix this) the ones facing backwards only get diffuse light. In other words, for a mesh that has all the front faces visible, some of the normals are forwards and some are backwards because of the vertex ordering.
In the past, I got around this with two lights but when I wanted to add specular lighting I hit this problem. I will probably leave out specular lighting until I can address the vertex ordering issue or start using shaders.
08-16-2010, 10:54 AM
I have tried LIGHT_MODEL_TWO_SIDE but it just calculates back side normals and because of some normals facing forward and some facing back... the ones facing backwards only get diffuse light.
Sorry about that. At the time I thought LIGHT_MODEL_TWO_SIDE just flipped the normal toward the eyepoint (sounds like what you want) but instead it only flips it for back faces.
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.