
float4 PositionRect;
float4 TexCoordRect;

Texture2D Tex;
Texture2D ColorMap;
SamplerState StdSampler;

struct VSInput
{
	float2 Position: POSITION;
};

struct VSOutput
{
	float4 Position: SV_Position;
	float2 TexCoord: TEXCOORD;
};

VSOutput vsMain(VSInput Input)
{
	VSOutput Output;
	Output.Position = float4(Input.Position * PositionRect.zw + PositionRect.xy, 0, 1);
	Output.TexCoord = Input.Position * TexCoordRect.zw * float2(1,-1) + TexCoordRect.xy;
	return Output;
}

float4 psMain(VSOutput Input): SV_Target
{
	float4 color = ColorMap.Sample(StdSampler, Input.TexCoord);
	float s = Tex.Sample(StdSampler, Input.TexCoord).x;

	s = max(0, 1.0-s);

	return float4(color.xyz*s, color.w>0?1:0);
}