/**
*
* \file Asura_D3D_VS_Skin_GraphicNovel.cpp
*
* Created by Kevin Lea - 15/07/2002 18:14:07
*
* Copyright (C) 2002 Rebellion, All Rights Reserved.
*
* \brief
*
**/

#include "Core/Asura.h"
#include "Rendering/Asura_Direct3D_Shaders.h"

static DWORD Asura_Direct3D_CharacterVertex_Decl[] =
{
    D3DVSD_STREAM( 0 ),
    D3DVSD_REG( 0,	D3DVSDT_FLOAT3 ),
    D3DVSD_REG( 1,	D3DVSDT_FLOAT3 ),
    D3DVSD_REG( 2,	D3DVSDT_FLOAT2 ),
    D3DVSD_REG( 3,	D3DVSDT_FLOAT4 ),
	D3DVSD_REG( 4,	D3DVSDT_FLOAT4 ),

   D3DVSD_END()
};

#if 0

static char* VertexShader="vs.1.1 \n\
					;add r0, v0, v3 \n\
					mov r0, v0 \n\
									\n\
					mov a0.x, v3.x \n\
					dp4 r1.x, c[a0.x+5], r0 \n\
					dp4 r1.y, c[a0.x+6], r0 \n\
					dp4 r1.z, c[a0.x+7], r0 \n\
					mul r1.xyz, r1, v4.x \n\
\n\
					dp3 r3.x, c[a0.x+5], v1 \n\
					dp3 r3.y, c[a0.x+6], v1 \n\
					dp3 r3.z, c[a0.x+7], v1 \n\
					;mov r3, v1\n\
												\n\
					mov a0.x, v3.y \n\
					dp4 r2.x, c[a0.x+5], r0 \n\
					dp4 r2.y, c[a0.x+6], r0 \n\
					dp4 r2.z, c[a0.x+7], r0 \n\
					mad r1.xyz, r2, v4.y, r1 \n\
												\n\
					mov a0.x, v3.z \n\
					dp4 r2.x, c[a0.x+5], r0 \n\
					dp4 r2.y, c[a0.x+6], r0 \n\
					dp4 r2.z, c[a0.x+7], r0 \n\
					mad r1.xyz, r2, v4.z, r1 \n\
												\n\
					mov a0.x, v3.w \n\
					dp4 r2.x, c[a0.x+5], r0 \n\
					dp4 r2.y, c[a0.x+6], r0 \n\
					dp4 r2.z, c[a0.x+7], r0 \n\
					mad r1.xyz, r2, v4.w, r1 \n\
\n\
					mov r1.w, r0.w \n\
\n\
\n\
					sub r4, c[5], r1\n\
					dp3 r5, r4, r4 \n\
					rsq r5.x, r5.x \n\
					mul r6, r4, r5.x \n\
\n\
					dp3 r2, r3, r6	\n\
										\n\
					mul oD0.xyz, c[4], r2         ; The constant color.\n\
					mov oD0.w, c[4].w \n\
					mov oT0.xy, v2 \n\
					\n\
					sub r4, c[6], r1\n\
					dp3 r5, r4, r4 \n\
					rsq r5.x, r5.x \n\
					mul r4, r4, r5.x \n\
\n\
					dp3 oT1.x, r3, r4 \n\
					;mov oT1.x, c[6].w \n\
					add r4, r4, r6 \n\
					mul r4, r4, c[6].w \n\
					dp3 r2.x, r3, r6 \n\
					mul r5, r2, r2.x \n\
					mul r5, r5, r5.x \n\
					mul r2, r5, r2.x \n\
					mov oT1.y, r2.x \n\
			;		mov oT1.y, -c[6].w \n\
\n\
					dp4 oPos.x, r1, c[0] \n\
					dp4 oPos.y, r1, c[1] \n\
					dp4 oPos.z, r1, c[2] \n\
					dp4 oPos.w, r1, c[3] \n\
					";
#else


