varying vec4 projPos;
varying float z;

uniform sampler2D Color0;   // scene color
uniform sampler2D Color1;   // radial mask
uniform sampler2D Position; // for soft particle effect

void main()
{
  // read mask
  vec3 color = texture2D( Color1, gl_TexCoord[0].st ).rgb;
  
  // screen pos
  vec2 texCoordAt = projPos.xy / projPos.w * 0.5 + 0.5;

  // tunable param
  float exposure = 0.2;

  // attenuate based on scene
  const float minDepth = 1.0;
  float sDepth = texture2D( Position, texCoordAt ).w;
  float dDepth = sDepth - z;
  float att = dDepth / minDepth; // converts attenuation to [0, some pos value]
  att = min( att, 1.0 ); // clamp to [0,1]
  color *= ( exposure * att ); // attenuate as approaches scenery
  
  gl_FragColor = vec4( color, 0.0 );
}
