sampler2D ShadowMap;

static float4 c0 = float4(-0.000692, -0.000868, -0.002347, 0.000450);
static float4 c1 = float4(0.000773, -0.002042, -0.001592, 0.001880);
static float4 c2 = float4(-0.001208, -0.001198, -0.000425, -0.000915);
static float4 c3 = float4(-0.000050, 0.000105, -0.000753, 0.001719);
static float4 c4 = float4(-0.001855, -0.000004, 0.001140, -0.001212);
static float4 c5 = float4(0.000684, 0.000273, 0.000177, 0.000647);
static float4 c6 = float4(-0.001448, 0.002095, 0.000811, 0.000421);
static float4 c7 = float4(0.000542, 0.001491, 0.000537, 0.002367);

static float SampleWeight = 0.0625;
static float DepthBias = -0.001;

struct PS_INPUT{
	float4 ShadowPos		: TEXCOORD0;
    float Depth				: TEXCOORD1;
};

struct PS_OUTPUT{
	float4 Color			: COLOR;
};

PS_OUTPUT main(const PS_INPUT Input){
	float ZBias = Input.Depth + DepthBias;

	float Depth = tex2Dproj(ShadowMap, Input.ShadowPos);
	
	float Color;// = Depth;
	if (abs(Input.Depth - Depth) < 0.01f){
		Color = 1;
	}
	else Color = 0;
		
	//float3 Color = Input.ShadowPos.xyz / 100;

	PS_OUTPUT Out;
	Out.Color.rgb = Color;
	Out.Color.a = 1;
	return Out;
}

#if 0

PS_OUTPUT main(const PS_INPUT Input){
	//float4 Pos = tex2D(ShininessTex, Input.BaseTex);

	
	/*float Color;
	float Depth = tex2D(ShadowMap, Input.ShadowPos);
	
	if (abs(Input.Depth - Depth) < 0.1f){
		Color = 0;
	}
	else Color = 1;*.
	
	/*if (Input.Depth > Depth){	// Every z-value larger than the depth map is clamped.
		Color = 0;
	}
	else Color = 1;
	
	//Color = Depth;*/
	
	
	//float3 Color = Input.ShadowPos;
	//float Color = Input.Depth;

	/*// Start
	float ZBias = Input.Depth + DepthBias;
	
	float s0 = tex2D(ShadowMap, Input.ShadowPos + c0.xyzw);
	float s1 = tex2D(ShadowMap, Input.ShadowPos + c0.wzyx);
	float s2 = tex2D(ShadowMap, Input.ShadowPos + c1.xyzw);
	float s3 = tex2D(ShadowMap, Input.ShadowPos + c1.wzyx);
	float s4 = tex2D(ShadowMap, Input.ShadowPos + c2.xyzw);
	float s5 = tex2D(ShadowMap, Input.ShadowPos + c2.wzyx);
	float s6 = tex2D(ShadowMap, Input.ShadowPos + c3.xyzw);
	float s7 = tex2D(ShadowMap, Input.ShadowPos + c3.wzyx);
	
	float Color = 0;
	
	float4 Part1;
	Part1.x = ZBias - s0;
	Part1.y = ZBias - s1;
	Part1.z = ZBias - s2;
	Part1.w = ZBias - s3;
	
	float4 Temp1;
	for (int i = 0; i < 4; i++){
		if (-Part1[i] >= 0){
			Temp1[i] = 1;
		}
		else Temp1[i] = 0;
	}
	
	Color += dot(Temp1, float4(SampleWeight, SampleWeight, SampleWeight, SampleWeight));
	
	float4 Part2;
	Part2.x = ZBias - s4;
	Part2.y = ZBias - s5;
	Part2.z = ZBias - s6;
	Part2.w = ZBias - s7;
	float4 Temp2;
	for (int i = 0; i < 4; i++){
		if (-Part2[i] >= 0){
			Temp2[i] = 1;
		}
		else Temp2[i] = 0;
	}
	
	Color += dot(Temp2, float4(SampleWeight, SampleWeight, SampleWeight, SampleWeight));
	
	s0 = tex2D(ShadowMap, Input.ShadowPos + c4.xyzw);
	s1 = tex2D(ShadowMap, Input.ShadowPos + c4.wzyx);
	s2 = tex2D(ShadowMap, Input.ShadowPos + c5.xyzw);
	s3 = tex2D(ShadowMap, Input.ShadowPos + c5.wzyx);
	s4 = tex2D(ShadowMap, Input.ShadowPos + c6.xyzw);
	s5 = tex2D(ShadowMap, Input.ShadowPos + c6.wzyx);
	s6 = tex2D(ShadowMap, Input.ShadowPos + c7.xyzw);
	s7 = tex2D(ShadowMap, Input.ShadowPos + c7.wzyx);
	
	float4 Part3;
	Part3.x = ZBias - s0;
	Part3.y = ZBias - s1;
	Part3.z = ZBias - s2;
	Part3.w = ZBias - s3;
	float4 Temp3;
	for (int i = 0; i < 4; i++){
		if (-Part3[i] >= 0){
			Temp3[i] = 1;
		}
		else Temp3[i] = 0;
	}
	
	Color += dot(Temp3, float4(SampleWeight, SampleWeight, SampleWeight, SampleWeight));
	
	float4 Part4;
	Part4.x = ZBias - s4;
	Part4.y = ZBias - s5;
	Part4.z = ZBias - s6;
	Part4.w = ZBias - s7;
	float4 Temp4;
	for (int i = 0; i < 4; i++){
		if (-Part4[i] >= 0){
			Temp4[i] = 1;
		}
		else Temp4[i] = 0;
	}
	
	Color += dot(Temp4, float4(SampleWeight, SampleWeight, SampleWeight, SampleWeight));*/
	
	PS_OUTPUT Out;
	Out.Color.rgb = Color;
	Out.Color.a = 1;
	return Out;
}

#endif
