We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello people. I'm having to implement a shader work as directional light per vertex. Already implemented but would like a review of you to know if I did correctly. Thanks!
vec4 ambient()
{
vec4 ambient = vec4 (0.0);
ambient = gl_FrontMaterial.ambient * gl_LightSource[0].ambient;
ambient += (gl_LightModel.ambient * gl_FrontMaterial.ambient);
return ambient;
}
vec4 diffuse(vec3 normal)
{
vec3 diffuse = gl_LightSource[0].position * normal;
float diff = max(dot(normal,diffuse),0.0);
diffuse = gl_LightSource[0].diffuse * gl_FrontMaterial.diffuse * diff;
return diffuse;
}
vec4 specular(vec3 normal)
{
float hv = max(dot(normal, vec3(gl_LightSource[0].halfVector)), 0.0);
float spec = pow(hv, gl_FrontMaterial.shininess);
return gl_LightSource[0].specular * gl_FrontMaterial.specular * spec;
}
void main()
{
vec3 normal = normalize(gl_NormalMatrix * gl_Normal);
gl_FrontColor = gl_Color*(ambient+difuse)+specular;
vec4 ambient = ambient();
vec4 diffuse = diffuse(normal);
vec4 specular = specular(normal);
gl_FragColor = ambient + diffuse + specular;
gl_Position = ftransform();
}