fixed issues in shaders
[demo] / gl_shaders / default.f.glsl
index 490efab..f0f61d8 100644 (file)
@@ -11,11 +11,15 @@ varying vec3 normal;
 varying vec3 ldir;
 varying vec2 tex_coord;
 
+// 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,7 +29,13 @@ void main()
        float cdiff = max(dot(l, n), 0.0);
        float cspec = pow(max(dot(r, vdir), 0.0), shininess);
 
+       float dist = -pos.z;
+       float fog = clamp(exp(-fog_density * dist), 0.0, 1.0);
+
        vec4 texel = texture2D(tex, tex_coord);
-       color.xyz = diffuse.xyz * cdiff * texel.xyz + specular.xyz * cspec;
+
+       vec3 object_color = diffuse.xyz * cdiff * texel.xyz + specular.xyz * cspec;
+
+       color.xyz = mix(sky_color, object_color, fog);
        color.w = 1.0;
 }