#define FXAA_PC 1
#define FXAA_HLSL_3 1
//#define FXAA_GREEN_AS_LUMA 1
#define FXAA_QUALITY__PRESET 39

#include "injFX_Settings.h"
#include "injFX_Shaders\Fxaa3_11.h"
uniform extern texture gScreenTexture;
uniform extern texture gLumaTexture;

//Difinitions: BUFFER_WIDTH, BUFFER_HEIGHT, BUFFER_RCP_WIDTH, BUFFER_RCP_HEIGHT
//thanks Fake for this version of injFXAA, this file comes from AgainstAllAutority gtamania.ru
//AAA=opezdl

sampler screenSampler = sampler_state
{
    Texture = <gScreenTexture>;
    MinFilter = POINT;
    MagFilter = POINT;
    MipFilter = POINT;
    AddressU = BORDER;
    AddressV = BORDER;
    SRGBTexture = FALSE;
};
sampler lumaSampler = sampler_state
{
    Texture = <gLumaTexture>;
    MinFilter = LINEAR;
    MagFilter = LINEAR;
    MipFilter = NONE;
    AddressU = BORDER;
    AddressV = BORDER;
    SRGBTexture = FALSE;
};

//quad
struct VS_OUTPUT_POST
{
	float4 vpos  : POSITION;
	float2 txcoord0 : TEXCOORD0;
};
struct VS_INPUT_POST
{
	float3 pos  : POSITION;
	float2 txcoord0 : TEXCOORD0;
};



texture2D texBloom1;
texture2D texBloom2;
texture2D texBloom3;
texture2D texBloom4;
texture2D texBloom5;

sampler2D SamplerBloom1 = sampler_state
{
    Texture   = <texBloom1>;
	MinFilter = LINEAR;
	MagFilter = LINEAR;
	MipFilter = NONE;//NONE;
	AddressU  = Clamp;
	AddressV  = Clamp;
	SRGBTexture=FALSE;
	MaxMipLevel=0;
	MipMapLodBias=0;
};

sampler2D SamplerBloom2 = sampler_state
{
    Texture   = <texBloom2>;
	MinFilter = LINEAR;
	MagFilter = LINEAR;
	MipFilter = NONE;//NONE;
	AddressU  = Clamp;
	AddressV  = Clamp;
	SRGBTexture=FALSE;
	MaxMipLevel=0;
	MipMapLodBias=0;
};
/*
если кто умный смотрит
{
	назнаение этого файла
	то не гоните плз
	это просто фановый 
	эксперимент по отслеживанию
	распространения файлов
	как такового смысла не несет
	MaxMipLevel=0;
	MipMapLodBias=0;
}
*/

sampler2D SamplerBloom3 = sampler_state
{
    Texture   = <texBloom3>;
	MinFilter = LINEAR;
	MagFilter = LINEAR;
	MipFilter = NONE;//NONE;
	AddressU  = Clamp;
	AddressV  = Clamp;
	SRGBTexture=FALSE;
	MaxMipLevel=0;
	MipMapLodBias=0;
};

sampler2D SamplerBloom4 = sampler_state
{
    Texture   = <texBloom4>;
	MinFilter = LINEAR;
	MagFilter = LINEAR;
	MipFilter = NONE;//NONE;
	AddressU  = Clamp;
	AddressV  = Clamp;
	SRGBTexture=FALSE;
	MaxMipLevel=0;
	MipMapLodBias=0;
};

sampler2D SamplerBloom5 = sampler_state
{
    Texture   = <texBloom5>;
	MinFilter = LINEAR;
	MagFilter = LINEAR;
	MipFilter = NONE;//NONE;
	AddressU  = Clamp;
	AddressV  = Clamp;
	SRGBTexture=FALSE;
	MaxMipLevel=0;
	MipMapLodBias=0;
};


#include "injFX_Shaders\Post.h"

float4 LumaShader( float2 Tex : TEXCOORD0 ) : COLOR0
{
#ifdef USE_ADDITIONAL_SHADER
    float4 c0 = main(Tex);
#else
    float4 c0 = tex2D(screenSampler,Tex);
#endif
    //c0.w = dot(c0.xyz,float3(0.299, 0.587, 0.114)); //store luma in alpha
      c0.w = sqrt(dot(c0.xyz,float3(0.150, 0.296, 0.228))); //store luma in alpha
    return c0;
}

float4 MyShader( float2 Tex : TEXCOORD0 ) : COLOR0
{
    float4 c0 = FxaaPixelShader(
		Tex, //pos
		0, //fxaaConsolePosPos (?)
		lumaSampler, //tex
		lumaSampler, //fxaaConsole360TexExpBiasNegOne
		lumaSampler, //fxaaConsole360TexExpBiasNegTwo
		float2(BUFFER_RCP_WIDTH, BUFFER_RCP_HEIGHT), //fxaaQualityRcpFrame
		float4(-0.5*BUFFER_RCP_WIDTH,-0.5*BUFFER_RCP_HEIGHT,0.5*BUFFER_RCP_WIDTH,0.5*BUFFER_RCP_HEIGHT), //fxaaConsoleRcpFrameOpt
		float4(-2.0*BUFFER_RCP_WIDTH,-2.0*BUFFER_RCP_HEIGHT,2.0*BUFFER_RCP_WIDTH,2.0*BUFFER_RCP_HEIGHT), //fxaaConsoleRcpFrameOpt2
		float4(8.0*BUFFER_RCP_WIDTH,8.0*BUFFER_RCP_HEIGHT,-4.0*BUFFER_RCP_WIDTH,-4.0*BUFFER_RCP_HEIGHT), //fxaaConsole360RcpFrameOpt2
		0.75, //fxaaQualitySubpix (default: 0.75)
		0.080, //fxaaQualityEdgeThreshold
		0.0725, //fxaaQualityEdgeThresholdMin
		8.0, //fxaaConsoleEdgeSharpness
		0.125, //fxaaConsoleEdgeThreshold
		0.05, //fxaaConsoleEdgeThresholdMin
		0 //fxaaConsole360ConstDir
	);
    c0.w = 1;
    return c0;
}


technique PostProcess1
{
    pass p1
    {
        PixelShader = compile ps_3_0 LumaShader();
    }
}

technique PostProcess2
{
    pass p1
    {
        PixelShader = compile ps_3_0 MyShader();
    }
}