View Full Version : gl_FrontLightProduct[i].specular not working?

08-20-2010, 08:34 AM
I have made a Shader that has both specular lightning and multiple lights. But, I can't get it to work properly.

gl_FrontLightProduct[i].diffuse and gl_FrontLightProduct[i].ambient work just great. But whenever I put in gl_FrontLightProduct[i].specular, my specular lighting quits working.

Any ideas on what is going on?

Frag shader:

#define MAX_LIGHTS 8
#define NUM_LIGHTS 1
varying vec3 lightVec[NUM_LIGHTS];
varying vec3 halfVec[NUM_LIGHTS];
uniform sampler2D colorMap;
uniform sampler2D normalMap;
uniform sampler2D specularMap;
uniform float shininess;

void main(void)
vec2 uv = gl_TexCoord[0].st;
vec4 base = texture2D(colorMap, gl_TexCoord[0].st);
vec4 final_color = vec4(0.0, 0.0, 0.0, 0.0);
vec3 bump =normalize(texture2D(normalMap, gl_TexCoord[1].st).xyz * 2.0 - 1.0);
vec4 specularColor=texture2D(specularMap, gl_TexCoord[2].st);

int i;
for (i=0; i<NUM_LIGHTS; ++i)
vec4 vAmbient=gl_FrontLightProduct[i].ambient*base;
final_color += vAmbient;

vec3 lVec = normalize(lightVec[i]);
float diffuse = max(dot(lVec, bump), 0.0);
vec4 vDiffuse =gl_FrontLightProduct[i].diffuse *diffuse * base;
final_color += vDiffuse;

float specularModifier=max(dot(bump, normalize(halfVec[i])), 0.0);
vec4 vSpecular= (specularColor *pow(specularModifier, shininess));
//previous line SHOULD BE: vec4 vSpecular= gl_FrontLightProduct[i].specular *specularColor *pow(specularModifier, shininess);
final_color += vSpecular;
gl_FragColor = clamp(final_color, 0.0, 1.0);

08-20-2010, 11:15 AM
Make sure your light specular (gl_LightSource[i].specular) and material specular (gl_FrontMaterial.specular) are not black.

08-20-2010, 11:41 AM
I am very sure that they are not black.

As my specular works (albiet a bit odd without the proper light), WITHOUT gl_LightSource[i].specular. So I know that material is good.

And I am setting the specular component of the light to be (1.0, 1.0, 1.0, 1.0), So I am sure it the light is not black.

Could it be my graphics card??

I havn't had a chance to try it on anouther computer yet. I am using Python, and PyInstaller and Py2EXE don't work with OpenGL very well.

08-20-2010, 12:26 PM
You don't use material specular color in the shader code (aside from the commented line), so how do you know it's good?

08-20-2010, 02:25 PM
right above the commented Line:

vec4 vSpecular= (specularColor *pow(specularModifier, shininess));

and right before the start of the loop:

vec4 specularColor=texture2D(specularMap, gl_TexCoord[2].st);

08-20-2010, 02:53 PM
That is not material specular... That is your custom specular map.

gl_FrontLightProduct[i].specular = gl_FrontMaterial.specular * gl_LightSource[i].specular

I repeat, check your material specular (gl_FrontMaterial.specular).

08-20-2010, 06:26 PM

Figured it out!

That also let me figure out some other stuff as well...