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

#include "dcLighting.HLSL"
#include "dcReflection.HLSL"
#include "dcShadowMap_V.HLSL"

struct VS_OUTPUT{
    float4 Pos				: POSITION;
    float4 Diffuse			: COLOR0;
	float4 Specular			: COLOR1;
	float2 BaseTex			: TEXCOORD0;
	float3 ReflectionTex	: TEXCOORD1;
	float1 Depth			: TEXCOORD2;
	float4 ShadowPos		: TEXCOORD3;
};

struct VS_INPUT{
    float3 Pos				: POSITION;
    float3 Normal			: NORMAL;
    float2 BaseTex			: TEXCOORD0;
};

VS_OUTPUT main(const VS_INPUT Input){
	float Depth;
	float4 ShadowPos;
	ComputeShadow(Input.Pos, Depth, ShadowPos);

	// Setup
	float3 Pos = mul(float4(Input.Pos, 1), (float4x3)World);
	float3 Normal = mul(Input.Normal, (float3x3)World);
	
	float3 WorldPos = Pos;

	// View transform position
	Pos = mul(float4(Pos, 1), (float4x3)View);

	float4 Diffuse = ComputeDiffuse(Pos, Normal);
	float3 Specular = ComputeSpecular(Pos, Normal) * 4;
	float3 ReflectionMap = ComputeReflection(WorldPos, Normal);
	
	// Output
    VS_OUTPUT Out;
    Out.Pos = mul(float4(Pos, 1), Proj);
    Out.Diffuse = Diffuse;
	Out.Specular = float4(Specular, 1);
	
	Out.Depth = Depth;
	Out.ShadowPos = ShadowPos;

	Out.BaseTex = Input.BaseTex;
	Out.ReflectionTex = ReflectionMap;

    return Out;
}
