fog.frag 544 B

123456789101112131415161718192021222324
  1. uniform sampler2D tex;
  2. uniform float density;
  3. uniform vec3 col;
  4. out vec4 FragColor;
  5. vec4 getPosFromUVDepth(vec3 uvDepth, mat4 InverseProjectionMatrix);
  6. void main()
  7. {
  8. vec2 uv = gl_FragCoord.xy / screen;
  9. float z = texture(tex, uv).x;
  10. vec4 xpos = getPosFromUVDepth(vec3(uv, z), InverseProjectionMatrix);
  11. float dist = length(xpos.xyz);
  12. float factor = (1. - exp(- density * dist));
  13. vec3 fog = col * factor;
  14. // fog is scattering component, factor is the beer lambert absorption
  15. FragColor = vec4(fog, factor);
  16. }