

uniform mat4 second_camera;

varying vec2 texcoord;
varying vec4 second_pos;
varying vec4 color;

#vertexshader

void main()
{
	gl_Position = ftransform();
	second_pos = gl_ProjectionMatrix * second_camera * gl_Vertex;
	texcoord = gl_MultiTexCoord0.xy;
	color = gl_Color;
}

#fragmentshader

uniform sampler2D depth_texture;
uniform vec2 screen_size;

void main(void)
{
	/*vec2 screen_size;
	screen_size.x = 1280.0;
	screen_size.y = 720.0;*/
	
	// convert to texture coordinates
	vec3 coord =
		(second_pos.xyz*(1.0/second_pos.w) // clip -> normalized
		+ vec3(1.0, 1.0, 1.0))*0.5; // -1 to 1 -> 0 to 1

	// sample depth
	float d = texture2D(depth_texture, coord.xy).x;

	// make sure we don't show anything behind the screen
	//if(second_pos.z < 11.4)
	//	discard;
	
	/*if(d < coord.z)
	{
		discard;
		//gl_FragColor = vec4(1,0,0,1); //discard;
	}
	else*/
	{
		//gl_FragColor = vec4(1,0,0,color.a*1.0/256.0*8.0); //discard;
		gl_FragColor = vec4(color.xyz,color.a*1.0/256.0*8.0);
	}
}

