You are on page 1of 48

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//

// M A S T E R E F F E C T 1.0 //
// effect.txt shader file for GTA San Andreas //
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
// made by : Marty McFly //
// Original Codes & Shaders by: //
// Matso, Ceejay.dk, SSontech, icelaglace, AAA //
// Reinhard, HeliosDoubleSix, PetkaGtA, DKT70 //
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
//////////////////////////////////-------------------------------------------------
----------------]

/*-----------------------------------------------------------.
/ Choose effects /
'-----------------------------------------------------------*/

//#define TVLEVELS // Adjusts the brightness/darkness of the scene


with a straight line instead of a curve.
//#define BORDER // 1 pixel broad border around the screen to fix
white outlining by SMAA/FXAA injectors
#define BORDER_DOF // use this option instead of border if using
the dof in this effect.txt
#define COLORWASHOUT // Color washout from GTA IV
//#define MATSO_FLARE // Matso's anamorphic flare with some
adjustments
//#define NOISE // Adds Film Grain
#define USE_DITHER // Applies dithering to simulate more colors
than your monitor can display. This lessens banding artifacts (mostly caused by
Vignette)
//#define VIBRANCEPASS // Intelligently saturates (or desaturates if
you use negative values) the pixels depending on their original saturation.
//#define CHROMATICABBERATION // Lens chromatic abberation and distortion
//#define HDR // No actual HDR - fog colors, exposure, gamma
and blueshift adjustments
//#define ANAMORPHICFLARE // Old version of my Anamorphic flare,
something like colormod anamflare and option for a buggy other version
//#define COLORMODBLOOM // BETA: colormod/enb-like bloom
//#define LIGHTSCATTERING // Godrays
#define FILMICPASS // OBGE filmic image improvement
//#define REINHARD_ICE21 // reinhard tonemapping with iCEnhancer 2.1
code improvement
#define DOF // Dynamic DOF, focus on foreground ->background
blurred, focus on background -> foreground blurred
#define GAMMACORRECTION // Gamma adjustment
//#define FILMICCURVE // filmic brightness curving
#define HD6_VIGNETTE // Advanced vignette
//#define BORISVIGNETTE // regular vignette shader - colorable
//#define CROSSPROCESS // Cross Processing/Technicolor, imitates
50/60's image look
//#define CROSSICE // adds Crysis-like color shader (you only
read crysis and enable it, huh? :D )
#define HSVULTIMATE // HSV based color grading, real advanced,
really difficult to adjust

/*-----------------------------------------------------------.
/ TVLevels settings /
'-----------------------------------------------------------*/

#define DARK_LEVEL 16.0 //[0 to 255] Darkness strength. Higher


values mean darker shadows, 0 means no change. Default is 16.0
#define BRIGHT_LEVEL 20.0 //[0 to 255] Brightness strength. Higher
values mean brighter lights, 0 means no change. Default is 20.0

/*-----------------------------------------------------------.
/ Border settings /
'-----------------------------------------------------------*/

float screenwidth = 1920;


float screenheight = 1080;

/*-----------------------------------------------------------.
/ Colorwashout settings /
'-----------------------------------------------------------*/

float ColorSaturation=0.5;
float ColorWashoutThreshold=0.85;
float ColorWashoutPow=1.0;
float ColorWashoutAmount=1.0;
float ColorDullnessAmount=0.5;
float ExpAdjustment=1.2;

/*-----------------------------------------------------------.
/ Anamorphic flare settings /
'-----------------------------------------------------------*/

#define fFlareLuminance 0.93 // bright pass luminance


value
#define fFlareBlur 1000.0 // manages the size of
the flare
#define fFlareIntensity 20.07 // effect intensity
#define fFlareTint float3(0.1, 0.15, 1.0) // effect tint
//#define fFlareVertical
#define fFlareHorizontal
const float FlareRadius = 1.0/256.0;

/*-----------------------------------------------------------.
/ Noise settings /
'-----------------------------------------------------------*/

float4 Timer; //leave as it is,


needed for grain frequency
#define SEED Timer.w //same
#define fGrainFreq 1000.0 // image grain
frequency, for some reason high values cause shadow flickering
#define fGrainScale 0.0001 // grain effect scale

/*-----------------------------------------------------------.
/ Dither settings /
'-----------------------------------------------------------*/

float screen_size = 1920; // Horizontal screen resolution

/*-----------------------------------------------------------.
/ Vibrance settings /
'-----------------------------------------------------------*/

float Vibrance = 0.245; //[-1.0 to 1.0]

/*-----------------------------------------------------------.
/ Chromatic Abberation settings /
'-----------------------------------------------------------*/

float ChromaticAmount = 0.009; // Amount of chromatic


aberration on the edges
float LensSize = 0.55; // 0.5 = Original image size; 1.0 =
Zoomed
float LensDistortion = 0.05; // Can be negative to stretch
the image
float LensDistortionCubic = 0.05; // similiar to above, better
results if same like LensDistortion

/*-----------------------------------------------------------.
/ FXAA settings /
'-----------------------------------------------------------*/

#define FXAA_LINEAR 0
#define FXAA_QUALITY__EDGE_THRESHOLD (1.0/16.0)
#define FXAA_QUALITY__EDGE_THRESHOLD_MIN (1.0/16.0)
#define FXAA_QUALITY__SUBPIX_CAP (3.0/4.0)
#define FXAA_QUALITY__SUBPIX_TRIM (1.0/4.0)
#define FXAA_QUALITY__SUBPIX_TRIM_SCALE (1.0/(1.0 - FXAA_QUALITY__SUBPIX_TRIM))
#define FXAA_SEARCH_STEPS 8
#define FXAA_SEARCH_THRESHOLD (1.0/4.0)

/*-----------------------------------------------------------.
/ HDR + Sharpen settings /
'-----------------------------------------------------------*/

float Defog=0.000; // Strength of FogColor, higher =


more.
float4 FogColor={0.0, 0.0, 0.0, 0.0}; // Lens-style color filters
for Blue, Red, Yellow, White.
float Exposure=0.95; // Contrast settings, higher =
brighter, but also more white.
float Gamma=0.450; // Gamma settings for darker or
lighter shadows and dark areas, higher = darker.
float BlueShift=0.25; // Shifts entire color spectrum
towards blue, good for images too yellow, but this is global.
float sharps = 0.0; //sharpen strength; always offset
value x 2
float offsetv = 0.0; //sharpen offset
float sxres = 1920; // Horizontal Resolution setting x
2
float syres = 1080; // Vertical Resolution setting x 2
float aspect = 1.77777777778; // horizontal/vertical
resolution

/*-----------------------------------------------------------.
/ Old anamorphic flare settings /
'-----------------------------------------------------------*/

#define FLAREMODE_2 //Flaremode 1 = new flare by me;


Flaremode 2 = colormod-type flare
//#define FLAREMODE_2

//the flares work differently so there are different values for the Threshold and
power needed.

static const float thresh1 = 0.979; //Flaremode 1 Threshold


static const float thresh2 = 60.0; //Flaremode 2 Threshold

float fFlareIntensity1 = 50.0; //Flaremode 1 Intensity


float fFlareIntensity2 = 0.03; //Flaremode 2 Intensity

float4 paramsS = {1.0,1.0,1.0,1.0}; //Colorcorrection for dark


areas
float4 paramsM = {1.0,1.0,1.0,1.0}; //Colorcorrection for medium
areas
float4 paramsH = {1.0,1.0,1.0,1.0}; //Colorcorrection for bright
areas

const float fBlurSize = 1.0/384.0; //How big the flare appears, don't
go too high or it will look ugly
const float fBlurDownsampling = 128; //Something IDK, remained
from Petka work, only change in powers of 2 like 16, 32, 64 etc.

//#define FORCECOLOR //if enabled tintcolor doesn't tint


the flare but forces color
//#define ANAMORPHICTINTCOLOR
#define ANAMORPHICREDAMOUNT 0.7 //power of red godray color
#define ANAMORPHICGREENAMOUNT 0.8 //power of green godray color
#define ANAMORPHICBLUEAMOUNT 1.0 //power of blue godray color

/*-----------------------------------------------------------.
/ Colormod-like bloom settings /
'-----------------------------------------------------------*/

static const float fBloomThreshold = 7.0;


float fBloomIntensity = 1.145;
const float BloomRadius = 1.0/64.0;
const float BloomDownsampling = 128;
float BloomCurve =1.0;
//#define COLORBLOOM

/*-----------------------------------------------------------.
/ Light Scattering settings ("Godrays") /
'-----------------------------------------------------------*/

//#define TINTCOLOR //Shifts godray color


#define COLORING //Colorizes godrays, original color gets
lost
#define REDAMOUNT 0.3 //power of red godray color
#define GREENAMOUNT 0.6 //power of green godray color
#define BLUEAMOUNT 0.9 //power of blue godray color

float2 ScreenLightPos = {0.5,0.5}; //where the Godrays appear, 0.5,


0.5 means screen center
float Density = 1.50; //power of the rays
static int NUM_SAMPLES = 128; //how many samples
float Weight = 0.25;
float Decay = 1.0;
float SStresh = 0.938; //pixel threshhold, above this
level pixels get sampled, let it stay like this!
float SunExposure = 2.0; //Sun gets brighter with this value

/*-----------------------------------------------------------.
/ Filmicpass settings /
'-----------------------------------------------------------*/

float Strenght = 0.25; // from 0.0 to 1.0


float BaseGamma = 1.6; // from 0.1.0 to 2.5
float Fade = 0.2; // from 0.0 to 0.5
float Contrast = 1.0; // from 0.6 to 1.0
float Saturation = -0.15; // from 0.25 to -0.25
float Bleach = 0.005; // from 0.0 to 1.0
float RedCurve = 6.0; // from 1.0 to 10.0
float GreenCurve = 6.0; // from 1.0 to 10.0
float BlueCurve = 6.0; // from 1.0 to 10.0
float BaseCurve = 1.5; // from 1.0 to 10.0
float EffectGammaR = 1.0; // from 0.1 to 2.5
float EffectGammaG = 1.0; // from 0.1 to 2.5
float EffectGammaB = 1.0; // from 0.1 to 2.5
float EffectGamma = 0.75; // from 0.1 to 2.5
float Linearization = 1.3; // from 1.0 to 2.5

/*-----------------------------------------------------------.
/ Reinhard tonemap settings /
'-----------------------------------------------------------*/

#define REINHARD_SAT 1.7 //Saturation only for Reinhard tonemap


#define TONEMAPEXP 3.4 //Exposure only for Reinhard
tonemap
#define LUM_FACTOR float4(0.299, 0.587, 0.114, 0.0) //DON NOT CHANGE IT

/*-----------------------------------------------------------.
/ PetkaGtA DOF settings /
'-----------------------------------------------------------*/

//constants, don't change

float ScreenScaleY;
float ScreenSize;
float PI = 3.14159265;
float2 texel = {0.0009765625,0.00130208333333333333333333333333};

//your screen resolution

float2 screenRes = {1920,1080};

//DOF params
float focalDepth = 90.5;
float focalLength = 80.5;
float fstop = 90.5;
bool manualdof = false; //manual dof calculation
float ndofstart = 1.0; //near dof blur start
float ndofdist = 2.0; //near dof blur falloff distance
float fdofstart = 1.0; //far dof blur start
float fdofdist = 3.0; //far dof blur falloff distance
bool autofocus = true;
float2 focus = float2(0.5,0.5);
float CoC = 0.100; //Circle of confusion
http://en.wikipedia.org/wiki/Circle_of_confusion
bool noise = false; //DOF noise, adds grain
float namount = 0.0000; //grain amount
float DOFdownsample = 4;
float maxblur = 4.0; //Power of DOF blur
static const int samples = 6; //more samples =better
quality but also less fps
static const int rings = 2; //ring count, DO NOT GO BEYOND 2 OR
GAME CRASH!!!
float threshold = 4.0; //threshold for gain
float gain =16.0; //brightens blurred areas to make bokeh
effect visible
float bias = 0.0;
float fringe = 0.0;
float znear = 20.0; //camera clipping start (blur
start)
float zfar = 2000.0; //camera clipping end (distance
beyond which blur doesn't get bigger anymore)
bool pentagon = false; //use pentagon as bokeh shape?
Bugged!
float feather = 10.0; //pentagon shape feather

