uniform mat4 inverseMVPMatrix;
uniform sampler2D depthTex;
uniform vec4 lightPos;
uniform float lightRadius;
uniform float near;
uniform float far;
varying vec2 texCoord;

void main() {
	float hyperDepth = texture2D(depthTex,texCoord).r;
	float depth = (2.0 * near) / (far + near - (hyperDepth*2.0-1.0) * (far - near));
	vec3 lightcolor = vec3(0.0);

	vec4 screenPos = vec4(texCoord.s*2.0-1.0, texCoord.t*2.0-1.0, hyperDepth*2.0-1.0, 1.0);
	vec4 worldPos = inverseMVPMatrix * screenPos;
	worldPos /= worldPos.w;
	
	if (distance(worldPos.xyz, lightPos.xyz) < lightRadius)
	{
		lightcolor = vec3(1.0);
	}
	
	if (distance(depth, lightPos.w) < 0.02)
	{
		lightcolor = vec3(1.0);
	}
	
	gl_FragColor = vec4(lightcolor, 1.0);
} 