varying vec3 ViewPos;
varying vec4 projPos;

uniform sampler2D Color0;
uniform sampler2D Position;
uniform float Scale;

void main()
{
  // color is offset
  vec3 color  = texture2D( Color0, gl_TexCoord[0].st ).rgb;

  // for soft particles, but fails
  // attenuate based on scene
  vec2 texCoordAt = projPos.xy / projPos.w * 0.5 + 0.5;
  const float minDepth = 1.0;//Scale;
  float bbDepth = length( ViewPos );
  float sDepth = texture2D( Position, texCoordAt ).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]
  color *= att; // attenuate as approaches scenery

  gl_FragColor = vec4( color, 0.0 );
}
