// DYNAMIC: "COMPRESSED_VERTS"		"0..1"
// DYNAMIC: "DOWATERFOG"			"0..1"
// DYNAMIC: "SKINNING"				"0..1"

#include "common_vs_fxc.h"

static const int g_FogType			= DOWATERFOG;
static const bool g_bSkinning		= SKINNING ? true : false;

const float4 cBaseTextureTransform[2]	: register( SHADER_SPECIFIC_CONST_0 );
const float4 cMaskTextureTransform[2]	: register( SHADER_SPECIFIC_CONST_2 );
const float4 cDetailTextureTransform[2] : register( SHADER_SPECIFIC_CONST_4 );

// Static control flow
const bool g_bVertexColor				: register( SHADER_SPECIFIC_BOOL_CONST_0 );

struct VS_INPUT
{
	float4 vPos			: POSITION;
	float4 vBoneWeights	: BLENDWEIGHT;
	float4 vBoneIndices	: BLENDINDICES;
	float4 vNormal		: NORMAL;

	float4 vColor		: COLOR0;

	float4 vTexCoord0	: TEXCOORD0;
};

struct VS_OUTPUT
{
	float4 vProjPos		: POSITION;
	float2 vTexCoord0	: TEXCOORD0;
	float2 vTexCoord1	: TEXCOORD1;
	float2 vTexCoord2	: TEXCOORD2;
	float2 vTexCoord3	: TEXCOORD3;

	float4 vColor		: COLOR0;
	float4 fogFactorW	: COLOR1;

#if !defined( _X360 )    
	float  fog		: FOG;
#endif

	float4 worldPos_projPosZ : TEXCOORD7;		// Necessary for pixel fog
};


VS_OUTPUT main( const VS_INPUT v )
{
	VS_OUTPUT o = ( VS_OUTPUT )0;

	float3 worldPos;
	float3 worldNormal;

	//------------------------------------------------------------------------------
	// Vertex blending
	//------------------------------------------------------------------------------
	SkinPosition( g_bSkinning, v.vPos, v.vBoneWeights, v.vBoneIndices, worldPos );

	o.vProjPos = mul( float4( worldPos, 1 ), cViewProj );
	o.worldPos_projPosZ = float4( worldPos.xyz, o.vProjPos.z );

	//------------------------------------------------------------------------------
	// Fog
	//------------------------------------------------------------------------------
	o.fogFactorW = CalcFog( worldPos, o.vProjPos, g_FogType );
#if !defined( _X360 )
	o.fog = o.fogFactorW;
#endif

	//------------------------------------------------------------------------------
	// Texture coord transforms
	//------------------------------------------------------------------------------
	o.vTexCoord0 = mul( v.vTexCoord0, (float2x4)cBaseTextureTransform );
	o.vTexCoord3 = mul( v.vTexCoord0, (float2x4)cDetailTextureTransform );

	o.vColor = cModulationColor;

	if( g_bVertexColor )
	{
		o.vColor *= v.vColor;
	}

	return o;
}



