fixed issues in shaders
[demo] / gl_shaders / morphing.f.glsl
1 #version 450
2
3 uniform sampler2D tex;
4
5 uniform vec4 diffuse;
6 uniform vec4 specular;
7 uniform float shininess;
8
9 uniform float fog_density;
10 const vec3 sky_color = vec3(0.35, 0.5, 0.65);
11
12 varying vec3 pos;
13 varying vec3 normal;
14 varying vec3 ldir;
15 varying vec2 tex_coord;
16
17 out vec4 color;
18
19 void main()
20 {
21         vec3 p = normalize(pos);
22         vec3 n = normalize(normal);
23         vec3 l = normalize(ldir);
24
25         vec3 r = normalize(-reflect(l, n));
26         vec3 vdir = normalize(-p);
27
28         float cdiff = max(dot(l, n), 0.0);
29         float cspec = pow(max(dot(r, vdir), 0.0), shininess);
30
31         vec4 texel = texture2D(tex, tex_coord);
32         vec3 object_color = diffuse.xyz * cdiff * texel.xyz + specular.xyz * cspec;
33
34         float dist = -pos.z;
35         float fog = clamp(exp(-fog_density * dist), 0.0, 1.0);
36
37         color.xyz = mix(sky_color, object_color, fog);
38         color.w = 1.0;
39 }