float4x4 WorldViewProjection;
float4 PaintColor;
texture PaintTex;

sampler PaintSampler = sampler_state 
{
	texture = <PaintTex>;
	AddressU  = WRAP;
	AddressV  = WRAP;
	AddressW  = WRAP;
	//MIPFILTER = LINEAR;
	MINFILTER = LINEAR;
	MAGFILTER = LINEAR;
};

struct VS_IN
{
	float4 pos : POSITION;
	float2 tex : TEXCOORD0;
};

struct PS_IN
{
	float4 pos : POSITION;
	float2 tex : TEXCOORD0;
};

PS_IN PaintVertexShader(VS_IN input)
{
	PS_IN output;
	output.pos = mul(input.pos, WorldViewProjection);
	output.tex = input.tex;
	
	return output;
}

float4 PaintPixelShader(PS_IN input) : COLOR
{
	float4 tex = tex2D(PaintSampler, input.tex);
	float4 color = (tex.a > 0) ? float4(PaintColor.xyz, tex.a) : tex;
	return color;
}

technique Paint
{
	pass P0
	{
		AlphaBlendEnable = true;
		SrcBlend = SRCALPHA;
		DestBlend = INVSRCALPHA;
		SEPARATEALPHABLENDENABLE = true;
		SRCBLENDALPHA = One;
		DestBlendAlpha = One;
		BlendOpAlpha = Add;
		ZEnable = false;
		ZWriteEnable = false;
		VertexShader = compile vs_2_a PaintVertexShader();
		PixelShader = compile ps_2_a PaintPixelShader();
	}
}
