Created
March 30, 2014 15:15
-
-
Save ishikawash/9874247 to your computer and use it in GitHub Desktop.
Fog effect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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