Directional light per vertex
Jun 14, 2014 at 1:58pm UTC  
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!
1vec4 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);	
    
    vec4 ambient = ambient();
    vec4 diffuse = diffuse(normal);
    vec4 specular = specular(normal);
     gl_FrontColor = gl_Color*(ambient+difuse)+specular;
    gl_FragColor =  ambient + diffuse + specular;
    gl_Position = ftransform();
}
Last edited on Jun 14, 2014 at 2:08pm UTC  
 
Topic archived. No new replies allowed.