Hello,
[video of the problem : http://robot.isp.imath.be/phong.flv]
I try to implement a simple Phong shader , it works nicely , but the main light is following the camera
and I cant figure out why, since I converted a code from GeeksLab (line by line), it should do the same
lightPosition comes from a shader node parameter (lightPosition = MatParam.LightPosition)
void main(){
normal = normalMatrix * normal;
//not sure if I should use WorldViewMatrix
vec4 v=vec4(worldViewMatrix* vec4(modelPosition,1.0)); // WorldViewMatrix = glModelViewMatrix ???
lightDir = lightPosition.xyz- v.xyz;
eyeVec=-v.xyz;
//----- in the following node :
projPosition = worldViewProjectionMatrix * vec4(modelPosition, 1.0);
}
void main(){
vec3 _normal= normalize(normal);
vec3 _lightDir=normalize(lightDir);
// diffuse -----------------------------------------------------------------------------------------------------------------
vec4 diffuse = vec4(0.7,0.7,0.7,1);
lambertTerm = max(dot(_normal, _lightDir), 0.0);
vec4 Id = lightDiffuse * diffuse * lambertTerm;
// phong
vec3 E = normalize(eyeVec).xyz;
vec3 R = normalize(reflect(-_lightDir,_normal));
float spec = pow( max(dot(R,E), 0.0), shininess );
vec4 Is = specular * lightSpecular * spec;
//
outColor = Id + Is;
}
can someone have a look ?
thanks