
float g_ConfT = 0.5f;

texture g_texDepth;
sampler2D g_sDepth = sampler_state
{
    Texture = <g_texDepth>;
    AddressU = Clamp;
    AddressV = Clamp;
    MipFilter = NONE;
    MagFilter = POINT;
    MinFilter = POINT;
};

texture g_texShadowMap;
sampler2D g_sShadowMap = sampler_state
{
    Texture = <g_texShadowMap>;
    AddressU = Clamp;
    AddressV = Clamp;
    MipFilter = NONE;	
    MagFilter = POINT;
    MinFilter = POINT;
};

void VSUnconv(float2 iTexC : TEXCOORD0, out float4 oPos : POSITION, out float2 oTexC : TEXCOORD0)
{
	oPos = float4(0, 0, 0, 1);
	oTexC = iTexC;
}

struct SHADOW_OUT
{
	float4 Shadow : COLOR0;
	float Z : DEPTH;
	//float4 SPass : COLOR1;
};

SHADOW_OUT PSUnconv(float2 iTexC : TEXCOORD0)
{
	SHADOW_OUT o;
	float depth = tex2D(g_sDepth, iTexC).r;
	float conf = tex2D(g_sShadowMap, iTexC).b; //confidence in blue channel
	if(conf >= g_ConfT) //kill if converged
		clip(-1);
	o.Z = depth;
	o.Shadow = depth;
	return o;
}

//draws depth of unconverged pixels
technique RenderUnconverged
{
	pass P0
    {      
		CullMode = NONE;
		ZEnable = true;
		ZWriteEnable = true;
		//zfunc set by app
		AlphaBlendEnable = false;
		AlphaTestEnable = false;
		//ColorWriteEnable = 0; //set by app

        VertexShader = compile vs_2_0 VSUnconv();
        PixelShader  = compile ps_2_0 PSUnconv();
    }
}
