Skip to content

Instantly share code, notes, and snippets.

@ishikawash
Created March 30, 2014 15:15
Show Gist options
  • Save ishikawash/9874247 to your computer and use it in GitHub Desktop.
Save ishikawash/9874247 to your computer and use it in GitHub Desktop.
Fog effect
#version 120
struct Fog {
float start;
float density;
vec3 color;
};
uniform Fog fog;
varying vec3 vertex_color;
void main()
{
float z = gl_FragCoord.z / gl_FragCoord.w;
if (z < fog.start) {
gl_FragColor = vec4(vertex_color, 1.0);
return;
}
float k = fog.density * (z - fog.start);
float fog_factor = clamp(exp(-k*k), 0.0, 1.0);
vec3 color = mix(fog.color, vertex_color, fog_factor);
gl_FragColor = vec4(color, 1.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment