Specular of GLSL point light

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

Recommended Posts

I've been banging my head on the keyboard for a couple of days now, perhaps one of you could point me in the right direction here. I have a specific light setup (one positional fill light and one directional kicker light) that works fine in fixed functionality, but that I can't seem to mimic on the shader path. Here's the shader (no fragment part)
void main()
{
const int kFillLight = 0, kKickLight = 1;

gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;

vec3 normal = gl_NormalMatrix * gl_Normal;
vec3 vertex = (gl_ModelViewMatrix * gl_Vertex).xyz;

vec3 fillLightDir = normalize (gl_LightSource[kFillLight].position.xyz - vertex);
vec3 kickLightDir = normalize (gl_LightSource[kKickLight].position.xyz);

float fillNDotL = max (0.0, dot (normal, fillLightDir));
float kickNDotL = max (0.0, dot (normal, kickLightDir));

vec3 globalAmbient = gl_LightModel.ambient.rgb * gl_FrontMaterial.ambient.rgb;

vec4 fillDiffuse = gl_FrontMaterial.diffuse * gl_LightSource[kFillLight].diffuse;
vec4 kickDiffuse = gl_FrontMaterial.diffuse * gl_LightSource[kKickLight].diffuse;

vec3 fillSpecular = vec3(0), kickSpecular = vec3(0);

if (kickNDotL > 0.0)
{
vec3 halfVector = normalize (gl_LightSource[kKickLight].halfVector.xyz);
float nDotHV = max (0.0, dot (normal, halfVector));
kickSpecular = gl_FrontMaterial.specular.rgb * gl_LightSource[kKickLight].specular.rgb * pow (nDotHV, gl_FrontMaterial.shininess);
}
if (fillNDotL > 0.0)
{
vec3 halfVector = normalize (fillLightDir - normalize(vertex));
float nDotHV = max (0.0, dot (normal, halfVector));
fillSpecular = gl_FrontMaterial.specular.rgb * gl_LightSource[kFillLight].specular.rgb * pow (nDotHV, gl_FrontMaterial.shininess);
}

vec3 ambient =	globalAmbient;
vec3 diffuse =	kickDiffuse.rgb * kickNDotL + fillDiffuse.rgb * fillNDotL;
vec3 specular = kickSpecular.rgb + fillSpecular.rgb;

gl_FrontColor = vec4 (ambient + diffuse + specular, gl_FrontMaterial.diffuse.a);
}

The problem is that the specular reflection from the point light (fill light, calculated in the fillNDotL > 0.0 clause) seems to come from the wrong direction. I've pretty much confirmed this: if I turn the specular reflection of the point light down to zero, the rendering is identical. If I make the point light a directional light, the rendering is identical. Hence, it is the point/specular combination that is at fault. I'm unsure if the eye vector is correctly calculated - is it just -vertex even if I have translated the entire scene? Any help would be greatly appreciated!

Share on other sites
Try to compute your own half vector. From my experience gl states arent supported very well. You can check it by mapping gl_LightSource[kKickLight].halfVector.xyz to a color range and displaying it directly.

Share on other sites
Thanks, but that's what I'm doing with the problematic light. The kick light is fine, but the fill light is definitely off by a lot. I can't use the GL computed half-vector because it assumes that the light is directional... So if you could help me with finding the proper eye vector to build the half-vector..?

1. 1
2. 2
Rutin
20
3. 3
khawk
16
4. 4
A4L
14
5. 5

• 11
• 16
• 26
• 10
• 11
• Forum Statistics

• Total Topics
633756
• Total Posts
3013707
×