Created
May 20, 2013 13:40
-
-
Save rgngl/5612286 to your computer and use it in GitHub Desktop.
fog shader
This file contains hidden or 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
uniform float u_fogMaxDist; | |
uniform float u_fogMinDist; | |
uniform vec4 u_fogColor; | |
varying vec4 v_eyePos; | |
float computeLinearFogFactor() | |
{ | |
float factor; | |
// Compute linear fog equation | |
factor = (u_fogMaxDist - length(v_eyePos.xyz)) / | |
(u_fogMaxDist - u_fogMinDist ); | |
// Clamp in the [0,1] range | |
factor = clamp( factor, 0.0, 1.0 ); | |
return factor; | |
} | |
vec4 getColorWithFog(vec4 baseColor) | |
{ | |
float a = baseColor.a; | |
float fogFactor = computeLinearFogFactor(); | |
vec4 fogColor = fogFactor * u_fogColor; | |
vec4 c = baseColor * fogFactor + fogColor * (1.0 - fogFactor); | |
c.a = a; | |
return c; | |
} |
This file contains hidden or 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
varying vec4 v_eyePos; | |
uniform mat4 u_worldViewMatrix; | |
void applyEyePos(vec4 position) | |
{ | |
v_eyePos = u_worldViewMatrix * position; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment