Directional light per vertex

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!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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);	
    

    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
Topic archived. No new replies allowed.