//vignetting, darkens screen borders


bool vignetting = true;
float vignout = 25.31; //vignetting outer border
float vignin = 5.30; //vignetting inner border
float MartyMcFly = 25.30; //f-stops till vignette fades

/*-----------------------------------------------------------.
/ Gamma settings /
'-----------------------------------------------------------*/

#define GammaAmount 2.0 //Gamma intensity

/*-----------------------------------------------------------.
/ Filmiccurve settings /
'-----------------------------------------------------------*/

float FilmicExposure = 7;

//configuring the following stuff is very difficult, let it stay like this
//explanation is senseless because only the most advanced coders really understand
//what each value does (not even me), maybe only the author. Set one to 10 and look
what happens
//is the best way to get its effect

float ShoulderStrength = 0.50;


float LinearStrength = 0.50;
float LinearAngle = 0.30;
float ToeStrength = 2.50;
float ToeNumerator = 0.02;
float ToeDenominator = 1.50;
float FilmWeight = 20.0; // 20

float3 Uncharted2Tonemap(float3 x)
{
return ((x*(ShoulderStrength*x+LinearAngle*LinearStrength)
+ToeStrength*ToeNumerator)/(x*(ShoulderStrength*x+LinearStrength)
+ToeStrength*ToeDenominator))-ToeNumerator/ToeDenominator;
}

/*-----------------------------------------------------------.
/ HD6 Vignette settings /
'-----------------------------------------------------------*/

//#define LEFTANDRIGHT //only enable one of the three options


here!
//#define TOPANDBOTTOM //only enable one of the three options
here!
#define CORNERDARKEN //only enable one of the three options
here!

float SquareTop = 0.58; // TOP of Screen.


float SquareBottom = 0.58; // BOTTOM of Screen.
float CircularPower = 0.4; // CIRCULAR Vignette Amount.
float ColorDistortion = -0.666; // COLOR Distortion Strength.
float ContrastSharpen = 11.666; // Contrast & Sharpness Increase.
float VignetteBorder = 0.6; // High value means black bar, low means
smooth gradient

/*-----------------------------------------------------------.
/ Standard Vignette settings /
'-----------------------------------------------------------*/

float EVignetteAmount=2.9; //Darkening/coloring power


float EVignetteCurve=1.5; //Vignette Curve (helpful huh? :D)
float EVignetteRadius=0.8; //Radius beyond which the screen
starts to get darkened/colored
//#define VIGNCOLORING //optional colorable vignette, ever
wanted to make a red vignette or such? here you go

#define VIGNREDAMOUNT 0.0 //self-explaining I think


#define VIGNGREENAMOUNT 5.0 //self-explaining I think
#define VIGNBLUEAMOUNT 0.0 //self-explaining I think

/*-----------------------------------------------------------.
/ Crossprocess settings /
'-----------------------------------------------------------*/

float CrossContrast =1.0; //Image contrast


float CrossSaturation2 = 1.0; //Image Saturation
float CrossBrightness = 0.0; //Image Brightness
float CrossAmount = 2.0; //amount of color changing
float2 crossMatrix [3] =
{
float2 (1.03, 0.04),
float2 (1.09, 0.01),
float2 (0.78, 0.13),
};

/*-----------------------------------------------------------.
/ color mood/crossice settings /
'-----------------------------------------------------------*/

float fRatio = 0.55; //power of the color distortion


float moodR = 1.0; //preconfigured by ice
float moodG = 1.1; //preconfigured by ice
float moodB = 0.5; //preconfigured by ice

/*-----------------------------------------------------------.
/ Color Grading settings /
'-----------------------------------------------------------*/

#define ENABLE_HSV_CONVERSION // Enables HSV Conversion. Required


for color controls below.
#define ENABLE_SATURATION_ADJUSTMENT // Enables color saturation
control for the entire scene.
#define ENABLE_INTENSITY_ADJUSTMENT // Enables brightness control
for the entire scene.
#define ENABLE_HUE_ADJUSTMENT // Enables hue control for the
entire scene.
#define ENABLE_COLOR_EQUALIZER // Enables the Color Equalizer
system for advanced tweaking.

//#define ENABLE_POW_CURVE // Enables power curve


controls.

// Color Saturation Variables


float EColorSaturationMod=0.0; // Adds to the overall color
saturation. Range: -1 to 1. Default: 0.0
float EColorSaturationMult=1.0; // Multiplies the color saturation.
Range: 0.0 (greyscale) to ???. Default: 1.0
float EColorSaturationPow=1.0; // Curves the color saturation.
Range: 0.0 to ???. Default: 1.0

// Color Intensity Variables


float EColorIntensityMod=0.0; // Adds to the overall brightness.
Range: -1 to 1. Default: 0.0
float EColorIntensityMult=1.0; // Multiplies the color intensity.
Range: 0.0 (black) to ???. Default: 1.0
float EColorIntensityPow=1.0; // Curves the color
intensity. Range: 0.0 to ???. Default: 1.0

// Color Hue Variables


float EColorHueMod=0.0; // Adds to the overall color hue
(color shifting). Range: -1 to 1. Default: 0.0
float EColorHueMult=1.0; // Multiplies the color hue
(color shifting). Range: 0.0 to ???. Default: 1.0
float EColorHuePow=1.0; // Curves the color hue. Range: 0.0
to ???. Default: 1.0.
// Color Equalizer Variables
// Adjust modifier to specific saturations. Range: -??? to ???. Default: 0.0
float SaturationModRed = 0.0;
float SaturationModOrange = 0.0;
float SaturationModYellow = 0.0;
float SaturationModGreen = 0.0;
float SaturationModCyan = 0.0;
float SaturationModBlue = 0.0;
float SaturationModMagenta = 0.0;

// Adjust multiplier to specific saturations. Range: 0.0 to ???. Default: 0.0


float SaturationMultRed = 0.1;
float SaturationMultOrange = -0.2;
float SaturationMultYellow = 0.0;
float SaturationMultGreen = 0.2;
float SaturationMultCyan = -0.1;
float SaturationMultBlue = 0.0;
float SaturationMultMagenta = 0.1;

// Adjust curve of specific saturations. Range: -1.0 to ???. Default: 0.0


float SaturationPowRed = 0.0;
float SaturationPowOrange = 0.0;
float SaturationPowYellow = 0.0;
float SaturationPowGreen = 0.0;
float SaturationPowCyan = 0.0;
float SaturationPowBlue = 0.0;
float SaturationPowMagenta = 0.0;

//////////////////////////////////-------------------------------------------------
----------------]
//////////////////////////////////////////////
// DO NOT MODIFY ANYTHING BELOW THIS LINE, //
// UNLESS YOU KNOW HLSL SHADER PROGRAMMING. //
//////////////////////////////////////////////
//////////////////////////////////-------------------------------------------------
----------------]

//#define COLORCORRMAIN

#ifdef HSVULTIMATE
// List of floating point values for hues, used in equalizer.
float HueRed = 0.0;
float HueOrange = 0.08333333;
float HueYellow = 0.16666667;
float HueGreen = 0.33333333;
float HueCyan = 0.5;
float HueBlue = 0.66666667;
float HueMagenta = 0.83333333;
float HueRed2 = 1.0;

float HueSkin = 0.07;


float HueSky = 0.58;

float ColorEqualizerMult(in float H)


{
float SMult = 1.0;
SMult += SaturationMultRed * ( 1.0 - min( 1.0, abs( ( HueRed - H ) / ( HueRed -
HueOrange ) ) ) );
SMult += SaturationMultOrange * ( 1.0 - min( 1.0, abs( ( HueOrange - H ) /
( HueOrange - HueYellow ) ) ) );
SMult += SaturationMultYellow * ( 1.0 - min( 1.0, abs( ( HueYellow - H ) /
( HueYellow - HueGreen ) ) ) );
SMult += SaturationMultGreen * ( 1.0 - min( 1.0, abs( ( HueGreen - H ) / ( HueGreen
- HueYellow ) ) ) );
SMult += SaturationMultCyan * ( 1.0 - min( 1.0, abs( ( HueCyan - H ) / ( HueCyan -
HueGreen ) ) ) );
SMult += SaturationMultBlue * ( 1.0 - min( 1.0, abs( ( HueBlue - H ) / ( HueBlue -
HueCyan ) ) ) );
SMult += SaturationMultMagenta * ( 1.0 - min( 1.0, abs( ( HueMagenta - H ) /
( HueMagenta - HueBlue ) ) ) );
SMult += SaturationMultRed * ( 1.0 - min( 1.0, abs( ( HueRed2 - H ) / ( HueRed2 -
HueMagenta ) ) ) );
return SMult;
}

float ColorEqualizerMod(in float H)


{
float SMod = 0.0;
SMod += SaturationModRed * ( 1.0 - min( 1.0, abs( ( HueRed - H ) / ( HueRed -
HueOrange ) ) ) );
SMod += SaturationModOrange * ( 1.0 - min( 1.0, abs( ( HueOrange - H ) /
( HueOrange - HueYellow ) ) ) );
SMod += SaturationModYellow * ( 1.0 - min( 1.0, abs( ( HueYellow - H ) /
( HueYellow - HueGreen ) ) ) );
SMod += SaturationModGreen * ( 1.0 - min( 1.0, abs( ( HueGreen - H ) / ( HueGreen -
HueYellow ) ) ) );
SMod += SaturationModCyan * ( 1.0 - min( 1.0, abs( ( HueCyan - H ) / ( HueCyan -
HueGreen ) ) ) );
SMod += SaturationModBlue * ( 1.0 - min( 1.0, abs( ( HueBlue - H ) / ( HueBlue -
HueCyan ) ) ) );
SMod += SaturationModMagenta * ( 1.0 - min( 1.0, abs( ( HueMagenta - H ) /
( HueMagenta - HueBlue ) ) ) );
SMod += SaturationModRed * ( 1.0 - min( 1.0, abs( ( HueRed2 - H ) / ( HueRed2 -
HueMagenta ) ) ) );
return SMod;
}

float ColorEqualizerPow(in float H)


{
float SPow = 1.0;
SPow += SaturationPowRed * ( 1.0 - min( 1.0, abs( ( HueRed - H ) / ( HueRed -
HueOrange ) ) ) );
SPow += SaturationPowOrange * ( 1.0 - min( 1.0, abs( ( HueOrange - H ) /
( HueOrange - HueYellow ) ) ) );
SPow += SaturationPowYellow * ( 1.0 - min( 1.0, abs( ( HueYellow - H ) /
( HueYellow - HueGreen ) ) ) );
SPow += SaturationPowGreen * ( 1.0 - min( 1.0, abs( ( HueGreen - H ) / ( HueGreen -
HueYellow ) ) ) );
SPow += SaturationPowCyan * ( 1.0 - min( 1.0, abs( ( HueCyan - H ) / ( HueCyan -
HueGreen ) ) ) );
SPow += SaturationPowBlue * ( 1.0 - min( 1.0, abs( ( HueBlue - H ) / ( HueBlue -
HueCyan ) ) ) );
SPow += SaturationPowMagenta * ( 1.0 - min( 1.0, abs( ( HueMagenta - H ) /
( HueMagenta - HueBlue ) ) ) );
SPow += SaturationPowRed * ( 1.0 - min( 1.0, abs( ( HueRed2 - H ) / ( HueRed2 -
HueMagenta ) ) ) );
return SPow;
}

float3 HUEtoRGB(in float H)


{
float R = abs(H * 6.0 - 3.0) - 1.0;
float G = 2.0 - abs(H * 6.0 - 2.0);
float B = 2.0 - abs(H * 6.0 - 4.0);
return saturate(float3(R,G,B));
}

float RGBCVtoHUE(in float3 RGB, in float C, in float V)


{
float3 Delta = (V - RGB) / C;
Delta.rgb -= Delta.brg;
Delta.rgb += float3(2.0,4.0,6.0);
Delta.brg = step(V, RGB) * Delta.brg;
float H;
H = max(Delta.r, max(Delta.g, Delta.b));
return frac(H / 6.0);
}

