/*******************************************************************
*	Skybox.fx
*	Author - Tejeev Kohli
*	Created on - 07/07/2008
*
*   All content © 2007 - 2008 DigiPen (USA) Corporation, all rights reserved.
*******************************************************************/
float4x4 WorldViewProjection;
float4x4 World;
float4 Eye;

float4 DiffuseColor;

texture DiffuseTex;

sampler DiffuseSampler = sampler_state 
{
	texture = <DiffuseTex>;
	AddressU  = WRAP;
	AddressV  = WRAP;
	AddressW  = WRAP;
	//MIPFILTER = LINEAR;
	MINFILTER = LINEAR;
	MAGFILTER = LINEAR;
};

//STRUCTS
struct VS_IN {
	float4 pos : POSITION;
	float2 Texcoord : TEXCOORD0;
};

struct PS_IN {
	float4 pos : POSITION;
	float2 Texcoord : TEXCOORD0;
};

//Skybox Vertex Shader
PS_IN SkyboxVertexShader(VS_IN input)
{
	PS_IN output;

	output.pos = mul(input.pos, WorldViewProjection);
	output.Texcoord = input.Texcoord;

	return output;
}

//Skybox Pixel Shader
float4 SkyboxPixelShader(PS_IN input): COLOR
{	
	//float4 color = (tex2D(DiffuseSampler, input.Texcoord) * 0.5f) + (0.5f * DiffuseColor);

	float4 color = tex2D(DiffuseSampler, input.Texcoord);

	return color;
}

technique Skybox
{
	pass P0
	{
		//CullMode = NONE;
		VertexShader = compile vs_2_a SkyboxVertexShader();
		PixelShader = compile ps_2_a SkyboxPixelShader();
	}
}


//cubemap skybox
texture CubeTexture;
samplerCUBE CubeSampler = sampler_state
{
   texture = <CubeTexture> ;
   magfilter = LINEAR;
   minfilter = LINEAR;
   mipfilter = LINEAR;
   AddressU = Mirror;
   AddressV = Mirror;
};

struct VS_INPUT
{
	float4 Position : POSITION;
	float3 Normal : NORMAL;    
};

struct PS_INPUT
{
	float4 Position    : POSITION;
	float3 ViewDirection : TEXCOORD0;    
};

PS_INPUT CubeVertexShader(VS_INPUT Input)
{
	float3 ObjectPosition = mul(Input.Position, World);

	PS_INPUT Output;
	Output.Position    = mul(Input.Position, WorldViewProjection);    
	Output.ViewDirection = Eye - ObjectPosition;    

	return Output;
}

float4 CubePixelShader(PS_INPUT Input) : COLOR0
{
	float3 viewDir = normalize(Input.ViewDirection);
	return texCUBE(CubeSampler, -viewDir);
}

technique CubeSkybox
{
	pass P0
	{
		VertexShader = compile vs_2_a CubeVertexShader();
		PixelShader  = compile ps_2_a CubePixelShader();
	}
}

