uniform vec4 specular;
uniform float shininess;
+uniform float fog_density;
+const vec3 sky_color = vec3(0.35, 0.5, 0.65);
+
varying vec3 pos;
varying vec3 normal;
varying vec3 ldir;
float cspec = pow(max(dot(r, vdir), 0.0), shininess);
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;
+
+ float dist = -pos.z;
+ float fog = clamp(exp(-fog_density * dist), 0.0, 1.0);
+
+ color.xyz = mix(sky_color, object_color, fog);
color.w = 1.0;
}