This is the relevant section of my fragment shader
varying vec3 normal;
varying vec3 halfv;
...
vec4 color = ambient * gl_LightSource[0].ambient;
vec3 n = normalize(normal);
float nl = max(dot(n, gl_LightSource[0].position.xyz), 0.0);
if (nl > 0.0)
color += (diffuse * gl_LightSource[0].diffuse * nl)
+ (specular * gl_LightSource[0].specular * pow(max(dot(n, normalize(halfVector)), 0.0), shininess));
gl_FragColor = color;
Where ambient, diffuse, specular, and shininess are all already defined. normal
and halfv
are defined in my vertex shader as
normal = normalize(gl_NormalMatrix * gl_Normal);
halfv = gl_LightSource[0].halfVector.xyz;
My light is directional, position is set to 100, 100, 100, 0
. Ambient, diffuse, and specular values are 1, 1, 1, 1
, .01, .01, .01, 1
, and 0, 0, 0, 1
, respectively. When might light vector is 100, 100, 100, 0
, the entire mesh appears ambient lit. Any other position or magnitude causes the mesh to go dark, only showing the ambient component.
EDIT
This is the updated fragment shader:
vec4 color = ambient * gl_LightSource[0].ambient;
vec3 n = normalize(normal);
vec3 ldir = normalize(gl_LightSource[0].position.xyz);
vec3 halfv = normalize(normalize(cam) + ldir);
float nl = max(dot(n, ldir), 0.0);
if (nl > 0.0)
color += (diffuse * gl_LightSource[0].diffuse * nl)
+ (specular * gl_LightSource[0].specular * pow(max(dot(n, normalize(halfv)), 0.0), shininess));
gl_FragColor = color;
and vertex shader:
normal = normalize(gl_NormalMatrix * gl_Normal);
cam = camera_pos.xyz - gl_Vertex.xyz;
I'm still seeing a dark, ambient tone only. I've also normalized my vector CPU side, now as 1, 1, 1, 1