#include "RTCommonData.fxh"


//--------------------------------------------------------------------------------------
// SHADERS BODIES
//--------------------------------------------------------------------------------------
void RenderSceneVS( float4 Pos				: POSITION,
                    float3 Normal			: NORMAL,
                    float2 Tex				: TEXCOORD0,
                    out float4 oPos			: POSITION,
                    out float4 oDiffuse		: COLOR,
                    out float2 oTex			: TEXCOORD0,
                    out float3 oNormal		: TEXCOORD1,
                    out float3 oViewPos		: TEXCOORD2)
{
    // Output screen space position
    oViewPos = mul(Pos, g_mWorldView);
    oPos = mul(float4(oViewPos, 1.0f), g_mProj);

    // Transform normal to view space
    oNormal = mul(Normal, (float3x3)g_mWorldView);

    // Compute diffuse
    oDiffuse = dot(g_vLightVect, mul(Normal, g_mWorld));

    // Propagate tex coord
    oTex = Tex;        
}


void RenderScenePS( float4 Diffuse			: COLOR,
                    float2 Tex				: TEXCOORD0,
                    float3 Normal			: TEXCOORD1,
                    float3 Pos				: TEXCOORD2,
                    float3 Velocity			: TEXCOORD3,
                    out float4 oCol			: COLOR0,
                    out float4 oNormal		: COLOR1,
                    out float4 oPos			: COLOR2)
{
    // Output pixel color
    oCol = tex2D(g_samMesh, Tex) * Diffuse;
    
    // Output normal
    oNormal = float4(normalize(Normal), 1.0f);
    
    // Output view position
    oPos = float4(Pos, 1.0f);
}


//-----------------------------------------------------------------------------
// Technique: RenderScene
// Desc: Renders the scene with a vertex and pixel shader.
//-----------------------------------------------------------------------------
technique MeshLighting
{
    pass p0
    {
		ZEnable = true;
		ZWriteEnable = true;
		AlphaBlendEnable = false;	// TODO : add states block to restore the pieline states after DXUT renders the GUI
		AlphaTestEnable = false;
		
        VertexShader = compile vs_1_1 RenderSceneVS();
        PixelShader = compile ps_2_0 RenderScenePS();
    }
}