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

#include "dcLighting.HLSL"

float Timer;
float FallTimer;

float FogRange;

struct VS_OUTPUT{
    float4 Pos				: POSITION;
    float4 Diffuse			: COLOR0;
    float3 Depth			: COLOR1;
	float2 BaseTex			: TEXCOORD0;
};

struct VS_INPUT{
    float3 Pos				: POSITION;
    float3 Normal			: NORMAL;
    float2 BaseTex			: TEXCOORD0;
    float2 LeafData			: TEXCOORD1;	// clamped to 0...1
};

VS_OUTPUT main(const VS_INPUT Input){
	float FallSpeed = 20 + (Input.LeafData.x * 30);
	float Rand = Input.LeafData.y * 3.141592654f * 2;

	float3 Pos = Input.Pos;
	
	float4 Emissive = float4(0.25f, 0.25f, 0.25f, 1.0f);
	
	float Scale = 1.0f / 25.0f;
	float IntTimer = Timer * 0.05f;
	
	

	// Setup
	Pos = mul(float4(Pos, 1), (float4x3)World);
	float3 Normal = mul(Input.Normal, (float3x3)World);
	
	Pos.x += sin(Rand * 1.7f) * (FallTimer * 15);
	Pos.y -= FallSpeed * FallTimer;
	Pos.z += sin(Rand * 7.3f) * (FallTimer * 15);
	
	Pos.x += sin(IntTimer * (Input.Pos.x + Input.Pos.y + Input.Pos.z));
	Pos.y += sin(IntTimer * (Input.Pos.x - Input.Pos.y + Input.Pos.z));
	Pos.z += sin(IntTimer * (Input.Pos.x + Input.Pos.y - Input.Pos.z));

	float4 Diffuse = ComputeDiffuseEmissiveOverride(Emissive, Pos, Normal);
	Diffuse.a = 1.0f;
	
	Pos = mul(float4(Pos, 1), (float4x3)View);

	// Output
    VS_OUTPUT Out;
    Out.Pos = mul(float4(Pos, 1), Proj);
    Out.Diffuse = Diffuse;
	Out.BaseTex = Input.BaseTex;
	Out.Depth = Out.Pos.z * FogRange;

    return Out;
}