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

float FogNear;
float InvFogRange;

#include "dcLighting.HLSL"

float Timer;
float3 CamPos;

struct VS_OUTPUT{
    float4 Pos				: POSITION;
    
    float4 Diff				: COLOR0;
	
	float2 BaseTex			: TEXCOORD0;
	float3 ViewDir			: TEXCOORD1;
	
	float2 BumpTex0			: TEXCOORD2;
	float2 BumpTex1			: TEXCOORD3;
	
	float FogIntensity		: TEXCOORD4;
};

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

VS_OUTPUT main(const VS_INPUT Input){
	// Setup
	float3 Pos = mul(float4(Input.Pos, 1), (float4x3)World);
	float3 Normal = mul(Input.Normal, (float3x3)World);
	
	//Pos.y += (sin(Timer + Pos.x * 1.3f) + sin(Timer + Pos.z * 1.7f)) * 10;
	
	float3 WorldPos = Pos;

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

	float4 Diffuse = ComputeDiffuse(Pos, Normal);

	// Output
    VS_OUTPUT Out;
    Out.Pos = mul(float4(Pos, 1), Proj);
    Out.Diff = 1;//Diffuse;

	Out.BaseTex = Input.BaseTex;
	Out.ViewDir = CamPos - WorldPos;
	
	Out.BumpTex0 = Input.BaseTex + float2(Timer / 15.1f, 0);
	Out.BumpTex1 = Input.BaseTex + float2(0, Timer / 17.4f);
	
	
	Out.FogIntensity = clamp((Out.Pos.z - FogNear) * InvFogRange, 0, 1);


    return Out;
}