added IBR lighting from irradiance maps
[demo] / gl_shaders / default.f.glsl
1 #version 450
2
3 uniform sampler2D tex;
4 uniform samplerCube dstex;
5
6 uniform vec4 diffuse;
7 uniform vec4 specular;
8 uniform float shininess;
9
10 varying vec3 pos;
11 // varying vec3 normal;
12 // varying vec3 ldir;
13 varying vec2 tex_coord;
14 varying vec3 world_normal;
15
16 // const float fog_density = 0.005;
17 uniform float fog_density;
18 const vec3 sky_color = vec3(0.35, 0.5, 0.65);
19
20 out vec4 color;
21
22 void main()
23 {
24         vec4 itexel = textureCube(dstex, normalize(world_normal));
25
26 /*      vec3 p = normalize(pos); // view space dir
27         vec3 n = normalize(normal);
28         vec3 l = normalize(ldir);
29
30         vec3 r = normalize(-reflect(l, n));
31         vec3 vdir = normalize(-p);
32
33         float cdiff = max(dot(l, n), 0.0);
34         float cspec = pow(max(dot(r, vdir), 0.0), shininess); */
35
36         float dist = -pos.z;
37         float fog = clamp(exp(-fog_density * dist), 0.0, 1.0);
38
39         vec4 texel = texture2D(tex, tex_coord);
40
41         // vec3 object_color = (diffuse.xyz * cdiff * texel.xyz + specular.xyz * cspec) * itexel.xyz;
42         vec3 object_color = diffuse.xyz * texel.xyz * itexel.xyz;
43
44         color.xyz = mix(sky_color, object_color, fog);
45         color.w = 1.0;
46 }