// transformations
float4x4 World : register(c0);
float4x4 View : register(c4);
float4x4 Proj : register(c8);

//float4x4 LightMatrix;
///float4x4 ShadowProjMatrix;.

float4x4 ShadowMatrix;
float4x4 ShadowAdjustment;

float RangeScale;

struct VS_OUTPUT{
    float4 Pos			: POSITION;
    float4 ShadowPos	: TEXCOORD0;
    float Depth			: TEXCOORD1;
};

struct VS_INPUT{
    float3 Pos              : POSITION;
};


VS_OUTPUT main(const VS_INPUT Input){
	float4x4 ShadowWorldViewProj = mul(World, ShadowMatrix);
	float4x4 AdjustedShadowWorldViewProj = mul(World, ShadowAdjustment);

	float Depth = mul(float4(Input.Pos, 1), ShadowWorldViewProj).z * RangeScale;
	
	float4 ShadowPos = mul(float4(Input.Pos, 1), AdjustedShadowWorldViewProj);
	/*ShadowPos.x *= RangeScale * 1.5f;
	ShadowPos.x += 0.5f;
	
	ShadowPos.y *= RangeScale * -1.5f;
	ShadowPos.y += 0.5f;*/

	//ShadowPos.z = 0;
	
	/*float4x4 FinalShadowMatrix = World * ShadowMatrix;
	//float4x4 FinalShadowAdjustment = FinalShadowMatrix * ShadowAdjustment;
	
	//float3 Pos = mul(float4(Input.Pos, 1), (float4x3)World);
	
	//float4 ShadowProj = mul(float4(Input.Pos, 1), FinalShadowAdjustment);
	//float Depth = mul(float4(Input.Pos, 1), FinalShadowMatrix).z;
	
	// View transform position
	//Pos = mul(float4(Pos, 1), (float4x3)View);*/
	
	float4x4 WorldViewProj = mul(mul(World, View), Proj);

	float4 Pos = mul(float4(Input.Pos, 1), WorldViewProj);

	// Output
	VS_OUTPUT Out;
    Out.Pos = Pos;//mul(float4(Pos, 1), Proj);
    Out.ShadowPos = ShadowPos;
    Out.Depth = Depth;
    return Out;
}