// All content © 2010-2011 DigiPen (USA) Corporation, all rights reserved.

//Shader to implement depth testing on point sprites, against the current scene

// ---------------------------------------------------------------------------
//uniforms

//uniform sampler2D		uLightBuffer; //stores light colors
uniform sampler2D		uTex; //particle effect texture
uniform bool			uTextured; //whether this particle is textured or not

uniform float			uWidth; //window width
uniform float			uHeight; //window height
uniform float			uFarClipPlane; //camera far clip plane
uniform bool			uLighted; //whether this particle effect is affected by light

// ---------------------------------------------------------------------------
// varyings

varying vec3			vViewSpacePos; //position of this particle in view space
varying float			vCos_a; //cos(A) where A is the rotation angle in radians
varying float			vSin_a; //sin(A) where A is the rotation angle in radians

// ---------------------------------------------------------------------------

void main()
{
	//transform from screenspace to texture coordinates
	vec2 texCoord = vec2( gl_FragCoord.x/uWidth, gl_FragCoord.y/uHeight );

	//rotate the tex coordinates to simulate point sprite rotation
	vec2 coords = gl_TexCoord[0].st - vec2( 0.5, 0.5 ); //rotate around center
	vec2 texCoord2 = vec2( vCos_a * coords.s - vSin_a * coords.t, vSin_a * coords.s + vCos_a * coords.t );
	texCoord2.s += 0.5;
	texCoord2.t += 0.5;

    gl_FragColor = ( uTextured ? texture2D( uTex, texCoord2 ) * gl_Color : gl_Color );

	//this is a super hacky way of "lighting" particles
/*	if ( uLighted )
	{
		vec4 diffuse = texture2D( uLightBuffer, texCoord );
		float luminance = 0.2125 * diffuse.r + 0.7154 * diffuse.g + 0.0721 * diffuse.b;
		gl_FragColor *= vec4( luminance, luminance, luminance, 1.0 );
	}*/
}




