/*******************************************************************
*	ColorPhong.fx
*	Author - Pongthep Charnchaichujit
*	Created on - ?
*
*   All content © 2007 - 2008 DigiPen (USA) Corporation, all rights reserved.
*******************************************************************/
#include "Scene.h"

//CONSTANTS
float4x4 World;
float4x4 WorldViewProjection;
float3 Eye;

float4 DiffuseColor;
float4 SpecularColor = {1, 1, 1, 1};

float shiny = 50.0f; // shininess for specular

//STRUCTS
struct VS_IN {
	float4 pos : POSITION;
	float3 normal : NORMAL;
};

struct PS_IN {
	float4 pos : POSITION;
	float3 normal : TEXCOORD0;
	float4 wpos : TEXCOORD1;
};

//Diffuse with color vertex shader
PS_IN ColorVertexShader(VS_IN input)
{
	PS_IN output;

	output.pos = mul(input.pos, WorldViewProjection);
	output.normal = mul(input.normal, (float3x3)World);
	output.wpos = mul(input.pos, World);

	return output;
}

//Diffuse with texture pixel shader
/*float4 DiffuseColorPixelShader(PS_IN input): COLOR
{
	//float3 normal = normalize(input.normal);
	
	return DiffuseColor;
}*/

//Phong pixel shader
float4 PhongPixelShader(PS_IN input): COLOR
{
	float3 normal = normalize(input.normal);
	float3 V = normalize(Eye - (float3)input.wpos); // view vector
	
	float4 light;
	for (int i=0; i<numLights; ++i)
	{
		float3 L = normalize(Lights[i] - (float3)input.wpos);
		float3 H = normalize(L + V); // half vector
		light = lit(dot(normal,L), dot(normal,H), shiny);
	}
	light /= numLights;
	float4 col = DiffuseColor + DiffuseColor*light.y + SpecularColor*light.z;

	return col;
}

//Phong Technique
technique ColorPhong
{
	pass Phong
	{
		VertexShader = compile vs_2_a ColorVertexShader();
		PixelShader = compile ps_2_a PhongPixelShader();
	}
}
