//////////////////////////////////////////////////////////////////////////////////////////////////
//										SHADOWS													//
//////////////////////////////////////////////////////////////////////////////////////////////////

float4 vs_shadow(VS_INPUT IN) : POSITION0
{
	//return mul(IN.position, matShadow);
    //float4 posWorld = mul(IN.position, matW);
	float4x4 mattemp = mul(matW, matVP);
//	return mul(IN.position, matW);
	return mul(IN.position, mattemp);
//	return mul(posWorld, matVP);
}

float4 ps_shadow(float4 pos : POSITION0) : COLOR0
{
	return float4(0.0f, 0.0f, 0.0f, 0.3f);
}

technique Shadows1_FFP
{
	pass P0
	{        
		VertexShader = compile vs_1_1 vs_shadow();
		PixelShader  = compile ps_1_1 ps_shadow();
		Lighting = false;		
		ZEnable = true; 
		ZWriteEnable = false;
		StencilEnable = true;
		ShadeMode = Flat;
		StencilFunc = Always;
		StencilZFail = Keep;
		StencilFail = Keep;
		StencilRef = 0x1;
		StencilMask = 0xffffffff;
		StencilWriteMask = 0xffffffff;
		AlphaBlendEnable = true;
		SrcBlend = Zero;
		DestBlend = One;
		
		CullMode = CCW;		
		StencilPass = Decr;
    }
	pass P1
	{
		VertexShader = compile vs_1_1 vs_shadow();
		PixelShader  = compile ps_1_1 ps_shadow();
		WorldTransform[0] = <matW>;
		ViewTransform = <matV>;
		ProjectionTransform = <matP>;	
		Lighting = false;		
		ZEnable = true; 
		ZWriteEnable = false;
		StencilEnable = true;
		ShadeMode = Flat;
		StencilFunc = Always;
		StencilZFail = Keep;
		StencilFail = Keep;
		StencilRef = 0x1;
		StencilMask = 0xffffffff;
		StencilWriteMask = 0xffffffff;
		AlphaBlendEnable = true;
		SrcBlend = Zero;
		DestBlend = One;
		
		CullMode = CW;		
		StencilPass = Incr;
	}
}

technique Shadows2_FFP
{
	pass P0
	{        
        VertexShader = compile vs_1_1 vs_shadow();
        PixelShader  = compile ps_1_1 ps_shadow();	
        WorldTransform[0] = <matW>;
		ViewTransform = <matV>;
		ProjectionTransform = <matP>;	
		ShadeMode = Gouraud;
		CullMode = CCW;
		ZEnable = false;
		StencilEnable = true;
		AlphaBlendEnable = true;
		Lighting = false;
		SrcBlend = SrcAlpha;
		DestBlend = InvSrcAlpha;
		StencilRef = 0x1;
		StencilFunc = LessEqual;
		StencilPass = Keep;				
	}
}

///////////////////////////////////////////////////////////////////////////////////////