float3 HSVtoRGB(in float3 HSV)


{
float3 RGB = HUEtoRGB(HSV.x);
return ((RGB - 1) * HSV.y + 1) * HSV.z;
}

float3 RGBtoHSV(in float3 RGB)


{
float3 HSV = 0.0;
HSV.z = max(RGB.r, max(RGB.g, RGB.b));
float M = min(RGB.r, min(RGB.g, RGB.b));
float C = HSV.z - M;
if (C != 0.0)
{
HSV.x = RGBCVtoHUE(RGB, C, HSV.z);
HSV.y = C / HSV.z;
}
return HSV;
}
#endif

#ifdef FILMICPASS
float GetLuminance(float3 sample)
{
return dot(sample.xyz, 0.333);
}

float4 FilmPass(float4 B)
{
float4 G = B;
float4 H = 0.01;

B = pow(abs(B), Linearization);
B = lerp(H, B, Contrast);

float A = GetLuminance(B.rgb);
float4 D = A;

B = pow(abs(B), 1.0 / BaseGamma);

float a = RedCurve;
float b = GreenCurve;
float c = BlueCurve;
float d = BaseCurve;

float y = 1.0 / (1.0 + exp(a / 2.0));


float z = 1.0 / (1.0 + exp(b / 2.0));
float w = 1.0 / (1.0 + exp(c / 2.0));
float v = 1.0 / (1.0 + exp(d / 2.0));

float4 C = B;

D.r = (1.0 / (1.0 + exp(-a * (D.r - 0.5))) - y) / (1.0 - 2.0 * y);


D.g = (1.0 / (1.0 + exp(-b * (D.g - 0.5))) - z) / (1.0 - 2.0 * z);
D.b = (1.0 / (1.0 + exp(-c * (D.b - 0.5))) - w) / (1.0 - 2.0 * w);

D = pow(abs(D), 1.0 / EffectGamma);

float4 Di = 1.0 - D;

D = lerp(D, Di, Bleach);

D.r = pow(abs(D.r), 1.0 / EffectGammaR);


D.g = pow(abs(D.g), 1.0 / EffectGammaG);
D.b = pow(abs(D.b), 1.0 / EffectGammaB);

if (D.r < 0.5)


C.r = (2.0 * D.r - 1.0) * (B.r - B.r * B.r) + B.r;
else
C.r = (2.0 * D.r - 1.0) * (sqrt(B.r) - B.r) + B.r;

if (D.g < 0.5)


C.g = (2.0 * D.g - 1.0) * (B.g - B.g * B.g) + B.g;
else
C.g = (2.0 * D.g - 1.0) * (sqrt(B.g) - B.g) + B.g;
//if (AgainstAllAutority) then fckoff else fckoff
if (D.b < 0.5)
C.b = (2.0 * D.b - 1.0) * (B.b - B.b * B.b) + B.b;
else
C.b = (2.0 * D.b - 1.0) * (sqrt(B.b) - B.b) + B.b;

float4 F = lerp(B, C, Strenght);

F = (1.0 / (1.0 + exp(-d * (F - 0.5))) - v) / (1.0 - 2.0 * v);

float r2R = 1.0 - Saturation;


float g2R = 0.0 + Saturation;
float b2R = 0.0 + Saturation;

float r2G = 0.0 + Saturation;


float g2G = (1.0 - Fade) - Saturation;
float b2G = (0.0 + Fade) + Saturation;

float r2B = 0.0 + Saturation;


float g2B = (0.0 + Fade) + Saturation;
float b2B = (1.0 - Fade) - Saturation;

float4 iF = F;

F.r = (iF.r * r2R + iF.g * g2R + iF.b * b2R);


F.g = (iF.r * r2G + iF.g * g2G + iF.b * b2G);
F.b = (iF.r * r2B + iF.g * g2B + iF.b * b2B);

float N = GetLuminance(F.rgb);
float4 Cn = F;

if (N < 0.5)
Cn = (2.0 * N - 1.0) * (F - F * F) + F;
else
Cn = (2.0 * N - 1.0) * (sqrt(F) - F) + F;

Cn = pow(abs(Cn), 1.0 / Linearization);

float4 Fn = lerp(B, Cn, Strenght);


return Fn;
}
#endif
//---------------------------------------------------------------------------------
-----
// Textures
//---------------------------------------------------------------------------------
-----
texture2D texColor;
texture2D texDepth;
texture2D texNoise;
//---------------------------------------------------------------------------------
-----
// Sampler Inputs
//---------------------------------------------------------------------------------
-----

sampler2D InputSampler = sampler_state


{
Texture = (texColor);
MinFilter = POINT;
MagFilter = POINT;
MipFilter = POINT;
AddressU = Clamp;
AddressV = Clamp;
SRGBTexture=FALSE;
MaxMipLevel=0;
MipMapLodBias=0;
};

sampler2D SamplerDepth = sampler_state


{
Texture = <texDepth>;
MinFilter = POINT;
MagFilter = POINT;
MipFilter = NONE;
AddressU = Clamp;
AddressV = Clamp;
SRGBTexture=FALSE;
MaxMipLevel=0;
MipMapLodBias=0;
};

sampler2D SamplerNoise = sampler_state


{
Texture = <texNoise>;
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = LINEAR;
AddressU = Wrap;
AddressV = Wrap;
SRGBTexture = FALSE;
MaxMipLevel = 0;
MipMapLodBias = 0;
};

struct VS_OUTPUT_POST
{
float4 vpos : POSITION;
float2 txcoord : TEXCOORD0;
};

struct VS_INPUT_POST
{
float3 pos : POSITION;
float2 txcoord : TEXCOORD0;
};

//---------------------------------------------------------------------------------
-----
// Vertex Shader Input
//---------------------------------------------------------------------------------
-----

VS_OUTPUT_POST VS_PostProcess(VS_INPUT_POST IN)


{
VS_OUTPUT_POST OUT;

float4 pos=float4(IN.pos.x,IN.pos.y,IN.pos.z,1.0);

OUT.vpos=pos;
OUT.txcoord.xy=IN.txcoord.xy;

return OUT;
}

//---------------------------------------------------------------------------------
-----
// Pixel Shader
//---------------------------------------------------------------------------------
-----

float Luminance( float3 c )


{
return dot( c, float3(0.22, 0.707, 0.071) );
}
#ifdef DOF
float penta(float2 coords) //pentagonal shape
{
float scale = float(rings) - 1.5;
float4 HS0 = float4( -20.0, -15.0, -15.0, -20.0);
float4 HS1 = float4( -20.0, -15.0, -15.0, -20.0);
float4 HS2 = float4( -20.0, -15.0, -15.0, -20.0);
float4 HS3 = float4( -20.0, -15.0, -15.0, -20.0);
float4 HS4 = float4( -20.0, -15.0, -15.0, -20.0);
float4 HS5 = float4( -20.0, -15.0, -15.0, -20.0);

float4 one = float4(8.0, 8.0, 8.0, 8.0);

float4 P = float4(coords,float2(scale, scale));

float4 dist = float4(4.0, 4.0, 4.0, 4.0);


float inorout = 0.0;

dist.x = dot( P, HS0 );


dist.y = dot( P, HS1 );
dist.z = dot( P, HS2 );
dist.w = dot( P, HS3 );

dist = smoothstep( -feather, feather, dist );

inorout += dot( dist, one );

dist.x = dot( P, HS4 );


dist.y = HS5.w - abs( P.z );

dist = smoothstep( -feather, feather, dist );


inorout += dist.x;

return saturate( inorout );


}

float linearize(float depth)


{
return -zfar * znear / (depth * (zfar - znear) - zfar);
}

float2 rand(float2 coord) //generating noise/pattern texture for dithering


{
float noiseX = ((frac(1.0-coord.x*(screenRes.x/2.0))*0.25)+
(frac(coord.y*(screenRes.y/2.0))*0.75))*2.0-1.0;
float noiseY = ((frac(1.0-coord.x*(screenRes.x/2.0))*0.75)+
(frac(coord.y*(screenRes.y/2.0))*0.25))*2.0-1.0;

return float2(noiseX,noiseY);
}

float4 colorDof(float2 coords,float blur) //processing the sample


{
float4 colDF = float4(0,0,0,1);
colDF.x = tex2D(InputSampler,coords + float2(0.0,1.0)*texel*fringe*blur).x;
colDF.y = tex2D(InputSampler,coords + float2(-0.866,-
0.5)*texel*fringe*blur).y;
colDF.z = tex2D(InputSampler,coords + float2(0.866,-
0.5)*texel*fringe*blur).z; //by Marty McFly

float3 lumcoeff = float3(0.299,0.587,0.114);


float lum = dot(colDF.xyz,lumcoeff);
float thresh = max((lum-threshold)*gain, 0.0);
float3 nullcol = float3(0,0,0);
colDF.xyz +=lerp(nullcol,colDF.xyz,thresh*blur);
return colDF;
}

float vignette(float2 coord)


{
float dist = distance(coord, float2(0.5,0.5));
dist = smoothstep(vignout+(fstop/MartyMcFly), vignin+(fstop/MartyMcFly),
dist);
return saturate(dist);
}
#endif

#ifdef NOISE

float Random(float2 co)


{
return frac(sin(dot(co.xy, float2(12.9898, 78.233))) * 43758.5453);
}

float Grain(float3 tex)


{
float PI = 3.1415926535897932384626433832795;
float rofl = Random(tex.xy);
float grain = sin(PI * tex.z * rofl * fGrainFreq) * fGrainScale * rofl;
return grain;
}
#endif

float4 main(VS_OUTPUT_POST i, float2 vPos : VPOS) : COLOR