static char* VertexShader="vs.1.1 \n\
					;add r0, v0, v3 \n\
					mov r0, v0 \n\
									\n\
					mov a0.x, v3.x \n\
					dp4 r1.x, c[a0.x+9], r0 \n\
					dp4 r1.y, c[a0.x+10], r0 \n\
					dp4 r1.z, c[a0.x+11], r0 \n\
					mul r1.xyz, r1, v4.x \n\
\n\
					dp3 r3.x, c[a0.x+9], v1 \n\
					dp3 r3.y, c[a0.x+10], v1 \n\
					dp3 r3.z, c[a0.x+11], v1 \n\
					;mov r3, v1\n\
												\n\
					mov a0.x, v3.y \n\
					dp4 r2.x, c[a0.x+9], r0 \n\
					dp4 r2.y, c[a0.x+10], r0 \n\
					dp4 r2.z, c[a0.x+11], r0 \n\
					mad r1.xyz, r2, v4.y, r1 \n\
												\n\
					mov a0.x, v3.z \n\
					dp4 r2.x, c[a0.x+9], r0 \n\
					dp4 r2.y, c[a0.x+10], r0 \n\
					dp4 r2.z, c[a0.x+11], r0 \n\
					mad r1.xyz, r2, v4.z, r1 \n\
												\n\
					mov a0.x, v3.w \n\
					dp4 r2.x, c[a0.x+9], r0 \n\
					dp4 r2.y, c[a0.x+10], r0 \n\
					dp4 r2.z, c[a0.x+11], r0 \n\
					mad r1.xyz, r2, v4.w, r1 \n\
\n\
					mov r1.w, r0.w \n\
\n\
					dp3 r4, r3, c[4] ; normal * light1 direction \n\
					max r4, r4, c[10] \n\
					mul r5, c[5], r4.x ; multiply by light1's colour \n\
					dp3 r4, r3, c[6]		\n\
					max r4, r4, c[10] \n\
					mad r5, c[7], r4.x, r5	\n\
					dp3 r4, r3, c[8]		\n\
					max r4, r4, c[10] \n\
					mad oD0.xyz, c[9], r4.x, r5	\n\
					mov oD0.w, c[10].w \n\
					mov oT0.xy, v2 \n\
													\n\
 					dp4 oPos.x, r1, c[0] \n\
					dp4 oPos.y, r1, c[1] \n\
					dp4 oPos.z, r1, c[2] \n\
					dp4 oPos.w, r1, c[3] \n\
			\n\
					sub r4, c[11], r1	\n\
					dp3 r5, r4, r4		\n\
					rsq r5.x, r5.x		\n\
					mul r4, r4, r5.x ; r4 is now normalised 'to eye' vector \n\
\n\
					dp3 oT1.x, r3, r4 \n\
			;		mov oT1.x, c[11].w \n\
					add r4, r4, c[4] \n\
					mul r4, r4, c[11].w \n\
					dp3 r2, r3, r4 \n\
					mul r5, r2, r2.x \n\
					mul r5, r5, r5.x \n\
					mul r2, r5, r2.x \n\
					mov oT1.y, r2.x \n\
			;		mov oT1.y, c[11].w \n\
\n\
					";
#endif


static Asura_Direct3D_VertexShader Shader(ASURA_D3D_VS_4BONESGRAPHICNOVEL,VertexShader,Asura_Direct3D_CharacterVertex_Decl);

#if 0
static char* VertexShader="vs.1.1 \n\
					;add r0, v0, v3 \n\
					mov r0, v0 \n\
									\n\
					mov a0.x, v3.x \n\
					dp4 r1.x, c[a0.x+5], r0 \n\
					dp4 r1.y, c[a0.x+6], r0 \n\
					dp4 r1.z, c[a0.x+7], r0 \n\
				;	mul r1.xyz, r1, v4.x \n\
\n\
					dp3 r3.x, c[a0.x+5], v1 \n\
					dp3 r3.y, c[a0.x+6], v1 \n\
					dp3 r3.z, c[a0.x+7], v1 \n\
					;mov r3, v1\n\
												\n\
			\n\
					mov r1.w, r0.w \n\
\n\
\n\
					sub r4, c[5], r1\n\
					dp3 r5, r4, r4 \n\
					rsq r5.x, r5.x \n\
					mul r6, r4, r5.x \n\
\n\
					dp3 r2, r3, r6	\n\
										\n\
					mul oD0.xyz, c[4], r2         ; The constant color.\n\
					mov oD0.w, c[4].w \n\
					mov oT0.xy, v2 \n\
					\n\
					sub r4, c[6], r1\n\
					dp3 r5, r4, r4 \n\
					rsq r5.x, r5.x \n\
					mul r4, r4, r5.x \n\
\n\
					dp3 oT1.x, r3, r4 \n\
					;mov oT1.x, c[6].w \n\
					add r4, r4, r6 \n\
					mul r4, r4, c[6].w \n\
					dp3 r2.x, r3, r6 \n\
					mul r5, r2, r2.x \n\
					mul r5, r5, r5.x \n\
					mul r2, r5, r2.x \n\
					mov oT1.y, r2.x \n\
			;		mov oT1.y, -c[6].w \n\
\n\
					dp4 oPos.x, r1, c[0] \n\
					dp4 oPos.y, r1, c[1] \n\
					dp4 oPos.z, r1, c[2] \n\
					dp4 oPos.w, r1, c[3] \n\
					";
#endif


