//
// Asura_D3D_VS_Tools_SpecularMaps.cpp
//
// Created by VGP - 16Feb2006
//
// Copyright (C) 2006 Rebellion (Strangelite), All Rights Reserved.
//
// Vertex shaders for tools specular maps
//

#include "Core/Asura.h"

#ifdef ASURA_USE_SPECULAR_MAPS
#ifdef ASURA_TOOLS

// This file's header.
#include "Rendering/Asura_Direct3D_Shaders.h"

static Direct3D_VertexElement auVSD[] =
{
	{	0,	0,	D3DDECLTYPE_FLOAT3,		D3DDECLMETHOD_DEFAULT,	D3DDECLUSAGE_POSITION,	0 },
	{	0, 12,	D3DDECLTYPE_FLOAT3,		D3DDECLMETHOD_DEFAULT,	D3DDECLUSAGE_NORMAL,	0 },
	{	0, 24,	D3DDECLTYPE_D3DCOLOR,	D3DDECLMETHOD_DEFAULT,	D3DDECLUSAGE_COLOR,		0 },
	{	0, 28,	D3DDECLTYPE_FLOAT2,		D3DDECLMETHOD_DEFAULT,	D3DDECLUSAGE_TEXCOORD,	0 },
	{	0, 36,	D3DDECLTYPE_FLOAT2,		D3DDECLMETHOD_DEFAULT,	D3DDECLUSAGE_TEXCOORD,	1 },
	D3DDECL_END()
};

// VGP 10Feb2006
const char* const szVS_TOOLS_SPECULAR_MAPS_CODE =
{
	// Vertex shader for texture based environment ambient specular highlights
	// Expected constants:
	//  c00-c03		: ViewProj matrix
	//  c4			: Camera position
	//	c5			: Light direction

	"vs.1.1 \n"
	"dcl_position	v0 \n"
	"dcl_normal		v1 \n"
	"dcl_color		v2 \n"
	"dcl_texcoord0	v3 \n"
	"dcl_texcoord1	v4 \n"

	// Transform position by ViewProj
	"m4x4 oPos, v0, c0						\n"

	// Output tex coords 1 & 2
	"mov oT0, v3							\n"
	"mov oT1, v4							\n"

	// Calculate view vector (in world space)
	"add oT2, c4, -v0						\n"		// View vector = camera pos - vertex pos

	// Output light direction (in world space)
	"mov oT4, c5							\n"

	// Output vertex normal (in world space)
	"mov oT3, v1							\n"

	// Output vertex color
	"mul oD0, v2, c5.a						\n"
};

// Register the shader with Asura
const Asura_Direct3D_VertexShader xVS_TOOLS_MODULE_SPECULAR_MAPS_SHADER(ASURA_D3D_VS_TOOLS_MODULE_SPECULAR_MAPS, szVS_TOOLS_SPECULAR_MAPS_CODE, auVSD);

#endif // ASURA_TOOLS
#endif // ASURA_USE_SPECULAR_MAPS
