17d4353eb241868cbe85464b0ca02e7e044171e5
[demo] / gl_shaders / default.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 varying vec3 pos;
10 varying vec3 normal;
11 varying vec3 ldir;
12 varying vec2 tex_coord;
13
14 const float fog_density = 0.005;
15 const vec4 sky_color = vec4(0.35, 0.5, 0.65, 1.0);
16
17 out vec4 color;
18
19 void main()
20 {
21         vec3 p = normalize(pos); // view space dir
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         float dist = -pos.z;
32         float fog = clamp(exp(-fog_density * dist), 0.0, 1.0);
33
34         vec4 texel = texture2D(tex, tex_coord);
35
36         vec4 object_color;
37         object_color.xyz = diffuse.xyz * cdiff * texel.xyz + specular.xyz * cspec;
38         object_color.w = 1.0;
39
40         color = mix(sky_color, object_color, fog);
41 }