PageRenderTime 12ms CodeModel.GetById 9ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/extra/gpu/demos/bunny/bunny.f.glsl

http://github.com/abeaumont/factor
Unknown | 39 lines | 31 code | 8 blank | 0 comment | 0 complexity | 19c82ac438f918421182d9230efa3c00 MD5 | raw file
 1#version 110
 2
 3uniform mat4 mv_matrix, p_matrix;
 4uniform vec4 color, ambient, diffuse;
 5uniform float shininess;
 6
 7varying vec3 frag_normal;
 8varying vec3 frag_light_direction;
 9varying vec3 frag_eye_direction;
10
11float
12cel(float d)
13{
14    return smoothstep(0.25, 0.255, d) * 0.4 + smoothstep(0.695, 0.70, d) * 0.5;
15}
16
17vec4
18cel_light()
19{
20    vec3 normal = normalize(frag_normal),
21         light = normalize(frag_light_direction),
22         eye = normalize(frag_eye_direction),
23         reflection = reflect(light, normal);
24
25    float d = dot(light, normal) * 0.5 + 0.5;
26    float s = pow(max(dot(reflection, -eye), 0.0), shininess);
27
28    vec4 amb_diff = ambient + diffuse * vec4(vec3(cel(d)), 1.0);
29    vec4 spec = vec4(vec3(cel(s)), 0.0);
30
31    return amb_diff * color + spec;
32}
33
34void
35main()
36{
37    gl_FragData[0] = cel_light();
38    gl_FragData[1] = vec4(frag_normal, 0.0);
39}