//-----------------------------------------------------------------------------
// DiffCubeLight.sha
// 
// Used with rendering the diffuse component into the diffuse cube map.
//-----------------------------------------------------------------------------

matrix mWVP;
matrix mW;
vector vLightDirection;
DWORD cColor = 0xffffffff;

texture tNormalizer; // Normalizer Cube Map

vertexshader vDiffuseCubeMapLight = 
    decl
    {
        stream 0;
        float    v0[3];  // Position
        D3DCOLOR v3;     // Normal
        float    v7[2];  // Tex coord 0
		D3DCOLOR v8;     // Binormal
        D3DCOLOR v9;     // Tangent
    }
    asm
    {
        ; Constants:
        ; 12..15 - World Matrix
        ; 16..19 - Composite World-View-Projection Matrix
        ; 20     - World Space Light Direction

        vs.1.0
        m4x4 oPos, v0, c16

        ; Position direction
        m4x4 oT2.xyz, v0, c12
        
        ; Light direction
		mov  oT1.xyz, c20

	};

pixelshader ps10_DiffuseCubeMapLight = asm
{
    ps.1.1
    tex      t1
    tex      t2
    dp3_sat  r0.rgb, t2_bx2, t1_bx2
    mul      r0.rgb, r0, c0
    +mov     r0.a, c0.a
};

technique DiffuseCubeMap
{
    pass P0
    {
        vertexshader = <vDiffuseCubeMapLight>;	
        VertexShaderConstant[12] = <mW>;
        VertexShaderConstant[16] = <mWVP>;
        VertexShaderConstant[20] = <vLightDirection>;

        CullMode = None;

        // Cubic Normalizer Map
	    Texture[2]   = <tNormalizer>;
	    AddressU[2]  = Clamp;
	    AddressV[2]  = Clamp;
	    MinFilter[2] = Linear;
	    MagFilter[2] = Linear;
	    MipFilter[2] = Point;

        // Cubic Normalizer Map
	    Texture[1]   = <tNormalizer>;
	    AddressU[1]  = Clamp;
	    AddressV[1]  = Clamp;
	    MinFilter[1] = Linear;
	    MagFilter[1] = Linear;
	    MipFilter[1] = Point;

        PixelShaderConstant[0] = <cColor>;
        PixelShader = <ps10_DiffuseCubeMapLight>;

        // Dest
        ZEnable = False;
        AlphaBlendEnable = True;
        SrcBlend = One;
        DestBlend = One;
    }
}