{
float4 color = tex2D(InputSampler, i.txcoord);

#ifdef HSVULTIMATE
#ifdef ENABLE_HSV_CONVERSION
float3 hsvcolor = RGBtoHSV( color.xyz );

#ifdef ENABLE_POW_CURVE
#ifdef ENABLE_HUE_ADJUSTMENT
hsvcolor.x = EColorHueMod + ( EColorHueMult * pow( hsvcolor.x, EColorHuePow ) );
#endif
#ifdef ENABLE_SATURATION_ADJUSTMENT
hsvcolor.y = EColorSaturationMod + ( EColorSaturationMult * pow( hsvcolor.y,
EColorSaturationPow ) );
#endif
#ifdef ENABLE_INTENSITY_ADJUSTMENT
hsvcolor.z = EColorIntensityMod + ( EColorIntensityMult * pow( hsvcolor.z,
EColorIntensityPow ) );
#endif
#ifdef ENABLE_COLOR_EQUALIZER
hsvcolor.y = ColorEqualizerMod( hsvcolor.x ) + ( ColorEqualizerMult( hsvcolor.x ) *
pow( hsvcolor.y, ColorEqualizerPow( hsvcolor.x ) ) );
#endif
#endif

#ifndef ENABLE_POW_CURVE
#ifdef ENABLE_HUE_ADJUSTMENT
hsvcolor.x = EColorHueMod + ( EColorHueMult * hsvcolor.x );
#endif
#ifdef ENABLE_SATURATION_ADJUSTMENT
hsvcolor.y = EColorSaturationMod + ( EColorSaturationMult * hsvcolor.y );
#endif
#ifdef ENABLE_INTENSITY_ADJUSTMENT
hsvcolor.z = EColorIntensityMod + ( EColorIntensityMult * hsvcolor.z );
#endif
#ifdef ENABLE_COLOR_EQUALIZER
hsvcolor.y = ColorEqualizerMod( hsvcolor.x ) + ( ColorEqualizerMult( hsvcolor.x ) *
hsvcolor.y );
#endif
#endif

hsvcolor.y = max( hsvcolor.y, 0.0 );


hsvcolor.z = max( hsvcolor.z, 0.0 );
color.xyz = HSVtoRGB( hsvcolor );
#endif
#endif

#ifdef GAMMACORRECTION
color = pow(color, 1/GammaAmount);
#endif

#ifdef COLORCORRMAIN
color.r = (color.r)*(0.05 + 1.0f) + (color.g + color.b)*(-0.04);
color.g = (color.g)*(0.06 + 1.0f) + (color.r + color.b)*(-0.04);
color.b = (color.b)*(0.055 + 1.0f) + (color.r + color.g)*(-0.04);

color.rgb = (color.rgb * (1.0 + color.rgb / 2))/(color.rgb + 4);


color = color*(1.0f + 0.2) - 0.12;
#endif

#ifdef COLORCORRMAIN
color = saturate(color);
color = 1 - (0.97 - 0.065)*(1.04 - color);
color = saturate(color);
color = color + (0.82f / 2.0 - 0.5) * (1.0 - color);
color = saturate(color);
color.rgb = pow(0.85f * color, 1.0 / 0.95f);

float dbr = -color.r + 1.4f;


float dbg = -color.g + 1.4f;
float dbb = -color.b + 1.4f;

float pr = lerp(dbr, 0.55f, 0.66f);


float pg = lerp(dbg, 0.55f, 0.66f);
float pb = lerp(dbb, 0.55f, 0.66f);
color.r = pow((color.r * 0.94f - 0.0035f), pr);
color.g = pow((color.g * 0.94f - 0.002f), pg);
color.b = pow((color.b * 0.91f + 0.001f), pb);

color = color * 4.0;


#endif

#ifdef FILMICCURVE
float3 curr = Uncharted2Tonemap(color);
float3 whiteScale = Uncharted2Tonemap(FilmWeight);
color.xyz = curr*whiteScale;
color = pow(color, 0.55);
color = color*FilmicExposure;
#endif

#ifdef REINHARD_ICE21
float pixelLumi = dot(color.xyz, LUM_FACTOR.xyz);
float toneMapCalc = pixelLumi / (pixelLumi + 1);
color = toneMapCalc * pow(color / pixelLumi, REINHARD_SAT);
color = color * TONEMAPEXP;
#endif

float toneMapExposure = 1.2;

color = color * toneMapExposure;


color = max(0, color - 0.004);
color = (color * (6.2 * color + 0.5)) / (color * (6.2 * color + 1.7)+ 0.06);
color = pow(color, 2.2);

#ifdef CROSSPROCESS

float4 image1 = color;


float4 image2 = color;
float gray = dot(float3(0.5,0.5,0.5), image1);

image1 = lerp (gray, image1,CrossSaturation2);

image1 = lerp (0.35, image1,CrossContrast);

image1 +=CrossBrightness;
image1 *=1.2;

image2.r = image1.r * crossMatrix[0].x + crossMatrix[0].y;


image2.g = image1.g * crossMatrix[1].x + crossMatrix[1].y;
image2.b = image1.b * crossMatrix[2].x + crossMatrix[2].y;

color = lerp(image1, image2, CrossAmount);

#endif

#ifdef CROSSICE
float Weight;
float4 colInput = color;
float4 colMood = 1.0f;
colMood.r = moodR;
colMood.g = moodG;
colMood.b = moodB;
float fLum = ( colInput.r + colInput.g + colInput.b ) / 3;
colMood = lerp(0, colMood, saturate(fLum * 2.0));
colMood = lerp(colMood, 1, saturate(fLum - 0.5) * 2.0);
float4 colOutput = lerp(colInput, colMood, saturate(fLum * fRatio));
color.rgb=max(0, colOutput);
#endif

#ifdef HDR
color.xyz = max(0, color.xyz - Defog * FogColor.xyz);
color.xyz *= pow(2.0f, Exposure);
color.xyz = pow(color.xyz, Gamma);
float3 trollface = color.xyz * float3(1.05f, 0.97f, 1.27f);
color.xyz = lerp(color.xyz, trollface, BlueShift);
#endif

#ifdef FILMICPASS
color = FilmPass(color);
#endif

#ifdef VIBRANCEPASS
float3 lumCoeff = float3(0.2126, 0.7152, 0.0722);
float vibranceluma = dot(lumCoeff, color.xyz);

float max_color = max(color.x, max(color.y,color.z)); //Find the strongest color


float min_color = min(color.x, max(color.y,color.z)); //Find the weakest color
float color_saturation = max_color - min_color;

color.xyz = lerp(vibranceluma, color.xyz, (1.0 + (Vibrance * (1.0 - (sign(Vibrance)


* color_saturation)))));
#endif

#ifdef COLORWASHOUT
float colorGray=dot(color.xyz, 0.333);
float

colorGray2=(colorGray*(6.2*colorGray+0.5))/(colorGray*(6.2*colorGray+1.7)+0.06);
float colorGray3=pow(colorGray, 0.36);
float colorWashout=saturate(colorGray2 - ColorWashoutThreshold)/(1.00 -
ColorWashoutThreshold);
colorWashout=saturate(pow(colorWashout, ColorWashoutPow) * ColorWashoutAmount);

float3 middleColor=(color.xyz+0.0001)/(colorGray+0.000001);
middleColor.xyz=lerp(pow(middleColor.xyz, ColorSaturation), middleColor.xyz,
ColorSaturation);
middleColor.xyz=lerp(middleColor.xyz, 1.00,
saturate(colorWashout*ColorWashoutAmount));
float tonemapMix=(0.5 - ColorDullnessAmount)*0.60; //temp
colorGray=lerp(colorGray2, colorGray3, tonemapMix);
color.xyz=middleColor.xyz*colorGray;
color.xyz *= ExpAdjustment;
#endif

#ifdef BORISVIGNETTE
float2 uv=(i.txcoord-0.5)*EVignetteRadius;
float vignetteold=saturate(dot(uv.xy, uv.xy));
vignetteold=pow(vignetteold, EVignetteCurve);
#ifdef VIGNCOLORING
float3 EVignetteColor=float3(VIGNREDAMOUNT, VIGNGREENAMOUNT,
VIGNBLUEAMOUNT);
#else
float3 EVignetteColor=float3(0.0, 0.0, 0.0);
#endif
color.xyz=lerp(color.xyz, EVignetteColor, vignetteold*EVignetteAmount);
#endif

#ifdef HD6_VIGNETTE

float rovigpwr = CircularPower; //for a circular vignette


float2 sqvigpwr = float2( SquareTop, SquareBottom ); // for the top and
bottom of the screen
float vsatstrength = ColorDistortion; // color distortion
float vignettepow = ContrastSharpen; // increases the contrast and sharpness
float vstrengthatnight = VignetteBorder;

float2 inTex = i.txcoord;


float vhnd = 0.5;
float4 voriginal = color;
float4 vcolor = voriginal;
vcolor.xyz=1;
inTex -= 0.5; // center
inTex.y += 0.01; // offset from the center
float vignette = 1.0 - dot( inTex, inTex );
vcolor *= pow( vignette, vignettepow );

float4 rvigtex = vcolor;


rvigtex.xyz = pow( vcolor, 1 );
rvigtex.xyz = lerp(float3(0.5, 0.5, 0.5), rvigtex.xyz, 2.25); // contrast
rvigtex.xyz = lerp(float3(1,1,1),rvigtex.xyz,rovigpwr); // strength of the
circular vinetty

//darken the top and bottom


float4 vigtex = vcolor;
vcolor.xyz = float3(1,1,1);

#ifdef LEFTANDRIGHT
float3 topv = min((inTex.x+0.5)*2,1.5) * 2; // top
float3 botv = min(((0-inTex.x)+0.5)*2,1.5) * 2; // botton
topv= lerp(float3(1,1,1), topv, sqvigpwr.x);
botv= lerp(float3(1,1,1), botv, sqvigpwr.y);
vigtex.xyz = (topv)*(botv);
#endif
#ifdef TOPANDBOTTOM
float3 topv = min((inTex.y+0.5)*2,1.5) * 2; // top
float3 botv = min(((0-inTex.y)+0.5)*2,1.5) * 2; // botton
topv= lerp(float3(1,1,1), topv, sqvigpwr.x);
botv= lerp(float3(1,1,1), botv, sqvigpwr.y);
vigtex.xyz = (topv)*(botv);
#endif
#ifdef CORNERDARKEN
float3 rightv = min((inTex.x+0.5)*2,1.5) * 2;
float3 leftv = min(((0-inTex.x)+0.5)*2,1.5) * 2;
float3 topv = min((inTex.y+0.5)*2,1.5) * 2;
float3 botv = min(((0-inTex.y)+0.5)*2,1.5) * 2;
rightv= lerp(float3(1,1,1), rightv, sqvigpwr.y);
leftv= lerp(float3(1,1,1), leftv, sqvigpwr.x);
topv= lerp(float3(1,1,1), topv, sqvigpwr.x);
botv= lerp(float3(1,1,1), botv, sqvigpwr.y);
vigtex.xyz = (topv)*(botv)*(rightv)*(leftv);
#endif

//vigtex.xyz = lerp(float3(1,1,1),vigtex.xyz,sqvigpwr); // strength of the


top and bottom

// mix the two types of vignettes


vigtex.xyz*=rvigtex.xyz;
vigtex.xyz = lerp(vigtex.xyz,float3(1,1,1),(vhnd-vstrengthatnight*vhnd));
//for a dark screen
vigtex.xyz = min(vigtex.xyz,1);
vigtex.xyz = max(vigtex.xyz,0);
float3 vtintensity = dot(voriginal.xyz, float3(0.2125, 0.7154, 0.0721));
color.xyz = lerp(vtintensity, voriginal.xyz, ((((1-(vigtex.xyz*2))+2)-
1)*vsatstrength)+1 );
color.xyz *= (vigtex.xyz);
#endif

float2 InputSize = float2(sxres, syres/aspect);


float Amount = sharps;
float2 offset = offsetv / InputSize;
float4 sharpencolor=tex2D(InputSampler, i.txcoord);
sharpencolor += tex2D(InputSampler, i.txcoord - offset) * Amount;
sharpencolor -= tex2D(InputSampler, i.txcoord + offset) * Amount;

#define const_1 (DARK_LEVEL/255.0)


#define const_2 (255.0/(255.0-BRIGHT_LEVEL))

#ifdef TVLEVELS
color.xyz = (color.xyz - const_1) * const_2;
#endif

#ifdef USE_DITHER2
float dither_size = 2.0; //move to settings?
float dither_bit = 8.0; //move to settings?
float grid_position = frac(dot(i.txcoord,(screen_size / dither_size)) + (0.5 /
dither_size));
float dither_shift = (0.25) * (1.0 / (pow(2,dither_bit) - 1.0));
color.xyz += lerp(2.0 * dither_shift,(-2.0 * dither_shift),grid_position);
#endif

#ifdef USE_DITHER
float dither_size = 2.0; //move to settings?
float dither_bit = 8.0; //move to settings?
float grid_position = frac(dot(i.txcoord,(screen_size / dither_size)) + (0.5 /
dither_size));
float dither_shift = (0.25) * (1.0 / (pow(2,dither_bit) - 1.0));
float3 dither_shift_RGB = float3(dither_shift, dither_shift, dither_shift);
color.xyz += lerp(2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position);
#endif

#define BUFFER_RCP_WIDTH (1.0 / screenwidth)


#define BUFFER_RCP_HEIGHT (1.0 / screenheight)

#define px BUFFER_RCP_WIDTH
#define py BUFFER_RCP_HEIGHT
#define pixel float2(px,py)

#ifdef BORDER
float2 distancefromcenter = abs(i.txcoord.xy - 0.5);
bool2 screen_border = step(0.5 - pixel,distancefromcenter);
color.xyz = (!dot(screen_border, 1.0)) ? color.xyz : 0.0;
#endif

color.w = 1.0;

return color*sharpencolor;
}

