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;
  // distance func for alpha test
  //color.a = texture2D( Distance, gl_TexCoord[0].st ).g;// whee hooo
  // scale by distance
  //color.a *= ( 1000.0 + ViewPos.z ) / 1000.0;

  float luma = dot(color, vec3(0.299, 0.587, 0.114));
  luma *= 4.0;
  luma /= luma + 1.0;
  vec3 modColor = gl_Color.rgb;
  color = luma * modColor;

  // 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 );
}
