#include "_shared.fx"

// parameters ------------------------------------------
float4x4 g_mWorld         : WORLD;
float4x4 g_mView          : VIEW;
float4x4 g_mProjection    : PROJECTION;

float4x4 g_mViewInverse   : VIEWINVERSE;


texture2D 	g_tDiffuseMap;
int g_iTransparency;
int g_iTranslucency;


	
// input structs ---------------------------------------
sampler2D g_sDiffuseSampler = 
sampler_state
{
	Texture = <g_tDiffuseMap>;
	MinFilter = anisotropic;
	MagFilter = linear;
	MipFilter = linear;
	AddressU = wrap;
	AddressV = wrap;
};


struct VS_INPUT
{
	float3	vPositionOS	: POSITION0;
	float2	vTexcoord0	: TEXCOORD0;
};

struct VS_OUTPUT
{
	float4	vPositionPS	: POSITION0;
	float2	vTexcoord0	: TEXCOORD0_centroid;
};

// shaders ---------------------------------------------
VS_OUTPUT
vsMain(VS_INPUT i)
{
	// preshader->
	float4x4 mWorldView = mul(g_mWorld, g_mView);
	float4x4 mWorldViewProjection = mul(mWorldView, g_mProjection);
	// <-preshader


	VS_OUTPUT o;
	
	o.vPositionPS = mul(float4(i.vPositionOS, 1), mWorldViewProjection);

	o.vTexcoord0 = i.vTexcoord0;

	return o;
}


float4
psMain(VS_OUTPUT i) : COLOR0
{		
	// surface color
	float3 vDiffuseColor = tex2D(g_sDiffuseSampler, i.vTexcoord0);
	
	float4 o;
	o.rgb = vDiffuseColor;
	o.a = tex2D(g_sDiffuseSampler, i.vTexcoord0).a;
	
	return o;
}


// techniques ------------------------------------------
technique ambientpass_staticmesh
{
	pass p0
	{
		VertexShader = compile vs_1_1 vsMain();
		PixelShader = compile ps_2_0 psMain();

		AlphaBlendEnable = (g_iTranslucency);
		SrcBlend = SrcAlpha;
		DestBlend = InvSrcAlpha;
		
		AlphaTestEnable = (g_iTransparency);
		AlphaRef = 128;
		AlphaFunc = Greater;
		
		ZEnable = true;
		ZFunc = less;
		ZWriteEnable = true;
	}
}

technique lightpass_staticmesh
{
}

// -----------------------------------------------------
technique shadowmap_staticmesh {}
technique shadowmap_skinnedmesh {}

// -----------------------------------------------------
