/*******************************************************************
*	NormalDepth.fx
*	Author - Pongthep Charnchaichujit
*	Created on - ?
*
*   All content © 2007 - 2008 DigiPen (USA) Corporation, all rights reserved.
*******************************************************************/
//CONSTANTS
float4x4 World;
float4x4 View;
float4x4 WorldViewProjection;
float objID;

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

struct PS_IN {
	float4 pos : POSITION;
	float4 color : TEXCOORD0;
};

// Normals Vertex Shader
PS_IN NormalDepthVertexShader(VS_IN input)
{
	PS_IN output;
	
	output.pos = mul(input.pos, WorldViewProjection);
	float3 normal = mul( mul(input.normal, (float3x3)World), View);
    //z = 1 - sqrt(x*x + y*y)
	//output.color.xy = normalize(normal.xyz).xy*.5f + .5f;// (normal.xy + 1) / 2 );
    //output.color.z = 0; //reserved for id
    //output.color.xyz = normal;
    normal = normalize(normal);

    output.color.xy = normal*.5 + .5;

    output.color.z = objID/255;
    
	output.color.w = mul(input.pos, mul(World, View)).z;//output.pos.z / output.pos.w;
    output.color.w = saturate((output.color.w-1)/(700-1));
	// OLD WAY output.color.w = output.pos.z / output.pos.w;
	return output;
}

// Normal Depth Pixel Shader
float4 NormalDepthPixelShader(PS_IN input): COLOR
{
	return input.color;
}

technique Technique0
{
	pass P0
	{
		AlphaBlendEnable = False;
		VertexShader = compile vs_2_a NormalDepthVertexShader();
		PixelShader = compile ps_2_a NormalDepthPixelShader();
	}
}
