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