//--------------------------------------------------------------------------------------
// Constant Buffer Variables
//--------------------------------------------------------------------------------------
Texture2D colorIn : register( t0 );
Texture2D posIn : register( t1 );
Texture2D normIn : register( t2 );
Texture2D materialIn : register( t3 );
SamplerState samLinear : register( s0 );
SamplerState samPoint : register( s1 );

static const float GLOW_BORDER = 0.3f;

//--------------------------------------------------------------------------------------
struct VS_INPUT
{
    float2 Pos : POSITION;
    float2 Tex : TEXCOORD0;
};

struct PS_INPUT
{
    float4 Pos : SV_POSITION;
    float2 Tex : TEXCOORD0;
};

struct PS_OUT
{
    float4 glow : SV_Target0;
	float4 pos : SV_Target1;
	float4 norm : SV_Target2;
};

//--------------------------------------------------------------------------------------
// Vertex Shader
//--------------------------------------------------------------------------------------
PS_INPUT VS( VS_INPUT input )
{
    PS_INPUT output = (PS_INPUT)0;
    output.Pos.xy = input.Pos;
	output.Pos.z = 0.0f;
	output.Pos.w = 1.0f;
    output.Tex = input.Tex;
    
    return output;
}


//--------------------------------------------------------------------------------------
// Pixel Shader
//--------------------------------------------------------------------------------------
PS_OUT PS( PS_INPUT input) : SV_TARGET
{
	PS_OUT ret = (PS_OUT)0;
	float4 color = colorIn.Sample( samLinear, input.Tex );
	float colorsum = color.x + color.y + color.z;
	float border = colorsum * GLOW_BORDER;
	if(color.x < border) color.x = 0.0f;
	if(color.y < border) color.y = 0.0f;
	if(color.z < border) color.z = 0.0f;

	float4 material = materialIn.Sample( samLinear, input.Tex );
	ret.glow.xyz = color.xyz * material.x; //x is glowfactor
	ret.pos = posIn.Sample( samLinear, input.Tex ); ret.pos.w = 1.0f;
	ret.norm = normIn.Sample( samLinear, input.Tex ); ret.norm.w = 0.0f;
	return ret;
}
