bool g_LightsEnabled;
bool g_TexturesEnabled;
bool g_AoEnabled;
bool g_GiEnabled;

Texture2D g_MRT0;
Texture2D g_MRT1;
Texture2D g_MRT2;
Texture2D g_MRT3;


SamplerState samPoint
{
    Filter = MIN_MAG_MIP_POINT;
    
    AddressU = Wrap;
    AddressV = Wrap;
};

SamplerState samLinear
{
    Filter = MIN_MAG_MIP_LINEAR;
    
    AddressU = Wrap;
    AddressV = Wrap;
};

SamplerState samAniso
{
    Filter = ANISOTROPIC;
    MaxAnisotropy = 16;
    
    AddressU = Wrap;
    AddressV = Wrap;
};

BlendState AlphaBlending
{
    BlendEnable[0] = TRUE;
    SrcBlend = SRC_ALPHA;
    DestBlend = INV_SRC_ALPHA;
    BlendOp = ADD;
    RenderTargetWriteMask[0] = 0x0F;
};

BlendState DisableBlend 
{ 
	BlendEnable[0] = FALSE; 
};

DepthStencilState DepthEnabling 
{ 
	DepthEnable = TRUE; 
};

DepthStencilState DepthDisabling
{
	DepthEnable = FALSE;
};

RasterizerState DisableCulling
{
	CullMode = NONE;
};


struct VS_INPUT
{
    float4 Pos  : POSITION;
    float3 Norm : NORMAL;
    float3 Tang : TANGENT; 
    float2 Tex  : TEXCOORD;
};

struct PS_INPUT
{
    float4 Pos   : SV_Position;
    float2 Tex   : TEXCOORD2;
};

struct PS_OUTPUT
{
	float4 data0 : SV_Target0;
	float4 data1 : SV_Target1;
};

//--------------------------------------------------------------------------------------
// Vertex Shader
//--------------------------------------------------------------------------------------
PS_INPUT COMBINE_VS( VS_INPUT input )
{
    PS_INPUT output = (PS_INPUT)0;

	output.Pos = float4(2.0*input.Pos.x-1.0, 1.0-2.0*input.Pos.y, 0.0, 1.0);
    output.Tex = input.Tex;
    
    return output;
}

//--------------------------------------------------------------------------------------
// Pixel Shader
//--------------------------------------------------------------------------------------
PS_OUTPUT COMBINE_PS( PS_INPUT input)
{
	PS_OUTPUT output = (PS_OUTPUT)0;	
	float3 diffuse  = g_MRT0.Sample(samPoint, input.Tex).rgb;
	float3 specular = g_MRT1.Sample(samPoint, input.Tex).rgb;
	float4 giAo     = g_MRT2.Sample(samPoint, input.Tex);
	float4 albedo   = g_MRT3.Sample(samPoint, input.Tex);
	
	
	output.data0 = float4(1.0, 1.0, 1.0, 1.0);
	
	if (g_AoEnabled) {
		output.data0.rgb *= giAo.a;
	}
	
	if (g_LightsEnabled) {
		output.data0.rgb += (diffuse + specular);
	}
	
	if (g_GiEnabled) {
		output.data0.rgb += giAo.rgb;
	}
	
	
	if (g_TexturesEnabled) {
		output.data0 *= albedo;
	}
	
	
	//output.data0 = float4(giAo.rgb, 1.0);

	output.data1 = float4(log(0.01 + output.data0.r), log(0.01 + output.data0.g), log(0.01 + output.data0.b), 1.0);
	
	return output;
}


//--------------------------------------------------------------------------------------
technique10 Render
{
    pass P0
    {
		SetRasterizerState(DisableCulling);
		SetBlendState( AlphaBlending, float4( 0.0f, 0.0f, 0.0f, 0.0f ), 0xFFFFFFFF );
		SetDepthStencilState( DepthDisabling, 0 );
		
        SetVertexShader( CompileShader( vs_4_0, COMBINE_VS() ) );
        SetGeometryShader( NULL );
        SetPixelShader( CompileShader( ps_4_0, COMBINE_PS() ) );
    }
}