uniform sampler2D Normal;   // eye space normal
uniform sampler2D Color0;

varying vec3 lightPos;
varying vec3 eyePos;
varying vec4 projPos;
varying float pos;
varying float dist;

const vec3 lightColor = vec3( 0.95, 0.97, 0.755 );

void main()
{
  // get screen coords from projected position
  vec2 texCoord = projPos.xy / projPos.w * .5 + .5;
  
  // normalize eye vector
  vec3 e = normalize( eyePos );

  vec4 buff = texture2D( Normal, texCoord );
  vec4 sceneColor = texture2D( Color0, texCoord );

  float exposure = 1.0 - ( dist / ( dist + 1.0 ) );
  exposure *= 0.2;
  // attenuate based on scene
  const float minDepth = 12.0;
  float bbDepth = pos;
  float sDepth = buff.w;
  float dDepth = sDepth - bbDepth;
  float att = dDepth / minDepth;                // converts attenuation to [0, some pos value]
  att = min( att, 1.0 );                        // clamp to [0,1]
  vec3 color = lightColor * ( exposure * att ); // attenuate as approaches scenery
  
  sceneColor.rgb += color;

  gl_FragColor = vec4( color, 0.0 );//sceneColor;
}