#ifdef LIGHTSCATTERING
float4 PS_ProcessSunShafts(VS_OUTPUT_POST IN, float2 vPos : VPOS) : COLOR
{
float2 texCoord = IN.txcoord;
// Calculate vector from pixel to light source in screen space.
half2 deltaTexCoord = (texCoord - ScreenLightPos.xy);
// Divide by number of samples and scale by control factor.
deltaTexCoord *= 1.0f / NUM_SAMPLES * Density;
// Store initial sample.
half3 color = max(float4(0,0,0,0),tex2D(InputSampler, texCoord)-SStresh);
// Set up illumination decay factor.
half illuminationDecay = 1.0f;
// Evaluate summation from Equation 3 NUM_SAMPLES iterations.
for (int i = 0; i < NUM_SAMPLES; i++)
{
// Step sample location along ray.
texCoord -= deltaTexCoord;
// Retrieve sample at new location.
half3 sample = max(float4(0,0,0,0),tex2D(InputSampler, texCoord)-
SStresh);
// Apply sample attenuation scale/decay factors.

#ifdef TINTCOLOR
sample.r *= REDAMOUNT;
sample.g *= GREENAMOUNT;
sample.b *= BLUEAMOUNT;
#endif

#ifdef COLORING
sample = dot(sample, float3(0.3, 0.59, 0.11));
sample.r *= REDAMOUNT;
sample.g *= GREENAMOUNT;
sample.b *= BLUEAMOUNT;
#endif

sample *= illuminationDecay * Weight;


// Accumulate combined color.
color += sample;
// Update exponential decay factor.
illuminationDecay *= Decay;
}
// Output final color with a further scale control factor.
return float4( saturate(color*SunExposure) , color.x);
}
#endif

#ifdef ANAMORPHICFLARE
float4 CCShadow (VS_OUTPUT_POST i, float2 vPos : VPOS) : COLOR
{

float4 threshhold1 = {thresh1, 1/(1-thresh1), 5.0, 5.0};


float4 threshhold2 = {thresh2, 1/(1-thresh2), 5.0, 5.0};
float4 col = tex2D(InputSampler, i.txcoord);
//float4 color = tex2Dlod(InputSampler, float4(i.txcoord,0,8));

float4 sum = float4(0,0,0,0);

// blur this in y (vertical)


// also I downsample it to get interesting result

#ifdef FLAREMODE_1
sum += tex2Dlod(InputSampler, float4(i.txcoord.y - 4.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.05;
sum += tex2Dlod(InputSampler, float4(i.txcoord.y - 3.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.09;
sum += tex2Dlod(InputSampler, float4(i.txcoord.y - 2.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.12;
sum += tex2Dlod(InputSampler, float4(i.txcoord.y - fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.15;
sum += tex2Dlod(InputSampler, float4(i.txcoord.y,
i.txcoord.y,0,fBlurDownsampling)) * 0.16;
sum += tex2Dlod(InputSampler, float4(i.txcoord.y + fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.15;
sum += tex2Dlod(InputSampler, float4(i.txcoord.y + 2.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.12;
sum += tex2Dlod(InputSampler, float4(i.txcoord.y + 3.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.09;
sum += tex2Dlod(InputSampler, float4(i.txcoord.y + 4.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.05;
#endif
#ifdef FLAREMODE_2
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 100.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.01;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 99.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.01;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 98.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.02;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 97.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.03;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 96.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.04;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 95.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.05;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 94.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.06;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 93.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.07;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 92.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.08;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 91.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.09;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 90.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.10;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 89.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.11;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 88.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.12;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 87.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.13;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 86.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.14;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 85.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.15;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 84.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.16;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 83.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.17;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 82.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.18;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 81.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.19;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 80.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.20;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 79.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.21;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 78.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.22;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 77.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.23;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 76.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.24;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 75.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.25;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 74.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.26;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 73.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.27;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 72.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.28;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 71.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.29;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 70.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.30;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 69.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.31;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 68.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.32;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 67.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.33;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 66.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.34;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 65.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.35;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 64.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.36;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 63.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.37;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 62.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.38;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 61.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.39;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 60.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.40;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 59.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.41;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 58.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.42;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 57.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.43;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 56.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.44;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 55.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.45;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 54.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.46;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 53.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.47;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 52.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.48;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 51.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.49;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 50.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.50;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 49.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.51;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 48.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.52;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 47.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.53;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 46.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.54;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 45.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.55;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 44.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.56;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 43.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.57;
//---------------------------------------------------------------------------------
---------------------------------------------
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 42.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.58;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 41.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.59;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 40.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.60;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 39.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.61;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 38.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.62;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 37.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.63;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 36.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.64;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 35.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.65;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 34.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.66;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 33.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.67;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 32.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.68;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 31.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.69;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 30.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.70;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 29.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.71;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 28.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.72;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 27.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.73;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 26.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.74;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 25.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.75;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 24.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.76;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 23.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.77;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 22.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.78;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 21.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.79;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 20.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.80;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 19.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.81;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 18.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.82;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 17.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.83;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 16.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.84;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 15.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.85;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 14.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.86;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 13.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.87;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 12.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.88;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 11.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.89;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 10.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.90;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 9.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.91;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 8.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.92;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 7.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.93;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 6.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.94;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 5.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.95;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 4.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.96;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 3.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.97;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - 2.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.98;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x - fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.99;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x, i.txcoord.y,0,fBlurDownsampling))


* 1.0;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 100.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.01;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 99.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.01;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 98.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.02;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 97.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.03;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 96.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.04;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 95.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.05;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 94.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.06;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 93.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.07;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 92.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.08;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 91.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.09;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 90.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.10;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 89.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.11;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 88.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.12;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 87.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.13;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 86.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.14;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 85.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.15;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 84.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.16;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 83.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.17;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 82.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.18;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 81.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.19;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 80.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.20;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 79.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.21;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 78.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.22;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 77.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.23;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 76.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.24;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 75.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.25;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 74.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.26;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 73.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.27;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 72.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.28;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 71.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.29;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 70.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.30;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 69.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.31;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 68.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.32;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 67.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.33;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 66.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.34;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 65.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.35;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 64.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.36;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 63.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.37;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 62.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.38;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 61.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.39;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 60.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.40;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 59.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.41;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 58.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.42;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 57.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.43;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 56.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.44;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 55.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.45;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 54.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.46;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 53.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.47;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 52.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.48;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 51.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.49;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 50.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.50;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 49.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.51;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 48.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.52;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 47.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.53;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 46.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.54;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 45.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.55;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 44.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.56;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 43.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.57;
//++++
+----------------------------------------------------------------------------------
---------------------------------------
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 42.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.58;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 41.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.59;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 40.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.60;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 39.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.61;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 38.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.62;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 37.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.63;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 36.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.64;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 35.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.65;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 34.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.66;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 33.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.67;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 32.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.68;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 31.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.69;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 30.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.70;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 29.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.71;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 28.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.72;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 27.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.73;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 26.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.74;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 25.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.75;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 24.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.76;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 23.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.77;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 22.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.78;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 21.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.79;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 20.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.80;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 19.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.81;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 18.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.82;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 17.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.83;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 16.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.84;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 15.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.85;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 14.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.86;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 13.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.87;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 12.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.88;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 11.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.89;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 10.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.90;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 9.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.91;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 8.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.92;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 7.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.93;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 6.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.94;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 5.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.95;

sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 4.0*fBlurSize,


i.txcoord.y,0,fBlurDownsampling)) * 0.96;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 3.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.97;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + 2.0*fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.98;
sum += tex2Dlod(InputSampler, float4(i.txcoord.x + fBlurSize,
i.txcoord.y,0,fBlurDownsampling)) * 0.99;

//vertical for smoothing


sum += tex2Dlod(InputSampler, float4(i.txcoord.y - 10.0*fBlurSize,
i.txcoord.x,0,fBlurDownsampling)) * 0.1;
sum += tex2Dlod(InputSampler, float4(i.txcoord.y - 6.6*fBlurSize,
i.txcoord.x,0,fBlurDownsampling)) * 0.25;
sum += tex2Dlod(InputSampler, float4(i.txcoord.y - 3.3*fBlurSize,
i.txcoord.x,0,fBlurDownsampling)) * 0.50;
sum += tex2Dlod(InputSampler, float4(i.txcoord.y - fBlurSize,
i.txcoord.x,0,fBlurDownsampling)) * 0.75;
sum += tex2Dlod(InputSampler, float4(i.txcoord.y,
i.txcoord.x,0,fBlurDownsampling)) * 1.0;
sum += tex2Dlod(InputSampler, float4(i.txcoord.y + fBlurSize,
i.txcoord.x,0,fBlurDownsampling)) * 0.75;
sum += tex2Dlod(InputSampler, float4(i.txcoord.y + 3.3*fBlurSize,
i.txcoord.x,0,fBlurDownsampling)) * 0.50;
sum += tex2Dlod(InputSampler, float4(i.txcoord.y + 6.6*fBlurSize,
i.txcoord.x,0,fBlurDownsampling)) * 0.25;
sum += tex2Dlod(InputSampler, float4(i.txcoord.y + 10.0*fBlurSize,
i.txcoord.x,0,fBlurDownsampling)) * 0.1;

#endif

#ifdef FORCECOLOR
sum = dot(sum, float3(0.3, 0.59, 0.11));
#endif
#ifdef ANAMORPHICTINTCOLOR
sum.r = sum.r * ANAMORPHICREDAMOUNT;
sum.g = sum.g * ANAMORPHICGREENAMOUNT;
sum.b = sum.b * ANAMORPHICBLUEAMOUNT;
#endif

// do some cool stuff to get bloom...


#ifdef FLAREMODE_1
float4 color = max(float4(0.0,0.0,0.0,0.0), sum-threshhold1.x);
float4 toBlend = saturate (color * fFlareIntensity1);
#else
float4 color = max(float4(0.0,0.0,0.0,0.0), sum-threshhold2.x);
float4 toBlend = saturate (color * fFlareIntensity2);
#endif

float4 smpl = 1-(1-col)*(1-toBlend);

float factor = max(smpl.x, max(smpl.y, smpl.z));


float factorM = (smpl.x + smpl.y + smpl.z)/3;
float4 shadows = paramsS;
float4 midtones = paramsM;
float4 highlights = paramsH;

float4 Color;

if(factor < 0.1) //Shadows


{
if(factor > 0.01)
{
factor = (factor + 0.09)*10;

shadows.w = shadows.x; //.w is value backup


shadows.x = ((1 - shadows.w) / 2) * factor;
shadows.x += shadows.w; //Adding backup

shadows.w = shadows.y; //.w is value backup


shadows.y = ((1 - shadows.w) / 2) * factor;
shadows.y += shadows.w; //Adding backup

shadows.w = shadows.z; //.w is value backup


shadows.z = ((1 - shadows.w) / 2) * factor;
shadows.z += shadows.w; //Adding backup
}
Color = float4(smpl.x * shadows.x, smpl.y * shadows.y, smpl.z *
shadows.z, smpl.w);
}
else if(factorM >= 0.1 && factorM <= 0.5) //Middle-tones
{
if(factorM > 0.3)
{
factorM = (factorM - 0.31)*10;

midtones.w = midtones.x; //.w is value backup


midtones.x = ((1 - midtones.w) / 2) * factorM;
midtones.x += midtones.w; //Adding backup
midtones.w = midtones.y; //.w is value backup
midtones.y = ((1 - midtones.w) / 2) * factorM;
midtones.y += midtones.w; //Adding backup

midtones.w = midtones.z; //.w is value backup


midtones.z = ((1 - midtones.w) / 2) * factorM;
midtones.z += midtones.w; //Adding backup
}
else if(factorM <= 0.3)
{
factorM = (factorM - 0.1)*10;

midtones.w = midtones.x;
midtones.x = (1 - midtones.w) - (factorM * ((1 - midtones.w) /
2));
midtones.x += midtones.w;

midtones.w = midtones.y;
midtones.y = (1 - midtones.w) - (factorM * ((1 - midtones.w) /
2));
midtones.y += midtones.w;

midtones.w = midtones.z;
midtones.z = (1 - midtones.w) - (factorM * ((1 - midtones.w) /
2));
midtones.z += midtones.w;
}

Color = float4(smpl.x * midtones.x, smpl.y * midtones.y, smpl.z *


midtones.z, smpl.w);
}
else if(factorM > 0.5) //Hightlights
{
if(factorM <= 0.8)
{
factorM = (factorM - 0.51)*10;

highlights.w = highlights.x;
highlights.x = (1 - highlights.w) - (factorM * ((1 -
highlights.w) / 2));
highlights.x += highlights.w;

highlights.w = highlights.y;
highlights.y = (1 - highlights.w) - (factorM * ((1 -
highlights.w) / 2));
highlights.y += highlights.w;

highlights.w = highlights.z;
highlights.z = (1 - highlights.w) - (factorM * ((1 -
highlights.w) / 2));
highlights.z += highlights.w;
}

Color = float4(smpl.x * highlights.x, smpl.y * highlights.y, smpl.z *


highlights.z, smpl.w);
}
else Color = smpl;
float lum = Luminance(Color.xyz);
return Color;

}
#endif

float4 CBloom (VS_OUTPUT_POST i, float2 vPos : VPOS) : COLOR


{

float4 BloomThreshold = {fBloomThreshold, 1/(1-fBloomThreshold), 5.0, 5.0};

float4 tcol = tex2D(InputSampler, i.txcoord);


float4 bloomsample = float4(0,0,0,0);

#ifdef COLORMODBLOOM
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x,
i.txcoord.y,0,BloomDownsampling)) * 0.19741;

bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -


0.94201624*BloomRadius, i.txcoord.y- 0.39906216*BloomRadius,0,BloomDownsampling)) *
0.19741;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.94558609*BloomRadius, i.txcoord.y- 0.76890725*BloomRadius,0,BloomDownsampling)) *
0.19741;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -
0.09418410*BloomRadius, i.txcoord.y- 0.92938870*BloomRadius,0,BloomDownsampling)) *
0.19741;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.34495938*BloomRadius, i.txcoord.y+ 0.29387760*BloomRadius,0,BloomDownsampling)) *
0.19741;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -
0.91588581*BloomRadius, i.txcoord.y+ 0.45771432*BloomRadius,0,BloomDownsampling)) *
0.19741;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -
0.81544232*BloomRadius, i.txcoord.y- 0.87912464*BloomRadius,0,BloomDownsampling)) *
0.19741;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -
0.38277543*BloomRadius, i.txcoord.y+ 0.27676845*BloomRadius,0,BloomDownsampling)) *
0.19741;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.97484398*BloomRadius, i.txcoord.y+ 0.75648379*BloomRadius,0,BloomDownsampling)) *
0.19741;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.44323325*BloomRadius, i.txcoord.y- 0.97511554*BloomRadius,0,BloomDownsampling)) *
0.19741;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.53742981*BloomRadius, i.txcoord.y- 0.47373420*BloomRadius,0,BloomDownsampling)) *
0.19741;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -
0.26496911*BloomRadius, i.txcoord.y- 0.41893023*BloomRadius,0,BloomDownsampling)) *
0.19741;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.79197514*BloomRadius, i.txcoord.y+ 0.19090188*BloomRadius,0,BloomDownsampling)) *
0.19741;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -
0.24188840*BloomRadius, i.txcoord.y+ 0.99706507*BloomRadius,0,BloomDownsampling)) *
0.19741;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -
0.81409955*BloomRadius, i.txcoord.y+ 0.91437590*BloomRadius,0,BloomDownsampling)) *
0.19741;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.19984126*BloomRadius, i.txcoord.y+ 0.78641367*BloomRadius,0,BloomDownsampling)) *
0.19741;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.14383161*BloomRadius, i.txcoord.y- 0.14100790*BloomRadius,0,BloomDownsampling)) *
0.19741;

bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -


0.94201624*BloomRadius*1.5, i.txcoord.y-
0.39906216*BloomRadius*1.5,0,BloomDownsampling)) * 0.17467;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.94558609*BloomRadius*1.5, i.txcoord.y-
0.76890725*BloomRadius*1.5,0,BloomDownsampling)) * 0.17467;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -
0.09418410*BloomRadius*1.5, i.txcoord.y-
0.92938870*BloomRadius*1.5,0,BloomDownsampling)) * 0.17467;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.34495938*BloomRadius*1.5, i.txcoord.y+
0.29387760*BloomRadius*1.5,0,BloomDownsampling)) * 0.17467;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -
0.91588581*BloomRadius*1.5, i.txcoord.y+
0.45771432*BloomRadius*1.5,0,BloomDownsampling)) * 0.17467;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -
0.81544232*BloomRadius*1.5, i.txcoord.y-
0.87912464*BloomRadius*1.5,0,BloomDownsampling)) * 0.17467;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -
0.38277543*BloomRadius*1.5, i.txcoord.y+
0.27676845*BloomRadius*1.5,0,BloomDownsampling)) * 0.17467;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.97484398*BloomRadius*1.5, i.txcoord.y+
0.75648379*BloomRadius*1.5,0,BloomDownsampling)) * 0.17467;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.44323325*BloomRadius*1.5, i.txcoord.y-
0.97511554*BloomRadius*1.5,0,BloomDownsampling)) * 0.17467;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.53742981*BloomRadius*1.5, i.txcoord.y-
0.47373420*BloomRadius*1.5,0,BloomDownsampling)) * 0.17467;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -
0.26496911*BloomRadius*1.5, i.txcoord.y-
0.41893023*BloomRadius*1.5,0,BloomDownsampling)) * 0.17467;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.79197514*BloomRadius*1.5, i.txcoord.y+
0.19090188*BloomRadius*1.5,0,BloomDownsampling)) * 0.17467;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -
0.24188840*BloomRadius*1.5, i.txcoord.y+
0.99706507*BloomRadius*1.5,0,BloomDownsampling)) * 0.17467;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -
0.81409955*BloomRadius*1.5, i.txcoord.y+
0.91437590*BloomRadius*1.5,0,BloomDownsampling)) * 0.17467;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.19984126*BloomRadius*1.5, i.txcoord.y+
0.78641367*BloomRadius*1.5,0,BloomDownsampling)) * 0.17467;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.14383161*BloomRadius*1.5, i.txcoord.y-
0.14100790*BloomRadius*1.5,0,BloomDownsampling)) * 0.17467;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -
0.94201624*BloomRadius*2.0, i.txcoord.y-
0.39906216*BloomRadius*2.0,0,BloomDownsampling)) * 0.12098;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.94558609*BloomRadius*2.0, i.txcoord.y-
0.76890725*BloomRadius*2.0,0,BloomDownsampling)) * 0.12098;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -
0.09418410*BloomRadius*2.0, i.txcoord.y-
0.92938870*BloomRadius*2.0,0,BloomDownsampling)) * 0.12098;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.34495938*BloomRadius*2.0, i.txcoord.y+
0.29387760*BloomRadius*2.0,0,BloomDownsampling)) * 0.12098;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -
0.91588581*BloomRadius*2.0, i.txcoord.y+
0.45771432*BloomRadius*2.0,0,BloomDownsampling)) * 0.12098;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -
0.81544232*BloomRadius*2.0, i.txcoord.y-
0.87912464*BloomRadius*2.0,0,BloomDownsampling)) * 0.12098;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -
0.38277543*BloomRadius*2.0, i.txcoord.y+
0.27676845*BloomRadius*2.0,0,BloomDownsampling)) * 0.12098;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.97484398*BloomRadius*2.0, i.txcoord.y+
0.75648379*BloomRadius*2.0,0,BloomDownsampling)) * 0.12098;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.44323325*BloomRadius*2.0, i.txcoord.y-
0.97511554*BloomRadius*2.0,0,BloomDownsampling)) * 0.12098;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.53742981*BloomRadius*2.0, i.txcoord.y-
0.47373420*BloomRadius*2.0,0,BloomDownsampling)) * 0.12098;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -
0.26496911*BloomRadius*2.0, i.txcoord.y-
0.41893023*BloomRadius*2.0,0,BloomDownsampling)) * 0.12098;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.79197514*BloomRadius*2.0, i.txcoord.y+
0.19090188*BloomRadius*2.0,0,BloomDownsampling)) * 0.12098;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -
0.24188840*BloomRadius*2.0, i.txcoord.y+
0.99706507*BloomRadius*2.0,0,BloomDownsampling)) * 0.12098;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -
0.81409955*BloomRadius*2.0, i.txcoord.y+
0.91437590*BloomRadius*2.0,0,BloomDownsampling)) * 0.12098;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.19984126*BloomRadius*2.0, i.txcoord.y+
0.78641367*BloomRadius*2.0,0,BloomDownsampling)) * 0.12098;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.14383161*BloomRadius*2.0, i.txcoord.y-
0.14100790*BloomRadius*2.0,0,BloomDownsampling)) * 0.12098;

bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -


0.94201624*BloomRadius*2.5, i.txcoord.y-
0.39906216*BloomRadius*2.5,0,BloomDownsampling)) * 0.06559;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.94558609*BloomRadius*2.5, i.txcoord.y-
0.76890725*BloomRadius*2.5,0,BloomDownsampling)) * 0.06559;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -
0.09418410*BloomRadius*2.5, i.txcoord.y-
0.92938870*BloomRadius*2.5,0,BloomDownsampling)) * 0.06559;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.34495938*BloomRadius*2.5, i.txcoord.y+
0.29387760*BloomRadius*2.5,0,BloomDownsampling)) * 0.06559;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -
0.91588581*BloomRadius*2.5, i.txcoord.y+
0.45771432*BloomRadius*2.5,0,BloomDownsampling)) * 0.06559;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -
0.81544232*BloomRadius*2.5, i.txcoord.y-
0.87912464*BloomRadius*2.5,0,BloomDownsampling)) * 0.06559;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -
0.38277543*BloomRadius*2.5, i.txcoord.y+
0.27676845*BloomRadius*2.5,0,BloomDownsampling)) * 0.06559;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.97484398*BloomRadius*2.5, i.txcoord.y+
0.75648379*BloomRadius*2.5,0,BloomDownsampling)) * 0.06559;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.44323325*BloomRadius*2.5, i.txcoord.y-
0.97511554*BloomRadius*2.5,0,BloomDownsampling)) * 0.06559;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.53742981*BloomRadius*2.5, i.txcoord.y-
0.47373420*BloomRadius*2.5,0,BloomDownsampling)) * 0.06559;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -
0.26496911*BloomRadius*2.5, i.txcoord.y-
0.41893023*BloomRadius*2.5,0,BloomDownsampling)) * 0.06559;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.79197514*BloomRadius*2.5, i.txcoord.y+
0.19090188*BloomRadius*2.5,0,BloomDownsampling)) * 0.06559;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -
0.24188840*BloomRadius*2.5, i.txcoord.y+
0.99706507*BloomRadius*2.5,0,BloomDownsampling)) * 0.06559;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -
0.81409955*BloomRadius*2.5, i.txcoord.y+
0.91437590*BloomRadius*2.5,0,BloomDownsampling)) * 0.06559;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.19984126*BloomRadius*2.5, i.txcoord.y+
0.78641367*BloomRadius*2.5,0,BloomDownsampling)) * 0.06559;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.14383161*BloomRadius*2.5, i.txcoord.y-
0.14100790*BloomRadius*2.5,0,BloomDownsampling)) * 0.06559;

bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -


0.94201624*BloomRadius*3.0, i.txcoord.y-
0.39906216*BloomRadius*3.0,0,BloomDownsampling)) * 0.02783;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.94558609*BloomRadius*3.0, i.txcoord.y-
0.76890725*BloomRadius*3.0,0,BloomDownsampling)) * 0.02783;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -
0.09418410*BloomRadius*3.0, i.txcoord.y-
0.92938870*BloomRadius*3.0,0,BloomDownsampling)) * 0.02783;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.34495938*BloomRadius*3.0, i.txcoord.y+
0.29387760*BloomRadius*3.0,0,BloomDownsampling)) * 0.02783;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -
0.91588581*BloomRadius*3.0, i.txcoord.y+
0.45771432*BloomRadius*3.0,0,BloomDownsampling)) * 0.02783;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -
0.81544232*BloomRadius*3.0, i.txcoord.y-
0.87912464*BloomRadius*3.0,0,BloomDownsampling)) * 0.02783;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -
0.38277543*BloomRadius*3.0, i.txcoord.y+
0.27676845*BloomRadius*3.0,0,BloomDownsampling)) * 0.02783;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.97484398*BloomRadius*3.0, i.txcoord.y+
0.75648379*BloomRadius*3.0,0,BloomDownsampling)) * 0.02783;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.44323325*BloomRadius*3.0, i.txcoord.y-
0.97511554*BloomRadius*3.0,0,BloomDownsampling)) * 0.02783;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.53742981*BloomRadius*3.0, i.txcoord.y-
0.47373420*BloomRadius*3.0,0,BloomDownsampling)) * 0.02783;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -
0.26496911*BloomRadius*3.0, i.txcoord.y-
0.41893023*BloomRadius*3.0,0,BloomDownsampling)) * 0.02783;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.79197514*BloomRadius*3.0, i.txcoord.y+
0.19090188*BloomRadius*3.0,0,BloomDownsampling)) * 0.02783;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -
0.24188840*BloomRadius*3.0, i.txcoord.y+
0.99706507*BloomRadius*3.0,0,BloomDownsampling)) * 0.02783;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -
0.81409955*BloomRadius*3.0, i.txcoord.y+
0.91437590*BloomRadius*3.0,0,BloomDownsampling)) * 0.02783;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.19984126*BloomRadius*3.0, i.txcoord.y+
0.78641367*BloomRadius*3.0,0,BloomDownsampling)) * 0.02783;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.14383161*BloomRadius*3.0, i.txcoord.y-
0.14100790*BloomRadius*3.0,0,BloomDownsampling)) * 0.02783;

bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -


0.94201624*BloomRadius*3.5, i.txcoord.y-
0.39906216*BloomRadius*3.5,0,BloomDownsampling)) * 0.01222;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.94558609*BloomRadius*3.5, i.txcoord.y-
0.76890725*BloomRadius*3.5,0,BloomDownsampling)) * 0.01222;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -
0.09418410*BloomRadius*3.5, i.txcoord.y-
0.92938870*BloomRadius*3.5,0,BloomDownsampling)) * 0.01222;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.34495938*BloomRadius*3.5, i.txcoord.y+
0.29387760*BloomRadius*3.5,0,BloomDownsampling)) * 0.01222;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -
0.91588581*BloomRadius*3.5, i.txcoord.y+
0.45771432*BloomRadius*3.5,0,BloomDownsampling)) * 0.01222;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -
0.81544232*BloomRadius*3.5, i.txcoord.y-
0.87912464*BloomRadius*3.5,0,BloomDownsampling)) * 0.01222;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -
0.38277543*BloomRadius*3.5, i.txcoord.y+
0.27676845*BloomRadius*3.5,0,BloomDownsampling)) * 0.01222;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.97484398*BloomRadius*3.5, i.txcoord.y+
0.75648379*BloomRadius*3.5,0,BloomDownsampling)) * 0.01222;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.44323325*BloomRadius*3.5, i.txcoord.y-
0.97511554*BloomRadius*3.5,0,BloomDownsampling)) * 0.01222;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.53742981*BloomRadius*3.5, i.txcoord.y-
0.47373420*BloomRadius*3.5,0,BloomDownsampling)) * 0.01222;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -
0.26496911*BloomRadius*3.5, i.txcoord.y-
0.41893023*BloomRadius*3.5,0,BloomDownsampling)) * 0.01222;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.79197514*BloomRadius*3.5, i.txcoord.y+
0.19090188*BloomRadius*3.5,0,BloomDownsampling)) * 0.01222;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -
0.24188840*BloomRadius*3.5, i.txcoord.y+
0.99706507*BloomRadius*3.5,0,BloomDownsampling)) * 0.01222;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x -
0.81409955*BloomRadius*3.5, i.txcoord.y+
0.91437590*BloomRadius*3.5,0,BloomDownsampling)) * 0.01222;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.19984126*BloomRadius*3.5, i.txcoord.y+
0.78641367*BloomRadius*3.5,0,BloomDownsampling)) * 0.01222;
bloomsample += tex2Dlod(InputSampler, float4(i.txcoord.x +
0.14383161*BloomRadius*3.5, i.txcoord.y-
0.14100790*BloomRadius*3.5,0,BloomDownsampling)) * 0.01222;

#endif

#ifndef COLORBLOOM
bloomsample = dot(bloomsample, float3(0.3, 0.59, 0.11));
#endif

bloomsample = bloomsample * BloomCurve;

bloomsample =max(1.0,0.0);

float4 tcol2 = max(float4(0.0,0.0,0.0,0.0), bloomsample-BloomThreshold.x);


float4 toBlend = saturate (tcol2 * fBloomIntensity);

float4 smpl = 1-(1-tcol)*(1-toBlend);

float4 Color;
Color = smpl;
return Color;
}

#ifdef DOF
float4 PS_ProcessDoFBokeh(VS_OUTPUT_POST IN, float2 vPos : VPOS) : COLOR
{
float depth = linearize(tex2D(SamplerDepth,IN.txcoord.xy).x);

float fDepth = focalDepth;

if (autofocus)
{
fDepth = linearize(tex2D(SamplerDepth,focus).x);
}
float blur = 0.0;
if (manualdof)
{
float a = depth-fDepth; //focal plane
float b = (a-fdofstart)/fdofdist; //far DoF
float c = (-a-ndofstart)/ndofdist; //near Dof
blur = (a>0.0)?b:c;
}
else
{
float f = focalLength; //focal length in mm
float d = fDepth*1000.0; //focal plane in mm
float o = depth*1000.0; //depth in mm

float a = (o*f)/(o-f);
float b = (d*f)/(d-f);
float c = (d-f)/(d*fstop*CoC);

blur = abs(a-b)*c;
}
blur = saturate(blur);
float2 noise = rand(IN.txcoord.xy)*namount*blur;

float w = (1.0/screenRes.x)*blur*maxblur+noise.x;
float h = (1.0/screenRes.y)*blur*maxblur+noise.y;

float4 col = float4(0,0,0,1);

if(blur < 0.05) //some optimization thingy


{
col = tex2D(InputSampler, IN.txcoord.xy);
}
else
{
col = tex2D(InputSampler, IN.txcoord.xy);
float s = 1.0;
int ringsamples;
for (int i = 1; i <= rings; i += 1)
{
ringsamples = i * samples;
for (int j = 0 ; j < ringsamples ; j += 1)
{
float step = PI*2.0 / ringsamples;
float pw = cos(j*step)*i;
float ph = sin(j*step)*i;
float p = 1.0;
if (pentagon)
{
p = penta(float2(pw,ph));
}
col.xyz += colorDof(IN.txcoord.xy + float2(pw*w,ph*h),blur).xyz;

s += 1.0*lerp(1.0,i/rings,bias)*p;
}
}
col = col/s; //divide by sample count
}
if (vignetting)
{
col *= vignette(IN.txcoord.xy);
}
#ifdef BORDER_DOF
float2 distancefromcenter = abs(IN.txcoord.xy - 0.5);
bool2 screen_border = step(0.5 - pixel,distancefromcenter);

col.xyz = (!dot(screen_border, 1.0)) ? col.xyz : 0.0;


#endif
return col;
}
#endif

#ifdef CHROMATICABBERATION
float4 PS_PostProcessChroma(VS_OUTPUT_POST IN, float2 vPos : VPOS) : COLOR
{

float4 coord=0.0;

coord.xy=IN.txcoord.xy;
coord.w=0.0;

float3 eta =
float3(1.0+ChromaticAmount*0.9,1.0+ChromaticAmount*0.6,1.0+ChromaticAmount*0.3);
float2 center;
center.x = coord.x-0.5;
center.y = coord.y-0.5;
float LensZoom = 1.0/LensSize;

float r2 = (IN.txcoord.x-0.5) * (IN.txcoord.x-0.5) + (IN.txcoord.y-0.5) *


(IN.txcoord.y-0.5);
float f = 0;

if( LensDistortionCubic == 0.0){


f = 1 + r2 * LensDistortion;
}else{
f = 1 + r2 * (LensDistortion + LensDistortionCubic * sqrt(r2));
};

float x = f*LensZoom*(coord.x-0.5)+0.5;
float y = f*LensZoom*(coord.y-0.5)+0.5;
float2 rCoords = (f*eta.r)*LensZoom*(center.xy*0.5)+0.5;
float2 gCoords = (f*eta.g)*LensZoom*(center.xy*0.5)+0.5;
float2 bCoords = (f*eta.b)*LensZoom*(center.xy*0.5)+0.5;

//float3 inputDistord = tex2D(InputSampler,float2(x,y));


float4 inputDistord = float4(tex2D(InputSampler,rCoords).r ,
tex2D(InputSampler,gCoords).g ,tex2D(InputSampler,bCoords).b,
tex2D(InputSampler,float2(x,y)).a);
return float4(inputDistord.r,inputDistord.g,inputDistord.b,1);
}
#endif

float ScreenSizeFXAA = 1920;; //width of the display resolution (1920 f.e.)


float ScreenScaleYFXAA = 1.333; //screen proportions (1.333 for 1920/1080)

float4 FxaaPixelShader(VS_OUTPUT_POST IN, float2 vPos : VPOS) : COLOR


