X-Git-Url: http://git.mutantstargoat.com?a=blobdiff_plain;f=gl_shaders%2Fdefault.f.glsl;h=f0f61d83eaa85c143c461eea22e381c35b33a3e0;hb=198fff0ac38a65f6c2db8d9061e47481febfb008;hp=388ba76a607608108f07ad2a31ebf4b6f5d74345;hpb=d03d86eb8489e7ab4c5460cea5ee265b0c1ee487;p=demo diff --git a/gl_shaders/default.f.glsl b/gl_shaders/default.f.glsl index 388ba76..f0f61d8 100644 --- a/gl_shaders/default.f.glsl +++ b/gl_shaders/default.f.glsl @@ -9,13 +9,17 @@ uniform float shininess; varying vec3 pos; varying vec3 normal; varying vec3 ldir; -varying vec3 tex_coord; +varying vec2 tex_coord; -layout(location = 0) out vec4 color; +// const float fog_density = 0.005; +uniform float fog_density; +const vec3 sky_color = vec3(0.35, 0.5, 0.65); + +out vec4 color; void main() { - vec3 p = normalize(pos); + vec3 p = normalize(pos); // view space dir vec3 n = normalize(normal); vec3 l = normalize(ldir); @@ -25,5 +29,13 @@ void main() float cdiff = max(dot(l, n), 0.0); float cspec = pow(max(dot(r, vdir), 0.0), shininess); - color = diffuse * cdiff * texture2D(tex, tex_coord.xy) + specular * cspec; + float dist = -pos.z; + float fog = clamp(exp(-fog_density * dist), 0.0, 1.0); + + vec4 texel = texture2D(tex, tex_coord); + + vec3 object_color = diffuse.xyz * cdiff * texel.xyz + specular.xyz * cspec; + + color.xyz = mix(sky_color, object_color, fog); + color.w = 1.0; }