2013-11-30 16:33:06 -05:00
|
|
|
uniform sampler2D tex;
|
|
|
|
|
2014-11-11 15:52:54 -05:00
|
|
|
uniform float density;
|
2013-11-30 16:33:06 -05:00
|
|
|
uniform vec3 col;
|
|
|
|
|
2014-05-02 12:11:34 -04:00
|
|
|
out vec4 FragColor;
|
|
|
|
|
|
|
|
|
|
|
|
vec4 getPosFromUVDepth(vec3 uvDepth, mat4 InverseProjectionMatrix);
|
2014-01-08 18:11:10 -05:00
|
|
|
|
2013-11-30 16:33:06 -05:00
|
|
|
void main()
|
|
|
|
{
|
2014-11-11 16:43:25 -05:00
|
|
|
vec2 uv = 2. * gl_FragCoord.xy / screen;
|
2014-11-10 16:08:12 -05:00
|
|
|
float z = texture(tex, uv).x;
|
|
|
|
vec4 xpos = getPosFromUVDepth(vec3(uv, z), InverseProjectionMatrix);
|
2013-11-30 16:33:06 -05:00
|
|
|
|
2014-11-10 16:08:12 -05:00
|
|
|
float dist = length(xpos.xyz);
|
2014-11-20 15:23:33 -05:00
|
|
|
float factor = (1. - exp(- density * dist));
|
|
|
|
vec3 fog = col * factor;
|
2013-11-30 16:33:06 -05:00
|
|
|
|
2014-11-20 15:23:33 -05:00
|
|
|
// fog is scattering component, factor is the beer lambert absorption
|
|
|
|
FragColor = vec4(fog, factor);
|
2013-11-30 16:33:06 -05:00
|
|
|
}
|