{

#define FxaaTexTop(t, p) tex2Dlod(t, float4(p, 0.0, 0.0))


#define FxaaTexOff(t, p, o, r) tex2Dlod(t, float4(p + (o * r), 0, 0))

float2 pos = IN.txcoord.xy;

float2 rcpFrame = float2(1/ScreenSizeFXAA, ScreenScaleYFXAA/ScreenSizeFXAA);


float4 rcpFrameOpt = float4(2/ScreenSizeFXAA, 2*ScreenScaleYFXAA/ScreenSizeFXAA,
0.5/ScreenSizeFXAA, 0.5*ScreenScaleYFXAA/ScreenSizeFXAA);

float lumaN = dot(FxaaTexOff(InputSampler, pos.xy, float2(0, -1), rcpFrame.xy).xyz,


float3(0.299, 0.587, 0.114));
float lumaW = dot(FxaaTexOff(InputSampler, pos.xy, float2(-1, 0), rcpFrame.xy).xyz,
float3(0.299, 0.587, 0.114));

float4 rgbyM;
rgbyM.xyz = FxaaTexTop(InputSampler, pos.xy).xyz;
rgbyM.w = dot(rgbyM.xyz, float3(0.299, 0.587, 0.114));
float lumaE = dot(FxaaTexOff(InputSampler, pos.xy, float2( 1, 0), rcpFrame.xy).xyz,
float3(0.299, 0.587, 0.114));
float lumaS = dot(FxaaTexOff(InputSampler, pos.xy, float2( 0, 1), rcpFrame.xy).xyz,
float3(0.299, 0.587, 0.114));
float lumaM = rgbyM.w;

float rangeMin = min(lumaM, min(min(lumaN, lumaW), min(lumaS, lumaE)));


float rangeMax = max(lumaM, max(max(lumaN, lumaW), max(lumaS, lumaE)));
float range = rangeMax - rangeMin;

if(range < max(FXAA_QUALITY__EDGE_THRESHOLD_MIN, rangeMax *


FXAA_QUALITY__EDGE_THRESHOLD)) return rgbyM;

float lumaNW = dot(FxaaTexOff(InputSampler, pos.xy, float2(-1,-1),


rcpFrame.xy).xyz, float3(0.299, 0.587, 0.114));
float lumaNE = dot(FxaaTexOff(InputSampler, pos.xy, float2( 1,-1),
rcpFrame.xy).xyz, float3(0.299, 0.587, 0.114));
float lumaSW = dot(FxaaTexOff(InputSampler, pos.xy, float2(-1, 1),
rcpFrame.xy).xyz, float3(0.299, 0.587, 0.114));
float lumaSE = dot(FxaaTexOff(InputSampler, pos.xy, float2( 1, 1),
rcpFrame.xy).xyz, float3(0.299, 0.587, 0.114));

float lumaL = (lumaN + lumaW + lumaE + lumaS) * 0.25;


float rangeL = abs(lumaL - lumaM);
float blendL = saturate((rangeL / range) - FXAA_QUALITY__SUBPIX_TRIM) *
FXAA_QUALITY__SUBPIX_TRIM_SCALE;
blendL = min(FXAA_QUALITY__SUBPIX_CAP, blendL);

float edgeVert = abs(lumaNW + (-2.0 * lumaN) + lumaNE) + 2.0 * abs(lumaW + (-2.0 *


lumaM) + lumaE ) + abs(lumaSW + (-2.0 * lumaS) + lumaSE);
float edgeHorz = abs(lumaNW + (-2.0 * lumaW) + lumaSW) + 2.0 * abs(lumaN + (-
2.0 * lumaM) + lumaS ) + abs(lumaNE + (-2.0 * lumaE) + lumaSE);
bool horzSpan = edgeHorz >= edgeVert;

float lengthSign = horzSpan ? -rcpFrame.y : -rcpFrame.x;


if(!horzSpan) lumaN = lumaW;
if(!horzSpan) lumaS = lumaE;
float gradientN = abs(lumaN - lumaM);
float gradientS = abs(lumaS - lumaM);
lumaN = (lumaN + lumaM) * 0.5;
lumaS = (lumaS + lumaM) * 0.5;

bool pairN = gradientN >= gradientS;


if(!pairN) lumaN = lumaS;
if(!pairN) gradientN = gradientS;
if(!pairN) lengthSign *= -1.0;
float2 posN;
posN.x = pos.x + (horzSpan ? 0.0 : lengthSign * 0.5);
posN.y = pos.y + (horzSpan ? lengthSign * 0.5 : 0.0);

gradientN *= FXAA_SEARCH_THRESHOLD;

float2 posP = posN;


float2 offNP = horzSpan ?
float2(rcpFrame.x, 0.0) :
float2(0.0f, rcpFrame.y);
float lumaEndN;
float lumaEndP;
bool doneN = false;
bool doneP = false;
posN += offNP * (-1.5);
posP += offNP * ( 1.5);
for(int i = 0; i < FXAA_SEARCH_STEPS; i++)
{
lumaEndN = dot(FxaaTexTop(InputSampler, posN.xy).xyz, float3(0.299, 0.587, 0.114));
lumaEndP = dot(FxaaTexTop(InputSampler, posP.xy).xyz, float3(0.299, 0.587, 0.114));
bool doneN2 = abs(lumaEndN - lumaN) >= gradientN;
bool doneP2 = abs(lumaEndP - lumaN) >= gradientN;
if(doneN2 && !doneN) posN += offNP;
if(doneP2 && !doneP) posP -= offNP;
if(doneN2 && doneP2) break;
doneN = doneN2;
doneP = doneP2;
if(!doneN) posN -= offNP * 2.0;
if(!doneP) posP += offNP * 2.0;
}

float dstN = horzSpan ? pos.x - posN.x : pos.y - posN.y;


float dstP = horzSpan ? posP.x - pos.x : posP.y - pos.y;

bool directionN = dstN < dstP;


lumaEndN = directionN ? lumaEndN : lumaEndP;

if(((lumaM - lumaN) < 0.0) == ((lumaEndN - lumaN) < 0.0))


lengthSign = 0.0;

float spanLength = (dstP + dstN);


dstN = directionN ? dstN : dstP;
float subPixelOffset = 0.5 + (dstN * (-1.0/spanLength));
subPixelOffset += blendL * (1.0/8.0);
subPixelOffset *= lengthSign;
float3 rgbF = FxaaTexTop(InputSampler, float2(pos.x + (horzSpan ? 0.0 :
subPixelOffset), pos.y + (horzSpan ? subPixelOffset : 0.0))).xyz;

#if (FXAA_LINEAR == 1)
lumaL *= lumaL;
#endif
float lumaF = dot(rgbF, float3(0.299, 0.587, 0.114)) + (1.0/(65536.0*256.0));
float lumaB = lerp(lumaF, lumaL, blendL);
float scale = min(4.0, lumaB/lumaF);
rgbF *= scale;

return float4(rgbF, lumaM);


}

#ifdef NOISE
float4 PS_ProcessPass_ImageGrain(VS_OUTPUT_POST IN, float2 vPos : VPOS) : COLOR
{
float4 res;
float2 coord = IN.txcoord.xy;
res.xyz = tex2D(InputSampler, coord.xy).xyz;
res.xyz += tex2D(SamplerNoise, coord.xy * 1024).xyz * Grain(float3(coord.xy,
SEED));
res.a = 1.0;
return res;
}
#endif
#ifdef MATSO_FLARE
float3 BrightPass(float2 tex)
{
float3 couleur = tex2D(InputSampler, tex).rgb;
float3 bC = max(couleur - float3(fFlareLuminance, fFlareLuminance,
fFlareLuminance), 0.0);
float bright = dot(bC, 1.0);
bright = smoothstep(0.0f, 0.5, bright);
return lerp(0.0, couleur, bright);
}

float3 AnamorphicSample(int axis, float2 tex, float blur)


{
tex = 2.0 * tex - 1.0;
if (!axis) tex.x /= -blur;
else tex.y /= -blur;
tex = 0.5 * tex + 0.5;
return BrightPass(tex);
}

float4 PS_ProcessPass_Anamorphic(VS_OUTPUT_POST IN, float2 vPos : VPOS, uniform int


axis) : COLOR
{
float4 res;
float2 coord = IN.txcoord.xy;

#ifdef fFlareHorizontal
#define fFlareAxis 0
#endif
#ifdef fFlareVertical
#define fFlareAxis 90
#endif

float3 anamFlare = AnamorphicSample(axis, coord.xy, fFlareBlur) * fFlareTint;


#ifdef fFlareHorizontal
anamFlare += AnamorphicSample(axis, coord.xy+float2(0, 4)*FlareRadius,
fFlareBlur) * fFlareTint* 0.30;
anamFlare += AnamorphicSample(axis, coord.xy+float2(0, 3)*FlareRadius,
fFlareBlur) * fFlareTint* 0.54;
anamFlare += AnamorphicSample(axis, coord.xy+float2(0, 2)*FlareRadius,
fFlareBlur) * fFlareTint* 0.72;
anamFlare += AnamorphicSample(axis, coord.xy+float2(0, 1)*FlareRadius,
fFlareBlur) * fFlareTint* 0.90;
anamFlare += AnamorphicSample(axis, coord.xy+float2(0, -1)*FlareRadius,
fFlareBlur) * fFlareTint* 0.90;
anamFlare += AnamorphicSample(axis, coord.xy+float2(0, -2)*FlareRadius,
fFlareBlur) * fFlareTint* 0.72;
anamFlare += AnamorphicSample(axis, coord.xy+float2(0, -3)*FlareRadius,
fFlareBlur) * fFlareTint* 0.54;
anamFlare += AnamorphicSample(axis, coord.xy+float2(0, -4)*FlareRadius,
fFlareBlur) * fFlareTint* 0.30;
#endif
#ifdef fFlareVertical
anamFlare += AnamorphicSample(axis, coord.xy+float2(4, 0)*FlareRadius,
fFlareBlur) * fFlareTint* 0.30;
anamFlare += AnamorphicSample(axis, coord.xy+float2(3, 0)*FlareRadius,
fFlareBlur) * fFlareTint* 0.54;
anamFlare += AnamorphicSample(axis, coord.xy+float2(2, 0)*FlareRadius,
fFlareBlur) * fFlareTint* 0.72;
anamFlare += AnamorphicSample(axis, coord.xy+float2(1, 0)*FlareRadius,
fFlareBlur) * fFlareTint* 0.90;
anamFlare += AnamorphicSample(axis, coord.xy+float2(1, 0)*FlareRadius,
fFlareBlur) * fFlareTint* 0.90;
anamFlare += AnamorphicSample(axis, coord.xy+float2(2, 0)*FlareRadius,
fFlareBlur) * fFlareTint* 0.72;
anamFlare += AnamorphicSample(axis, coord.xy+float2(3, 0)*FlareRadius,
fFlareBlur) * fFlareTint* 0.54;
anamFlare += AnamorphicSample(axis, coord.xy+float2(4, 0)*FlareRadius,
fFlareBlur) * fFlareTint* 0.30;
#endif

res.rgb = anamFlare * fFlareIntensity;


res.a = 1.0;
return res;
}
#endif
//---------------------------------------------------------------------------------
-----
// Compiler
//---------------------------------------------------------------------------------
-----
technique PostProcess
{
pass P0
{
VertexShader = compile vs_3_0 VS_PostProcess();
PixelShader = compile ps_3_0 main();
}
#ifdef LIGHTSCATTERING
pass P1
{
VertexShader = compile vs_3_0 VS_PostProcess();
PixelShader = compile ps_3_0 PS_ProcessSunShafts();
AlphaBlendEnable=True;
SrcBlend = One;
DestBlend = One;
}
#endif
#ifdef MATSO_FLARE
pass P2
{
AlphaBlendEnable = true;
SrcBlend = One;
DestBlend = One;

PixelShader = compile ps_3_0 PS_ProcessPass_Anamorphic(fFlareAxis);


}
#endif
}

technique PostProcess2
{
pass P0
{
VertexShader = compile vs_3_0 VS_PostProcess();
PixelShader = compile ps_3_0 FxaaPixelShader();

FogEnable=FALSE;
ALPHATESTENABLE=FALSE;
SEPARATEALPHABLENDENABLE=FALSE;
AlphaBlendEnable=FALSE;
FogEnable=FALSE;
SRGBWRITEENABLE=FALSE;
}
#ifdef CHROMATICABBERATION
pass P1
{

VertexShader = compile vs_3_0 VS_PostProcess();


PixelShader = compile ps_3_0 PS_PostProcessChroma();

DitherEnable=FALSE;
ZEnable=FALSE;
CullMode=NONE;
ALPHATESTENABLE=FALSE;
SEPARATEALPHABLENDENABLE=FALSE;
AlphaBlendEnable=FALSE;
StencilEnable=FALSE;
FogEnable=FALSE;
SRGBWRITEENABLE=FALSE;
}
#endif
}

technique PostProcess3
{
pass P0
{
VertexShader = compile vs_3_0 VS_PostProcess();
PixelShader = compile ps_3_0 FxaaPixelShader();

FogEnable=FALSE;
ALPHATESTENABLE=FALSE;
SEPARATEALPHABLENDENABLE=FALSE;
AlphaBlendEnable=FALSE;
FogEnable=FALSE;
SRGBWRITEENABLE=FALSE;
}
}

technique PostProcess4
{
pass P0
{
VertexShader = compile vs_3_0 VS_PostProcess();
PixelShader = compile ps_3_0 FxaaPixelShader();

FogEnable=FALSE;
ALPHATESTENABLE=FALSE;
SEPARATEALPHABLENDENABLE=FALSE;
AlphaBlendEnable=FALSE;
FogEnable=FALSE;
SRGBWRITEENABLE=FALSE;
}
}

technique PostProcess5
{
pass P0
{
VertexShader = compile vs_3_0 VS_PostProcess();
PixelShader = compile ps_3_0 FxaaPixelShader();

FogEnable=FALSE;
ALPHATESTENABLE=FALSE;
SEPARATEALPHABLENDENABLE=FALSE;
AlphaBlendEnable=FALSE;
FogEnable=FALSE;
SRGBWRITEENABLE=FALSE;
}
#ifdef NOISE
pass P1
{

VertexShader = compile vs_3_0 VS_PostProcess();


PixelShader = compile ps_3_0 PS_ProcessPass_ImageGrain();

DitherEnable=FALSE;
ZEnable=FALSE;
CullMode=NONE;
ALPHATESTENABLE=FALSE;
SEPARATEALPHABLENDENABLE=FALSE;
AlphaBlendEnable=FALSE;
StencilEnable=FALSE;
FogEnable=FALSE;
SRGBWRITEENABLE=FALSE;
}
#endif
}

technique PostProcess6
{
pass P0
{
VertexShader = compile vs_3_0 VS_PostProcess();
PixelShader = compile ps_3_0 CBloom();
}
}

#ifdef ANAMORPHICFLARE
technique PostProcess7
{
pass P0
{
VertexShader = compile vs_3_0 VS_PostProcess();
PixelShader = compile ps_3_0 CCShadow();
}
}
#endif

#ifdef DOF
#ifdef ANAMORPHICFLARE
technique PostProcess8
#else
technique PostProcess7
#endif
{
pass P0
{
VertexShader = compile vs_3_0 VS_PostProcess();
PixelShader = compile ps_3_0 PS_ProcessDoFBokeh();
CullMode=NONE;
}

}
#endif

You might also like