Welcome, Guest.
Username: Password: Remember me

TOPIC: 2x same shader/shader to brighten dark.

2x same shader/shader to brighten dark. 1 year 4 months ago #1

Hi

Im experimenting with Reshade in some unconventional ways.
With old games I find it Can look quite good using small amounts of
very low threshold CFX gaussbloom while reducing the gamma with SFX
liftgammagain and sharpening with SFX lumasharpen etc, so that the bloom takes over
some brightening. I have also used the GemFX bloom for some low threshold
colored bloom but that bloom doesn't go low enough in threshold to brighten
up the shadows a little.

So i was wondering if one could use the gaussbloom two times
at the same time. One for very low threshold 0,015. And then
the second time for higher threshold.
I have used many many hours trying to install the extra Gauss by myself,
have also tried to install another external gaussbloom meant for Sweetfx
with no luck. Is it possible?

I can brighten the darkness after reducing liftgammagain "gain xyz"
with liftgammagain "lift xyz" but then the blacks become completely gray
like raising brightness to much. Is there a shader that lighten darks
without graying out the black level? That may raise shadow contrast insted of
brightness. The low low threshold gaussbloom does that relatively good but I
need it as much for highlights.

I have experimented with stuff like this for so many days and learnt a lot.
But I now think I need some help.



So what im asking is, is it possible to use two CFX gaussblooms at once,
and how do I install so that both show up in Mediator?

Is there another shader out there such as liftgammagain that maybe has
four stages like: dark - lowgamma - highgamma - highlights. or something else?
It would be really great.

And have i maybe overlooked some shader or setting in Reshade?
Don't think so since I now have tweaked and tested for a long time.



Thanks again for Reshade and to all the great shader builders!
It's been much fun:) And thanks to anyone ho would be able to help:)
The administrator has disabled public write access.

2x same shader/shader to brighten dark. 1 year 4 months ago #2

NB; I have tried whole bunch of times to duplicate the "Gaussian" shader,
following directions in this forum and other places but I must be doing something wrong.
It sounds easy to do but I might be stupid, probably..
Last Edit: 1 year 4 months ago by Flygesoppen. Reason: replicate is not duplicate! to much stargate i guess
The administrator has disabled public write access.

2x same shader/shader to brighten dark. 1 year 4 months ago #3

Sorry for nagging you guys like this.. I'm quite obsessed about this yeahh.
I have finally made it so Gauss2 shows up in Mediator pipeline, without disappearing!! And i can actually use the Gauss2:)
But.. I cannot use both Gauss and Gauss2 together:( When we try we have this:
"E:\SPILL\Tomb Raider - Anniversary\/ReShade/CustomFX/Gaussian2.h(56, 13): error X3003: redefinition of 'random'"
I have most certainly fracked up the renaming of the gaussian2.h file internals, its so much code and I know so little:/
One does not actually know what to rename so a great lot of trying and failing has been going on.

Anybody help a poor lonesome beggar with small legs and little brain to think with?
The files internals can be posted if allowed.
Last Edit: 1 year 4 months ago by Flygesoppen. Reason: randomness
The administrator has disabled public write access.

2x same shader/shader to brighten dark. 1 year 4 months ago #4

  • crosire
  • crosire's Avatar
  • Offline
  • Posts: 2643
  • Thank you received: 1517
  1. Copy CustomFX/Gaussian.h to CustomFX/Gaussian2.h
  2. Add "#include EFFECT(CustomFX, Gaussian2)" to Pipeline.cfg
  3. Open CustomFX.def and duplicate the entire "GAUSS" section
  4. Now add a "2" to each define name in the duplicated section, open CustomFX/Gaussian2.h and replace each occurance of the old name with the new name there too (simply use the search & replace feature pretty much every editor has).

Excerpt from modified CustomFX.cfg:
////---------//
///**GAUSS**///
//---------////

...

////---------//
///**GAUSS2**///
//---------////
#define USE_GAUSS2 0 //[Gaussian] //-Gaussian Blur / Bloom / Unsharpmask

//>Gaussian Blur / Unsharpmask Settings<\\
#define Use_GaussianBlur2 1 //[0:1] //-0 = off, 1 = on. Blurs the image
#define BlurStrength2 0.13 //[0.00:1.00] //-Strength of the blur effect
#define Use_Unsharpmask2 1 //[0:1] //-0 = off, 1 = on. Sharpens the image
#define SharpStrength2 0.05 //[0.00:1.00] //-Strength of the sharpening effect
#define GaussSigma2 1 //[1|2|3|4] //-Makes the blur and sharpening radius wider. Only works when GaussQuality is set to 1 or higher.
#define GaussQuality2 1 //[0:12] //-Higher #'s = more blur passes for Blur and Unsharp Mask (Higher performance cost).

...
Excerpt from CustomFX/Gaussian2.h:
...

#if GaussSigma2 == 2
#define Gpx_size (RFX_PixelSize*2)
#elif GaussSigma2 == 3
#define Gpx_size (RFX_PixelSize*3)
#elif GaussSigma2 == 4
#define Gpx_size (RFX_PixelSize*4)
#else
#define Gpx_size (RFX_PixelSize)
#endif

...
Cheers, crosire =)
Last Edit: 1 year 4 months ago by crosire.
The administrator has disabled public write access.
The following user(s) said Thank You: Flygesoppen

2x same shader/shader to brighten dark. 1 year 4 months ago #5

I thank you for replying:)

I will go through the files again. The thing is I did just what you are suggesting.
But i guess after while I renamed to much, I renamed with the number 2 just about everything in the gaussien.h file.

So if i understand right,
I just have to rename in the Gaussian2.h file the same "code" I duplicated in the CustomFX.cfg?

And I dont have a "CustomFX.def" file anywhere, but I have a "CustomFX.undef" file.

It was wrong of me to put a 2 behind every word in the gaussian2.h right hehe
just had to try everything:)

I will try anew!
The administrator has disabled public write access.

2x same shader/shader to brighten dark. 1 year 4 months ago #6

Now i managed to do exactly what you told me, I really think I did..
It is a step forward! Now we have no disappearing settings in Mediator anymore.
No error messages when settings load in game, no error messages in log.
but the second Gauss(Gauss2) now does nothing at all. Not a tiny little change in game.

Could it be that the Gauss doesn't want to play with other Gausses?
Has combining Gausses ever been tried before?

I thank you again for your time:)
Even though I cant get everything to work out as I like, I'm definitively donating!
The administrator has disabled public write access.

2x same shader/shader to brighten dark. 1 year 4 months ago #7

If i change the line:

#define USE_GAUSS2 0 //[Gaussian] //-Gaussian Blur / Bloom / Unsharpmask

to

#define USE_GAUSS2 0 //[Gaussian2] //-Gaussian Blur / Bloom / Unsharpmask

Then the Gauss shader number 2 works.
But when I try to load the default Gauss shader on top of Gauss2, again the error messages comes to screen.
If I do it like you told me without changing to Gaussian2 :

#define USE_GAUSS2 0 //[Gaussian] //-Gaussian Blur / Bloom / Unsharpmask

Then there is no error but no joy in a second Gauss ether.

What can this be?
The administrator has disabled public write access.

2x same shader/shader to brighten dark. 1 year 4 months ago #8

  • Ganossa
  • Ganossa's Avatar
  • Offline
  • 최정장군
  • Posts: 790
  • Thank you received: 838
If you do not mind the duplicate being executed right after the original, there is a much simpler solution to this problem which you might want to try (from scratch):

1. Before the last #endif in Gaussian.h, add the following three lines
NAMESPACE_LEAVE()
#include CFX_SETTINGS_UNDEF
NAMESPACE_ENTER(CFX2)


2. After the above line, paste a copy of all the Gaussian shader #defines in CustomFX.cfg

3. After that line, past a copy of the complete code, starting from line 7 to line 1024 and you are done :)
Last Edit: 1 year 4 months ago by Ganossa.
The administrator has disabled public write access.
The following user(s) said Thank You: Flygesoppen

2x same shader/shader to brighten dark. 1 year 4 months ago #9

Thanks:)

Will it then work ass a separate shader so one could configure them separately?
And will it show up in the Mediator?

I did try it your way a couple times already but seems I cannot do anything right today.
I'm tired in the head after too much fiddling and its late,
i'm going to give it another shot tomorrow.

But if you are interested in looking over the Gaussian.h file I worked with and could tell me where I went wrong,
I would be more than grateful:) again.

The insides of Gaussian.h:
NAMESPACE_ENTER(CFX)

#include CFX_SETTINGS_DEF

#if USE_GAUSS

#if USE_Blur == 1
#define Use_GaussianBlur 1
#endif
#if USE_Sharpening == 1 
#define Use_Unsharpmask 1
#endif
#if USE_Bloom == 1
#define Use_GaussianBloom 1 
#endif

 /**
 * Copyright (C) 2012 Jorge Jimenez (). All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *    1. Redistributions of source code must retain the above copyright notice,
 *       this list of conditions and the following disclaimer.
 *
 *    2. Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * The views and conclusions contained in the software and documentation are 
 * those of the authors and should not be interpreted as representing official
 * policies, either expressed or implied, of the copyright holders.
 */

/* This is my attempt to port the the GAUSSIAN shader by Boulotaur2024 to ReShade.
   Some settings from the original are missing and I have added some other settings to achieve certain looks.
   More info can be found at 
   http://reshade.me/forum/shader-presentation/27-gaussian-blur-bloom-unsharpmask */ 

#define CoefLuma_G            float3(0.2126, 0.7152, 0.0722)      // BT.709 & sRBG luma coefficient (Monitors and HD Television)
#define sharp_strength_luma_G (CoefLuma_G * SharpStrength + 0.2)
#define sharp_clampG        0.035

uniform int random < source = "random"; min = 0; max = 10; >;

#if Use_GaussianBlur == 0 && Use_Unsharpmask == 0 
#undef GaussTexScale 
#endif 

#if Use_GaussianBloom == 0 
#undef BloomTexScale 
#endif

#if GaussTexScale == 1 
#define txsize 2 
#elif GaussTexScale == 2 
#define txsize 4 
#else 
#define txsize 1 
#endif

#if GaussSigma == 2
#define Gpx_size (RFX_PixelSize*2)
#elif GaussSigma == 3
#define Gpx_size (RFX_PixelSize*3)
#elif GaussSigma == 4
#define Gpx_size (RFX_PixelSize*4)
#else
#define Gpx_size (RFX_PixelSize)
#endif

texture GBlurTex2Dping{ Width = BUFFER_WIDTH/txsize; Height = BUFFER_HEIGHT/txsize; Format = RGBA8; };
sampler2D GBlurSamplerPing { Texture = GBlurTex2Dping; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; AddressU = Clamp; SRGBTexture = FALSE;};
#if GaussTexScale != 0
texture GBlurTex2Dpong{ Width = BUFFER_WIDTH/txsize; Height = BUFFER_HEIGHT/txsize; Format = RGBA8; };
sampler2D GBlurSamplerPong { Texture = GBlurTex2Dpong; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; AddressU = Clamp; SRGBTexture = FALSE;};
#endif

#if BloomSigma == 2
#define Bpx_size (RFX_PixelSize*2)
#elif BloomSigma == 3
#define Bpx_size (RFX_PixelSize*3)
#elif BloomSigma == 4
#define Bpx_size (RFX_PixelSize*4)
#else
#define Bpx_size (RFX_PixelSize)
#endif

#if BloomTexScale != 0
 
#if BloomTexScale == 1 
	#define Btxsize 0.5 
#elif BloomTexScale == 2 
	#define Btxsize 0.25 
#else 
	#define Btxsize 1 
#endif

texture BBlurTex2Dping{ Width = BUFFER_WIDTH*Btxsize; Height = BUFFER_HEIGHT*Btxsize; Format = RGBA8; };
texture BBlurTex2Dpong{ Width = BUFFER_WIDTH*Btxsize; Height = BUFFER_HEIGHT*Btxsize; Format = RGBA8; };
sampler2D BBlurSamplerPing { Texture = BBlurTex2Dping; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; AddressU = Clamp; SRGBTexture = FALSE;};
sampler2D BBlurSamplerPong { Texture = BBlurTex2Dpong; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; AddressU = Clamp; SRGBTexture = FALSE;};
#endif 

float4 GOriginalPixel(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
	float4 color = tex2D(RFX_backbufferColor, texcoord);
	return saturate(color);
}

float4 HGaussianBlurPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
  
	float sampleOffsets[5] = { 0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130 };
	float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
	#if GaussTexScale != 0 
	float4 color = tex2D(GBlurSamplerPing, texcoord) * sampleWeights[0];
	[loop]
	for(int i = 1; i < 5; ++i) {
		color += tex2D(GBlurSamplerPing, texcoord + float2(sampleOffsets[i] * RFX_PixelSize.x, 0.0)) * sampleWeights[i];
		color += tex2D(GBlurSamplerPing, texcoord - float2(sampleOffsets[i] * RFX_PixelSize.x, 0.0)) * sampleWeights[i]; 
	}
	#else
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int i = 1; i < 5; ++i) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(sampleOffsets[i] * RFX_PixelSize.x, 0.0)) * sampleWeights[i];
		color += tex2D(RFX_backbufferColor, texcoord - float2(sampleOffsets[i] * RFX_PixelSize.x, 0.0)) * sampleWeights[i]; 
	}
	#endif
	return color;
}

float4 VGaussianBlurPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
  
	float sampleOffsets[5] = { 0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130 };
	float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
	#if GaussTexScale != 0
	float4 color = tex2D(GBlurSamplerPong, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(GBlurSamplerPong, texcoord + float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
		color += tex2D(GBlurSamplerPong, texcoord - float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
	}
	#else
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
		color += tex2D(RFX_backbufferColor, texcoord - float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
	}
	#endif
	return color;
}

float4 V2GaussianBlurPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
  
	float sampleOffsets[5] = { 0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130 };
	float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
	#if GaussTexScale != 0
	float4 color = tex2D(GBlurSamplerPong, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(GBlurSamplerPong, texcoord + float2(0.0, sampleOffsets[j] * Gpx_size.y)) * sampleWeights[j];
		color += tex2D(GBlurSamplerPong, texcoord - float2(0.0, sampleOffsets[j] * Gpx_size.y)) * sampleWeights[j];
	}
	#else
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(0.0, sampleOffsets[j] * Gpx_size.y)) * sampleWeights[j];
		color += tex2D(RFX_backbufferColor, texcoord - float2(0.0, sampleOffsets[j] * Gpx_size.y)) * sampleWeights[j];
	}
	#endif
	return color;
}

float4 H2GaussianBlurPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
  
	float sampleOffsets[5] = { 0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130 };
	float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
	#if GaussTexScale != 0
	float4 color = tex2D(GBlurSamplerPing, texcoord) * sampleWeights[0];
	[loop]
	for(int i = 1; i < 5; ++i) {
		color += tex2D(GBlurSamplerPing, texcoord + float2(sampleOffsets[i] * Gpx_size.x, 0.0)) * sampleWeights[i];
		color += tex2D(GBlurSamplerPing, texcoord - float2(sampleOffsets[i] * Gpx_size.x, 0.0)) * sampleWeights[i]; 
	}
	#else 
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int i = 1; i < 5; ++i) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(sampleOffsets[i] * Gpx_size.x, 0.0)) * sampleWeights[i];
		color += tex2D(RFX_backbufferColor, texcoord - float2(sampleOffsets[i] * Gpx_size.x, 0.0)) * sampleWeights[i]; 
	}
	#endif
	return color;
}

float4 GaussianBlurFinalPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
  
	float sampleOffsets[5] = { 0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130 };
	float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
	#if GaussTexScale >= 1
	#if GaussQuality >= 1
	float4 color = tex2D(GBlurSamplerPong, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(GBlurSamplerPong, texcoord + float2(0.0, sampleOffsets[j] * Gpx_size.y)) * sampleWeights[j];
		color += tex2D(GBlurSamplerPong, texcoord - float2(0.0, sampleOffsets[j] * Gpx_size.y)) * sampleWeights[j];
	}
	float4 orig = tex2D(RFX_backbufferColor, texcoord); //Original Image
	#else
	float4 color = tex2D(GBlurSamplerPong, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(GBlurSamplerPong, texcoord + float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
		color += tex2D(GBlurSamplerPong, texcoord - float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
	}
	float4 orig = tex2D(RFX_backbufferColor, texcoord); //Original Image
	#endif
	#else
	#if GaussQuality >= 1
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(0.0, sampleOffsets[j] * Gpx_size.y)) * sampleWeights[j];
		color += tex2D(RFX_backbufferColor, texcoord - float2(0.0, sampleOffsets[j] * Gpx_size.y)) * sampleWeights[j];
	}
	float4 orig = tex2D(GBlurSamplerPing, texcoord); //Original Image
	#else 
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
		color += tex2D(RFX_backbufferColor, texcoord - float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
	}
	float4 orig = tex2D(GBlurSamplerPing, texcoord); //Original Image
	#endif 
	#endif
	
	#if Use_Unsharpmask == 1 // Sharpening
	float3 sharp;
		sharp = orig.rgb - color.rgb;
		float sharp_luma1 = dot(sharp, sharp_strength_luma_G);
		sharp_luma1 = clamp(sharp_luma1, -sharp_clampG, sharp_clampG);
		orig = orig + sharp_luma1;
	#endif

	#if Use_GaussianBlur == 1
		orig = lerp(orig, color, BlurStrength);
	#endif

	return saturate(orig);
}

#if Use_GaussianBloom == 1
float3 FilmicTonemap(float3 x) {
    float A = 0.15;
    float B = 0.50;
    float C = 0.10;
    float D = 0.20;
    float E = 0.02;
    float F = 0.30;
    float W = 11.2;
    return ((x*(A*x+C*B)+D*E) / (x*(A*x+B)+D*F))- E / F;
}

float3 DoToneMap(float3 color) {
	/*
    #if TONEMAP_OPERATOR == 1 //TONEMAP_LINEAR
    return exposure * color;
    #elif TONEMAP_OPERATOR == 2 //TONEMAP_EXPONENTIAL
    color = 1.0 - exp2(-exposure * color);
    return color;
    #elif TONEMAP_OPERATOR == 3 //TONEMAP_EXPONENTIAL_HSV
    color = rgb2hsv(color);
    color.b = 1.0 - exp2(-exposure * color.b);
    color = hsv2rgb(color);
    return color;
    #elif TONEMAP_OPERATOR == 5 //TONEMAP_REINHARD
    color = xyz2Yxy(rgb2xyz(color));
    float L = color.r;
    L *= exposure;
    float LL = 1 + L / (burnout * burnout);
    float L_d = L * LL / (1 + L);
    color.r = L_d;
    color = xyz2rgb(Yxy2xyz(color));
    return color;
    #else // TONEMAP_FILMIC
	*/
    color = 2.0f * FilmicTonemap(2.00 * color);
    float3 whiteScale = 1.0f / FilmicTonemap(11.2);
    color *= whiteScale;
    return color;
}

float4 GlareDetectionPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
	#if BloomTexScale != 0
	float4 color = tex2D( BBlurSamplerPong, texcoord );
	#else
	float4 color = tex2D( RFX_backbufferColor, texcoord );
	#endif
	
	#if GaussBloomWarmth == 1
	color.rgb = lerp(color.rgb,dot(color.rgb, CoefLuma_G),-0.2);
	#else
	color.rgb = lerp(color.rgb,dot(color.rgb, CoefLuma_G),0.5);
	#endif
	
	color.rgb *= float3(BloomRed,BloomGreen,BloomBlue);
	
	color.rgb *= ( 1.0f + ( color.rgb / ( GaussThreshold * GaussThreshold ) ) );
	color.rgb *= 0.1800 / ( 0.051 );
    color.rgb -= 5.0f;

    color.rgb = max( color.rgb, 0.0f );

    color.rgb /= ( GaussExposure*0.1 + color.rgb ); 
	
	color.rgb = DoToneMap(color.rgb);
	
	return color;
}

float4 HBloomBlurPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
  
	float sampleOffsets[5] = { 0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130 };
	float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
	#if BloomTexScale >= 1 
	float4 color = tex2D(BBlurSamplerPing, texcoord) * sampleWeights[0];
	[loop]
	for(int i = 1; i < 5; ++i) {
		color += tex2D(BBlurSamplerPing, texcoord + float2(sampleOffsets[i] * RFX_PixelSize.x, 0.0)) * sampleWeights[i];
		color += tex2D(BBlurSamplerPing, texcoord - float2(sampleOffsets[i] * RFX_PixelSize.x, 0.0)) * sampleWeights[i]; 
	}
	#else
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int i = 1; i < 5; ++i) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(sampleOffsets[i] * RFX_PixelSize.x, 0.0)) * sampleWeights[i];
		color += tex2D(RFX_backbufferColor, texcoord - float2(sampleOffsets[i] * RFX_PixelSize.x, 0.0)) * sampleWeights[i]; 
	}
	#endif
	return color;
}

float4 VBloomBlurPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
  
	float sampleOffsets[5] = { 0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130 };
	float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
	#if BloomTexScale != 0
	float4 color = tex2D(BBlurSamplerPong, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(BBlurSamplerPong, texcoord + float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
		color += tex2D(BBlurSamplerPong, texcoord - float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
	}
	#else
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
		color += tex2D(RFX_backbufferColor, texcoord - float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
	}
	#endif
	return color;
}

float4 V2BloomBlurPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
  
	float sampleOffsets[5] = { 0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130 };
	float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
	#if BloomTexScale >= 1
	float4 color = tex2D(BBlurSamplerPong, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(BBlurSamplerPong, texcoord + float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
		color += tex2D(BBlurSamplerPong, texcoord - float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
	}
	#else
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
		color += tex2D(RFX_backbufferColor, texcoord - float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
	}
	#endif
	return color;
}

float4 H2BloomBlurPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
  
	float sampleOffsets[5] = { 0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130 };
	float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
	#if BloomTexScale != 0
	float4 color = tex2D(BBlurSamplerPing, texcoord) * sampleWeights[0];
	[loop]
	for(int i = 1; i < 5; ++i) {
		color += tex2D(BBlurSamplerPing, texcoord + float2(sampleOffsets[i] * Bpx_size.x, 0.0)) * sampleWeights[i];
		color += tex2D(BBlurSamplerPing, texcoord - float2(sampleOffsets[i] * Bpx_size.x, 0.0)) * sampleWeights[i]; 
	}
	#else 
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int i = 1; i < 5; ++i) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(sampleOffsets[i] * Bpx_size.x, 0.0)) * sampleWeights[i];
		color += tex2D(RFX_backbufferColor, texcoord - float2(sampleOffsets[i] * Bpx_size.x, 0.0)) * sampleWeights[i]; 
	}
	#endif
	return color;
}

float4 FinalBloomPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{

	float sampleOffsets[5] = { 0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130 };
	float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
	#if BloomTexScale != 0
	#if BloomQuality >= 1
	float4 color = tex2D(BBlurSamplerPong, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(BBlurSamplerPong, texcoord + float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
		color += tex2D(BBlurSamplerPong, texcoord - float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
	}
	float4 orig = tex2D(RFX_backbufferColor, texcoord); //Original Image
	#else 
	float4 color = tex2D(BBlurSamplerPong, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(BBlurSamplerPong, texcoord + float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
		color += tex2D(BBlurSamplerPong, texcoord - float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
	}
	float4 orig = tex2D(RFX_backbufferColor, texcoord); //Original Image
	#endif
	#else
	#if BloomQuality >= 1
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
		color += tex2D(RFX_backbufferColor, texcoord - float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
	}
	float4 orig = tex2D(GBlurSamplerPing, texcoord); //Original Image
	#else
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
		color += tex2D(RFX_backbufferColor, texcoord - float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
	}
	float4 orig = tex2D(GBlurSamplerPing, texcoord); //Original Image
	#endif
	#endif
			#define BloomDebug 0
		
		#if (GaussBloomWarmth == 0)
			#if BloomDebug == 1 
			orig = (1.0 - ((1.0 - orig) * (1.0 - (pow(abs(color*2.3),2.5))*0.3)));
			#else
			//orig = lerp(orig, (1.0 - ((1.0 - orig) * (1.0 - (pow(abs(color*2.3),2.5))*0.3))), BloomStrength);
			orig = lerp(orig, (1.0 - ((0.95 - orig) * (1.05 - (pow(abs(color*2.6),2.5))*0.3))), BloomStrength);
			#endif
		#elif (GaussBloomWarmth == 1)
			#if BloomDebug == 1 
			orig = (1.0 - ((1.05 - orig) * (0.95 - (pow(abs(color*2.6),2.5))*0.3)));
			#else
			orig = lerp(orig, (1.0 - ((1.05 - orig) * (0.95 - (pow(abs(color*2.6),2.5))*0.3))), BloomStrength);
			//orig = lerp(orig, (1.0 - ((1.0 - orig) * (1.00 - (pow(abs(color*2.6),2.5))*0.3))), BloomStrength);
			#endif
		#else
			#if BloomDebug == 1 
			orig = (1.0 - ((1.0 - orig) * (1.0 - (color)))), BloomStrength);
			#else
			orig = lerp(orig, (1.0 - ((1.0 - orig) * (1.0 - (color)))), BloomStrength);  // Foggy bloom
			#endif
		#endif 
		
	return saturate(orig);
}
#endif

technique Gaussian_Tech <bool enabled = RFX_Start_Enabled; int toggle = Gaussian_ToggleKey; >
{
#if Use_Unsharpmask == 1 || Use_GaussianBlur == 1
	pass H1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = GOriginalPixel;
		RenderTarget = GBlurTex2Dping;
	}

	pass H1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = HGaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}

#if GaussQuality >= 1
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = VGaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussQuality >= 2
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussQuality >= 3	
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussQuality >= 4
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussQuality >= 5	
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussQuality >= 6	
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussQuality >= 7	
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussQuality >= 8	
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussQuality >= 9
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussQuality >= 10	
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussQuality >= 11	
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussQuality >= 12
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif
	pass VFinal
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = GaussianBlurFinalPS;
	}
#endif
#if Use_GaussianBloom == 1

	pass H1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = GOriginalPixel;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#else
		RenderTarget = GBlurTex2Dping;
		#endif
	}

	pass GD
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = GlareDetectionPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
	
	pass H1Bloom
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = HBloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
		
#if GaussBloomQuality >= 1
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = VBloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussBloomQuality >= 2
	pass V2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
	
	pass H3
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussBloomQuality >= 3
	pass V3
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
		
	pass H4
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussBloomQuality >= 4
	pass V4
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}	
	
	pass H5
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussBloomQuality >= 5	
	pass V5
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
	
	pass H6
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussBloomQuality >= 6
	pass V2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
	
	pass H3
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussBloomQuality >= 7	
	pass V2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
	
	pass H3
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussBloomQuality >= 8
	pass V2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
	
	pass H3
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussBloomQuality >= 9
	pass V2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
	
	pass H3
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussBloomQuality >= 10	
	pass V2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
	
	pass H3
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussBloomQuality >= 11	
	pass V2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
	
	pass H3
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussBloomQuality >= 12
	pass V2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
	
	pass H3
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif
	
	pass VFinal
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = FinalBloomPS;
	}
#endif
}
NAMESPACE_LEAVE()
#include CFX_SETTINGS_UNDEF
NAMESPACE_ENTER(CFX2)

#define USE_GAUSS 1 //[Gaussian] //-Gaussian Blur / Bloom / Unsharpmask

//>Gaussian Blur / Unsharpmask Settings<\\
#define Use_GaussianBlur 0 //[0:1] //-0 = off, 1 = on. Blurs the image
#define BlurStrength 0.13 //[0.00:1.00] //-Strength of the blur effect
#define Use_Unsharpmask 0 //[0:1] //-0 = off, 1 = on. Sharpens the image
#define SharpStrength 0.10 //[0.00:1.00] //-Strength of the sharpening effect
#define GaussSigma 1 //[1|2|3|4] //-Makes the blur and sharpening radius wider. Only works when GaussQuality is set to 1 or higher.
#define GaussQuality 11 //[0:12] //-Higher #'s = more blur passes for Blur and Unsharp Mask (Higher performance cost).

//>Gaussian Bloom Settings<\\
#define Use_GaussianBloom 1 //[0:1] //-0 = off, 1 = on. 
#define BloomStrength 1.00 //[0.00:1.00] //-Amount of bloom effect added to the image.
#define GaussBloomWarmth 2 //[0|1|2] //-0 = neutral, 1 = warm, 2 = hazy/foggy
#define GaussThreshold 0.300 //[0.000:1.000] //-Threshold for what is considered a bright light. Lower #'s = brighter
#define GaussExposure 43.77 //[0.00:100.00] //-Exposure of the effect. Lower #'s = brighter 
#define BloomSigma 2 //[1|2|3|4] //-Makes the bloom radius wider. Only works when BloomQuality is set to 1 or higher. 
#define BloomRed 1.00 //[0.00:2.00] //-Adds a RED tint to bloom. #'s < 1.00 add color, #'s > 1.00 remove color.
#define BloomGreen 1.00 //[0.00:2.00] //-Adds a GREEN tint to bloom. #'s < 1.00 add color, #'s > 1.00 remove color.
#define BloomBlue 1.00 //[0.00:2.00] //-Adds a BLUE tint to bloom. #'s < 1.00 add color, #'s > 1.00 remove color.
#define GaussBloomQuality 8 //[0:12] //-Higher #'s = more blur passes

//>Performance and Misc Options<\\
#define GaussTexScale 0 //[0|1|2] //-0 = Off, 1 = 1/2 Resolution, 2 = 1/4 Resolution. Reduces performance cost. Works best with Quality settings > 1.
#define BloomTexScale 0 //[0|1|2] //-0 = Off, 1 = 1/2 Resolution, 2 = 1/4 Resolution. Reduces performance cost. Works best with Quality settings > 1.
#define Gaussian_ToggleKey RFX_ToggleKey //[undef] //-
#endif

#if USE_Blur == 1
#define Use_GaussianBlur 1
#endif
#if USE_Sharpening == 1 
#define Use_Unsharpmask 1
#endif
#if USE_Bloom == 1
#define Use_GaussianBloom 1 
#endif

 /**
 * Copyright (C) 2012 Jorge Jimenez (). All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *    1. Redistributions of source code must retain the above copyright notice,
 *       this list of conditions and the following disclaimer.
 *
 *    2. Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * The views and conclusions contained in the software and documentation are 
 * those of the authors and should not be interpreted as representing official
 * policies, either expressed or implied, of the copyright holders.
 */

/* This is my attempt to port the the GAUSSIAN shader by Boulotaur2024 to ReShade.
   Some settings from the original are missing and I have added some other settings to achieve certain looks.
   More info can be found at 
   http://reshade.me/forum/shader-presentation/27-gaussian-blur-bloom-unsharpmask */ 

#define CoefLuma_G            float3(0.2126, 0.7152, 0.0722)      // BT.709 & sRBG luma coefficient (Monitors and HD Television)
#define sharp_strength_luma_G (CoefLuma_G * SharpStrength + 0.2)
#define sharp_clampG        0.035

uniform int random < source = "random"; min = 0; max = 10; >;

#if Use_GaussianBlur == 0 && Use_Unsharpmask == 0 
#undef GaussTexScale 
#endif 

#if Use_GaussianBloom == 0 
#undef BloomTexScale 
#endif

#if GaussTexScale == 1 
#define txsize 2 
#elif GaussTexScale == 2 
#define txsize 4 
#else 
#define txsize 1 
#endif

#if GaussSigma == 2
#define Gpx_size (RFX_PixelSize*2)
#elif GaussSigma == 3
#define Gpx_size (RFX_PixelSize*3)
#elif GaussSigma == 4
#define Gpx_size (RFX_PixelSize*4)
#else
#define Gpx_size (RFX_PixelSize)
#endif

texture GBlurTex2Dping{ Width = BUFFER_WIDTH/txsize; Height = BUFFER_HEIGHT/txsize; Format = RGBA8; };
sampler2D GBlurSamplerPing { Texture = GBlurTex2Dping; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; AddressU = Clamp; SRGBTexture = FALSE;};
#if GaussTexScale != 0
texture GBlurTex2Dpong{ Width = BUFFER_WIDTH/txsize; Height = BUFFER_HEIGHT/txsize; Format = RGBA8; };
sampler2D GBlurSamplerPong { Texture = GBlurTex2Dpong; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; AddressU = Clamp; SRGBTexture = FALSE;};
#endif

#if BloomSigma == 2
#define Bpx_size (RFX_PixelSize*2)
#elif BloomSigma == 3
#define Bpx_size (RFX_PixelSize*3)
#elif BloomSigma == 4
#define Bpx_size (RFX_PixelSize*4)
#else
#define Bpx_size (RFX_PixelSize)
#endif

#if BloomTexScale != 0
 
#if BloomTexScale == 1 
	#define Btxsize 0.5 
#elif BloomTexScale == 2 
	#define Btxsize 0.25 
#else 
	#define Btxsize 1 
#endif

texture BBlurTex2Dping{ Width = BUFFER_WIDTH*Btxsize; Height = BUFFER_HEIGHT*Btxsize; Format = RGBA8; };
texture BBlurTex2Dpong{ Width = BUFFER_WIDTH*Btxsize; Height = BUFFER_HEIGHT*Btxsize; Format = RGBA8; };
sampler2D BBlurSamplerPing { Texture = BBlurTex2Dping; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; AddressU = Clamp; SRGBTexture = FALSE;};
sampler2D BBlurSamplerPong { Texture = BBlurTex2Dpong; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; AddressU = Clamp; SRGBTexture = FALSE;};
#endif 

float4 GOriginalPixel(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
	float4 color = tex2D(RFX_backbufferColor, texcoord);
	return saturate(color);
}

float4 HGaussianBlurPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
  
	float sampleOffsets[5] = { 0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130 };
	float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
	#if GaussTexScale != 0 
	float4 color = tex2D(GBlurSamplerPing, texcoord) * sampleWeights[0];
	[loop]
	for(int i = 1; i < 5; ++i) {
		color += tex2D(GBlurSamplerPing, texcoord + float2(sampleOffsets[i] * RFX_PixelSize.x, 0.0)) * sampleWeights[i];
		color += tex2D(GBlurSamplerPing, texcoord - float2(sampleOffsets[i] * RFX_PixelSize.x, 0.0)) * sampleWeights[i]; 
	}
	#else
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int i = 1; i < 5; ++i) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(sampleOffsets[i] * RFX_PixelSize.x, 0.0)) * sampleWeights[i];
		color += tex2D(RFX_backbufferColor, texcoord - float2(sampleOffsets[i] * RFX_PixelSize.x, 0.0)) * sampleWeights[i]; 
	}
	#endif
	return color;
}

float4 VGaussianBlurPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
  
	float sampleOffsets[5] = { 0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130 };
	float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
	#if GaussTexScale != 0
	float4 color = tex2D(GBlurSamplerPong, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(GBlurSamplerPong, texcoord + float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
		color += tex2D(GBlurSamplerPong, texcoord - float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
	}
	#else
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
		color += tex2D(RFX_backbufferColor, texcoord - float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
	}
	#endif
	return color;
}

float4 V2GaussianBlurPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
  
	float sampleOffsets[5] = { 0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130 };
	float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
	#if GaussTexScale != 0
	float4 color = tex2D(GBlurSamplerPong, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(GBlurSamplerPong, texcoord + float2(0.0, sampleOffsets[j] * Gpx_size.y)) * sampleWeights[j];
		color += tex2D(GBlurSamplerPong, texcoord - float2(0.0, sampleOffsets[j] * Gpx_size.y)) * sampleWeights[j];
	}
	#else
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(0.0, sampleOffsets[j] * Gpx_size.y)) * sampleWeights[j];
		color += tex2D(RFX_backbufferColor, texcoord - float2(0.0, sampleOffsets[j] * Gpx_size.y)) * sampleWeights[j];
	}
	#endif
	return color;
}

float4 H2GaussianBlurPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
  
	float sampleOffsets[5] = { 0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130 };
	float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
	#if GaussTexScale != 0
	float4 color = tex2D(GBlurSamplerPing, texcoord) * sampleWeights[0];
	[loop]
	for(int i = 1; i < 5; ++i) {
		color += tex2D(GBlurSamplerPing, texcoord + float2(sampleOffsets[i] * Gpx_size.x, 0.0)) * sampleWeights[i];
		color += tex2D(GBlurSamplerPing, texcoord - float2(sampleOffsets[i] * Gpx_size.x, 0.0)) * sampleWeights[i]; 
	}
	#else 
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int i = 1; i < 5; ++i) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(sampleOffsets[i] * Gpx_size.x, 0.0)) * sampleWeights[i];
		color += tex2D(RFX_backbufferColor, texcoord - float2(sampleOffsets[i] * Gpx_size.x, 0.0)) * sampleWeights[i]; 
	}
	#endif
	return color;
}

float4 GaussianBlurFinalPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
  
	float sampleOffsets[5] = { 0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130 };
	float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
	#if GaussTexScale >= 1
	#if GaussQuality >= 1
	float4 color = tex2D(GBlurSamplerPong, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(GBlurSamplerPong, texcoord + float2(0.0, sampleOffsets[j] * Gpx_size.y)) * sampleWeights[j];
		color += tex2D(GBlurSamplerPong, texcoord - float2(0.0, sampleOffsets[j] * Gpx_size.y)) * sampleWeights[j];
	}
	float4 orig = tex2D(RFX_backbufferColor, texcoord); //Original Image
	#else
	float4 color = tex2D(GBlurSamplerPong, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(GBlurSamplerPong, texcoord + float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
		color += tex2D(GBlurSamplerPong, texcoord - float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
	}
	float4 orig = tex2D(RFX_backbufferColor, texcoord); //Original Image
	#endif
	#else
	#if GaussQuality >= 1
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(0.0, sampleOffsets[j] * Gpx_size.y)) * sampleWeights[j];
		color += tex2D(RFX_backbufferColor, texcoord - float2(0.0, sampleOffsets[j] * Gpx_size.y)) * sampleWeights[j];
	}
	float4 orig = tex2D(GBlurSamplerPing, texcoord); //Original Image
	#else 
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
		color += tex2D(RFX_backbufferColor, texcoord - float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
	}
	float4 orig = tex2D(GBlurSamplerPing, texcoord); //Original Image
	#endif 
	#endif
	
	#if Use_Unsharpmask == 1 // Sharpening
	float3 sharp;
		sharp = orig.rgb - color.rgb;
		float sharp_luma1 = dot(sharp, sharp_strength_luma_G);
		sharp_luma1 = clamp(sharp_luma1, -sharp_clampG, sharp_clampG);
		orig = orig + sharp_luma1;
	#endif

	#if Use_GaussianBlur == 1
		orig = lerp(orig, color, BlurStrength);
	#endif

	return saturate(orig);
}

#if Use_GaussianBloom == 1
float3 FilmicTonemap(float3 x) {
    float A = 0.15;
    float B = 0.50;
    float C = 0.10;
    float D = 0.20;
    float E = 0.02;
    float F = 0.30;
    float W = 11.2;
    return ((x*(A*x+C*B)+D*E) / (x*(A*x+B)+D*F))- E / F;
}

float3 DoToneMap(float3 color) {
	/*
    #if TONEMAP_OPERATOR == 1 //TONEMAP_LINEAR
    return exposure * color;
    #elif TONEMAP_OPERATOR == 2 //TONEMAP_EXPONENTIAL
    color = 1.0 - exp2(-exposure * color);
    return color;
    #elif TONEMAP_OPERATOR == 3 //TONEMAP_EXPONENTIAL_HSV
    color = rgb2hsv(color);
    color.b = 1.0 - exp2(-exposure * color.b);
    color = hsv2rgb(color);
    return color;
    #elif TONEMAP_OPERATOR == 5 //TONEMAP_REINHARD
    color = xyz2Yxy(rgb2xyz(color));
    float L = color.r;
    L *= exposure;
    float LL = 1 + L / (burnout * burnout);
    float L_d = L * LL / (1 + L);
    color.r = L_d;
    color = xyz2rgb(Yxy2xyz(color));
    return color;
    #else // TONEMAP_FILMIC
	*/
    color = 2.0f * FilmicTonemap(2.00 * color);
    float3 whiteScale = 1.0f / FilmicTonemap(11.2);
    color *= whiteScale;
    return color;
}

float4 GlareDetectionPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
	#if BloomTexScale != 0
	float4 color = tex2D( BBlurSamplerPong, texcoord );
	#else
	float4 color = tex2D( RFX_backbufferColor, texcoord );
	#endif
	
	#if GaussBloomWarmth == 1
	color.rgb = lerp(color.rgb,dot(color.rgb, CoefLuma_G),-0.2);
	#else
	color.rgb = lerp(color.rgb,dot(color.rgb, CoefLuma_G),0.5);
	#endif
	
	color.rgb *= float3(BloomRed,BloomGreen,BloomBlue);
	
	color.rgb *= ( 1.0f + ( color.rgb / ( GaussThreshold * GaussThreshold ) ) );
	color.rgb *= 0.1800 / ( 0.051 );
    color.rgb -= 5.0f;

    color.rgb = max( color.rgb, 0.0f );

    color.rgb /= ( GaussExposure*0.1 + color.rgb ); 
	
	color.rgb = DoToneMap(color.rgb);
	
	return color;
}

float4 HBloomBlurPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
  
	float sampleOffsets[5] = { 0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130 };
	float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
	#if BloomTexScale >= 1 
	float4 color = tex2D(BBlurSamplerPing, texcoord) * sampleWeights[0];
	[loop]
	for(int i = 1; i < 5; ++i) {
		color += tex2D(BBlurSamplerPing, texcoord + float2(sampleOffsets[i] * RFX_PixelSize.x, 0.0)) * sampleWeights[i];
		color += tex2D(BBlurSamplerPing, texcoord - float2(sampleOffsets[i] * RFX_PixelSize.x, 0.0)) * sampleWeights[i]; 
	}
	#else
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int i = 1; i < 5; ++i) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(sampleOffsets[i] * RFX_PixelSize.x, 0.0)) * sampleWeights[i];
		color += tex2D(RFX_backbufferColor, texcoord - float2(sampleOffsets[i] * RFX_PixelSize.x, 0.0)) * sampleWeights[i]; 
	}
	#endif
	return color;
}

float4 VBloomBlurPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
  
	float sampleOffsets[5] = { 0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130 };
	float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
	#if BloomTexScale != 0
	float4 color = tex2D(BBlurSamplerPong, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(BBlurSamplerPong, texcoord + float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
		color += tex2D(BBlurSamplerPong, texcoord - float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
	}
	#else
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
		color += tex2D(RFX_backbufferColor, texcoord - float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
	}
	#endif
	return color;
}

float4 V2BloomBlurPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
  
	float sampleOffsets[5] = { 0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130 };
	float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
	#if BloomTexScale >= 1
	float4 color = tex2D(BBlurSamplerPong, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(BBlurSamplerPong, texcoord + float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
		color += tex2D(BBlurSamplerPong, texcoord - float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
	}
	#else
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
		color += tex2D(RFX_backbufferColor, texcoord - float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
	}
	#endif
	return color;
}

float4 H2BloomBlurPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
  
	float sampleOffsets[5] = { 0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130 };
	float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
	#if BloomTexScale != 0
	float4 color = tex2D(BBlurSamplerPing, texcoord) * sampleWeights[0];
	[loop]
	for(int i = 1; i < 5; ++i) {
		color += tex2D(BBlurSamplerPing, texcoord + float2(sampleOffsets[i] * Bpx_size.x, 0.0)) * sampleWeights[i];
		color += tex2D(BBlurSamplerPing, texcoord - float2(sampleOffsets[i] * Bpx_size.x, 0.0)) * sampleWeights[i]; 
	}
	#else 
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int i = 1; i < 5; ++i) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(sampleOffsets[i] * Bpx_size.x, 0.0)) * sampleWeights[i];
		color += tex2D(RFX_backbufferColor, texcoord - float2(sampleOffsets[i] * Bpx_size.x, 0.0)) * sampleWeights[i]; 
	}
	#endif
	return color;
}

float4 FinalBloomPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{

	float sampleOffsets[5] = { 0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130 };
	float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
	#if BloomTexScale != 0
	#if BloomQuality >= 1
	float4 color = tex2D(BBlurSamplerPong, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(BBlurSamplerPong, texcoord + float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
		color += tex2D(BBlurSamplerPong, texcoord - float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
	}
	float4 orig = tex2D(RFX_backbufferColor, texcoord); //Original Image
	#else 
	float4 color = tex2D(BBlurSamplerPong, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(BBlurSamplerPong, texcoord + float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
		color += tex2D(BBlurSamplerPong, texcoord - float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
	}
	float4 orig = tex2D(RFX_backbufferColor, texcoord); //Original Image
	#endif
	#else
	#if BloomQuality >= 1
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
		color += tex2D(RFX_backbufferColor, texcoord - float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
	}
	float4 orig = tex2D(GBlurSamplerPing, texcoord); //Original Image
	#else
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
		color += tex2D(RFX_backbufferColor, texcoord - float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
	}
	float4 orig = tex2D(GBlurSamplerPing, texcoord); //Original Image
	#endif
	#endif
			#define BloomDebug 0
		
		#if (GaussBloomWarmth == 0)
			#if BloomDebug == 1 
			orig = (1.0 - ((1.0 - orig) * (1.0 - (pow(abs(color*2.3),2.5))*0.3)));
			#else
			//orig = lerp(orig, (1.0 - ((1.0 - orig) * (1.0 - (pow(abs(color*2.3),2.5))*0.3))), BloomStrength);
			orig = lerp(orig, (1.0 - ((0.95 - orig) * (1.05 - (pow(abs(color*2.6),2.5))*0.3))), BloomStrength);
			#endif
		#elif (GaussBloomWarmth == 1)
			#if BloomDebug == 1 
			orig = (1.0 - ((1.05 - orig) * (0.95 - (pow(abs(color*2.6),2.5))*0.3)));
			#else
			orig = lerp(orig, (1.0 - ((1.05 - orig) * (0.95 - (pow(abs(color*2.6),2.5))*0.3))), BloomStrength);
			//orig = lerp(orig, (1.0 - ((1.0 - orig) * (1.00 - (pow(abs(color*2.6),2.5))*0.3))), BloomStrength);
			#endif
		#else
			#if BloomDebug == 1 
			orig = (1.0 - ((1.0 - orig) * (1.0 - (color)))), BloomStrength);
			#else
			orig = lerp(orig, (1.0 - ((1.0 - orig) * (1.0 - (color)))), BloomStrength);  // Foggy bloom
			#endif
		#endif 
		
	return saturate(orig);
}
#endif

technique Gaussian_Tech <bool enabled = RFX_Start_Enabled; int toggle = Gaussian_ToggleKey; >
{
#if Use_Unsharpmask == 1 || Use_GaussianBlur == 1
	pass H1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = GOriginalPixel;
		RenderTarget = GBlurTex2Dping;
	}

	pass H1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = HGaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}

#if GaussQuality >= 1
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = VGaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussQuality >= 2
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussQuality >= 3	
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussQuality >= 4
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussQuality >= 5	
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussQuality >= 6	
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussQuality >= 7	
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussQuality >= 8	
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussQuality >= 9
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussQuality >= 10	
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussQuality >= 11	
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussQuality >= 12
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif
	pass VFinal
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = GaussianBlurFinalPS;
	}
#endif
#if Use_GaussianBloom == 1

	pass H1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = GOriginalPixel;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#else
		RenderTarget = GBlurTex2Dping;
		#endif
	}

	pass GD
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = GlareDetectionPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
	
	pass H1Bloom
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = HBloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
		
#if GaussBloomQuality >= 1
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = VBloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussBloomQuality >= 2
	pass V2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
	
	pass H3
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussBloomQuality >= 3
	pass V3
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
		
	pass H4
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussBloomQuality >= 4
	pass V4
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}	
	
	pass H5
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussBloomQuality >= 5	
	pass V5
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
	
	pass H6
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussBloomQuality >= 6
	pass V2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
	
	pass H3
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussBloomQuality >= 7	
	pass V2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
	
	pass H3
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussBloomQuality >= 8
	pass V2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
	
	pass H3
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussBloomQuality >= 9
	pass V2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
	
	pass H3
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussBloomQuality >= 10	
	pass V2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
	
	pass H3
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussBloomQuality >= 11	
	pass V2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
	
	pass H3
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussBloomQuality >= 12
	pass V2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
	
	pass H3
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif
	
	pass VFinal
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = FinalBloomPS;
	}
#endif
}
NAMESPACE_LEAVE()

#endif

#include CFX_SETTINGS_UNDEF

NAMESPACE_LEAVE()
Last Edit: 1 year 4 months ago by Ganossa.
The administrator has disabled public write access.

2x same shader/shader to brighten dark. 1 year 4 months ago #10

  • Ganossa
  • Ganossa's Avatar
  • Offline
  • 최정장군
  • Posts: 790
  • Thank you received: 838
The second last NAMESPACE_LEAVE() is one too much and in the Gausssian code there are some #defines in the beginning that might need to be undefined after one execution cause otherwise causing conflicts.

Delete the second last NAMESPACE_LEAVE() and add the following lines between my suggested Step 1 and Step 2:
#undef CoefLuma_G
#undef sharp_strength_luma_G
#undef sharp_clampG
#undef txsize
#undef Gpx_size
#undef Bpx_size
#undef Btxsize


This solution will not come up in the mediator. You can manually define the second values in the pasted copy of the #defines you did in Step 2.
Last Edit: 1 year 4 months ago by Ganossa.
The administrator has disabled public write access.

2x same shader/shader to brighten dark. 1 year 4 months ago #11

Sorry. I cant for the life of me get it to work. Did excactly what you told me but all I get is this:

"05/01/2016 16:08:27:817 [10596] | ERROR | Failed to compile effect on context 056A3FC0:"
and
"... /ReShade/CustomFX/Gaussian.h(1113, 13): error X3003: redefinition of 'random'"

This is what the gaussian.h file looks like now:
NAMESPACE_ENTER(CFX)

#include CFX_SETTINGS_DEF

#if USE_GAUSS

#if USE_Blur == 1
#define Use_GaussianBlur 1
#endif
#if USE_Sharpening == 1 
#define Use_Unsharpmask 1
#endif
#if USE_Bloom == 1
#define Use_GaussianBloom 1 
#endif

 /**
 * Copyright (C) 2012 Jorge Jimenez (). All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *    1. Redistributions of source code must retain the above copyright notice,
 *       this list of conditions and the following disclaimer.
 *
 *    2. Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * The views and conclusions contained in the software and documentation are 
 * those of the authors and should not be interpreted as representing official
 * policies, either expressed or implied, of the copyright holders.
 */

/* This is my attempt to port the the GAUSSIAN shader by Boulotaur2024 to ReShade.
   Some settings from the original are missing and I have added some other settings to achieve certain looks.
   More info can be found at 
   http://reshade.me/forum/shader-presentation/27-gaussian-blur-bloom-unsharpmask */ 

#define CoefLuma_G            float3(0.2126, 0.7152, 0.0722)      // BT.709 & sRBG luma coefficient (Monitors and HD Television)
#define sharp_strength_luma_G (CoefLuma_G * SharpStrength + 0.2)
#define sharp_clampG        0.035

uniform int random < source = "random"; min = 0; max = 10; >;

#if Use_GaussianBlur == 0 && Use_Unsharpmask == 0 
#undef GaussTexScale 
#endif 

#if Use_GaussianBloom == 0 
#undef BloomTexScale 
#endif

#if GaussTexScale == 1 
#define txsize 2 
#elif GaussTexScale == 2 
#define txsize 4 
#else 
#define txsize 1 
#endif

#if GaussSigma == 2
#define Gpx_size (RFX_PixelSize*2)
#elif GaussSigma == 3
#define Gpx_size (RFX_PixelSize*3)
#elif GaussSigma == 4
#define Gpx_size (RFX_PixelSize*4)
#else
#define Gpx_size (RFX_PixelSize)
#endif

texture GBlurTex2Dping{ Width = BUFFER_WIDTH/txsize; Height = BUFFER_HEIGHT/txsize; Format = RGBA8; };
sampler2D GBlurSamplerPing { Texture = GBlurTex2Dping; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; AddressU = Clamp; SRGBTexture = FALSE;};
#if GaussTexScale != 0
texture GBlurTex2Dpong{ Width = BUFFER_WIDTH/txsize; Height = BUFFER_HEIGHT/txsize; Format = RGBA8; };
sampler2D GBlurSamplerPong { Texture = GBlurTex2Dpong; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; AddressU = Clamp; SRGBTexture = FALSE;};
#endif

#if BloomSigma == 2
#define Bpx_size (RFX_PixelSize*2)
#elif BloomSigma == 3
#define Bpx_size (RFX_PixelSize*3)
#elif BloomSigma == 4
#define Bpx_size (RFX_PixelSize*4)
#else
#define Bpx_size (RFX_PixelSize)
#endif

#if BloomTexScale != 0
 
#if BloomTexScale == 1 
	#define Btxsize 0.5 
#elif BloomTexScale == 2 
	#define Btxsize 0.25 
#else 
	#define Btxsize 1 
#endif

texture BBlurTex2Dping{ Width = BUFFER_WIDTH*Btxsize; Height = BUFFER_HEIGHT*Btxsize; Format = RGBA8; };
texture BBlurTex2Dpong{ Width = BUFFER_WIDTH*Btxsize; Height = BUFFER_HEIGHT*Btxsize; Format = RGBA8; };
sampler2D BBlurSamplerPing { Texture = BBlurTex2Dping; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; AddressU = Clamp; SRGBTexture = FALSE;};
sampler2D BBlurSamplerPong { Texture = BBlurTex2Dpong; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; AddressU = Clamp; SRGBTexture = FALSE;};
#endif 

float4 GOriginalPixel(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
	float4 color = tex2D(RFX_backbufferColor, texcoord);
	return saturate(color);
}

float4 HGaussianBlurPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
  
	float sampleOffsets[5] = { 0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130 };
	float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
	#if GaussTexScale != 0 
	float4 color = tex2D(GBlurSamplerPing, texcoord) * sampleWeights[0];
	[loop]
	for(int i = 1; i < 5; ++i) {
		color += tex2D(GBlurSamplerPing, texcoord + float2(sampleOffsets[i] * RFX_PixelSize.x, 0.0)) * sampleWeights[i];
		color += tex2D(GBlurSamplerPing, texcoord - float2(sampleOffsets[i] * RFX_PixelSize.x, 0.0)) * sampleWeights[i]; 
	}
	#else
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int i = 1; i < 5; ++i) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(sampleOffsets[i] * RFX_PixelSize.x, 0.0)) * sampleWeights[i];
		color += tex2D(RFX_backbufferColor, texcoord - float2(sampleOffsets[i] * RFX_PixelSize.x, 0.0)) * sampleWeights[i]; 
	}
	#endif
	return color;
}

float4 VGaussianBlurPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
  
	float sampleOffsets[5] = { 0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130 };
	float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
	#if GaussTexScale != 0
	float4 color = tex2D(GBlurSamplerPong, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(GBlurSamplerPong, texcoord + float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
		color += tex2D(GBlurSamplerPong, texcoord - float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
	}
	#else
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
		color += tex2D(RFX_backbufferColor, texcoord - float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
	}
	#endif
	return color;
}

float4 V2GaussianBlurPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
  
	float sampleOffsets[5] = { 0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130 };
	float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
	#if GaussTexScale != 0
	float4 color = tex2D(GBlurSamplerPong, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(GBlurSamplerPong, texcoord + float2(0.0, sampleOffsets[j] * Gpx_size.y)) * sampleWeights[j];
		color += tex2D(GBlurSamplerPong, texcoord - float2(0.0, sampleOffsets[j] * Gpx_size.y)) * sampleWeights[j];
	}
	#else
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(0.0, sampleOffsets[j] * Gpx_size.y)) * sampleWeights[j];
		color += tex2D(RFX_backbufferColor, texcoord - float2(0.0, sampleOffsets[j] * Gpx_size.y)) * sampleWeights[j];
	}
	#endif
	return color;
}

float4 H2GaussianBlurPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
  
	float sampleOffsets[5] = { 0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130 };
	float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
	#if GaussTexScale != 0
	float4 color = tex2D(GBlurSamplerPing, texcoord) * sampleWeights[0];
	[loop]
	for(int i = 1; i < 5; ++i) {
		color += tex2D(GBlurSamplerPing, texcoord + float2(sampleOffsets[i] * Gpx_size.x, 0.0)) * sampleWeights[i];
		color += tex2D(GBlurSamplerPing, texcoord - float2(sampleOffsets[i] * Gpx_size.x, 0.0)) * sampleWeights[i]; 
	}
	#else 
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int i = 1; i < 5; ++i) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(sampleOffsets[i] * Gpx_size.x, 0.0)) * sampleWeights[i];
		color += tex2D(RFX_backbufferColor, texcoord - float2(sampleOffsets[i] * Gpx_size.x, 0.0)) * sampleWeights[i]; 
	}
	#endif
	return color;
}

float4 GaussianBlurFinalPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
  
	float sampleOffsets[5] = { 0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130 };
	float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
	#if GaussTexScale >= 1
	#if GaussQuality >= 1
	float4 color = tex2D(GBlurSamplerPong, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(GBlurSamplerPong, texcoord + float2(0.0, sampleOffsets[j] * Gpx_size.y)) * sampleWeights[j];
		color += tex2D(GBlurSamplerPong, texcoord - float2(0.0, sampleOffsets[j] * Gpx_size.y)) * sampleWeights[j];
	}
	float4 orig = tex2D(RFX_backbufferColor, texcoord); //Original Image
	#else
	float4 color = tex2D(GBlurSamplerPong, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(GBlurSamplerPong, texcoord + float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
		color += tex2D(GBlurSamplerPong, texcoord - float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
	}
	float4 orig = tex2D(RFX_backbufferColor, texcoord); //Original Image
	#endif
	#else
	#if GaussQuality >= 1
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(0.0, sampleOffsets[j] * Gpx_size.y)) * sampleWeights[j];
		color += tex2D(RFX_backbufferColor, texcoord - float2(0.0, sampleOffsets[j] * Gpx_size.y)) * sampleWeights[j];
	}
	float4 orig = tex2D(GBlurSamplerPing, texcoord); //Original Image
	#else 
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
		color += tex2D(RFX_backbufferColor, texcoord - float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
	}
	float4 orig = tex2D(GBlurSamplerPing, texcoord); //Original Image
	#endif 
	#endif
	
	#if Use_Unsharpmask == 1 // Sharpening
	float3 sharp;
		sharp = orig.rgb - color.rgb;
		float sharp_luma1 = dot(sharp, sharp_strength_luma_G);
		sharp_luma1 = clamp(sharp_luma1, -sharp_clampG, sharp_clampG);
		orig = orig + sharp_luma1;
	#endif

	#if Use_GaussianBlur == 1
		orig = lerp(orig, color, BlurStrength);
	#endif

	return saturate(orig);
}

#if Use_GaussianBloom == 1
float3 FilmicTonemap(float3 x) {
    float A = 0.15;
    float B = 0.50;
    float C = 0.10;
    float D = 0.20;
    float E = 0.02;
    float F = 0.30;
    float W = 11.2;
    return ((x*(A*x+C*B)+D*E) / (x*(A*x+B)+D*F))- E / F;
}

float3 DoToneMap(float3 color) {
	/*
    #if TONEMAP_OPERATOR == 1 //TONEMAP_LINEAR
    return exposure * color;
    #elif TONEMAP_OPERATOR == 2 //TONEMAP_EXPONENTIAL
    color = 1.0 - exp2(-exposure * color);
    return color;
    #elif TONEMAP_OPERATOR == 3 //TONEMAP_EXPONENTIAL_HSV
    color = rgb2hsv(color);
    color.b = 1.0 - exp2(-exposure * color.b);
    color = hsv2rgb(color);
    return color;
    #elif TONEMAP_OPERATOR == 5 //TONEMAP_REINHARD
    color = xyz2Yxy(rgb2xyz(color));
    float L = color.r;
    L *= exposure;
    float LL = 1 + L / (burnout * burnout);
    float L_d = L * LL / (1 + L);
    color.r = L_d;
    color = xyz2rgb(Yxy2xyz(color));
    return color;
    #else // TONEMAP_FILMIC
	*/
    color = 2.0f * FilmicTonemap(2.00 * color);
    float3 whiteScale = 1.0f / FilmicTonemap(11.2);
    color *= whiteScale;
    return color;
}

float4 GlareDetectionPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
	#if BloomTexScale != 0
	float4 color = tex2D( BBlurSamplerPong, texcoord );
	#else
	float4 color = tex2D( RFX_backbufferColor, texcoord );
	#endif
	
	#if GaussBloomWarmth == 1
	color.rgb = lerp(color.rgb,dot(color.rgb, CoefLuma_G),-0.2);
	#else
	color.rgb = lerp(color.rgb,dot(color.rgb, CoefLuma_G),0.5);
	#endif
	
	color.rgb *= float3(BloomRed,BloomGreen,BloomBlue);
	
	color.rgb *= ( 1.0f + ( color.rgb / ( GaussThreshold * GaussThreshold ) ) );
	color.rgb *= 0.1800 / ( 0.051 );
    color.rgb -= 5.0f;

    color.rgb = max( color.rgb, 0.0f );

    color.rgb /= ( GaussExposure*0.1 + color.rgb ); 
	
	color.rgb = DoToneMap(color.rgb);
	
	return color;
}

float4 HBloomBlurPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
  
	float sampleOffsets[5] = { 0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130 };
	float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
	#if BloomTexScale >= 1 
	float4 color = tex2D(BBlurSamplerPing, texcoord) * sampleWeights[0];
	[loop]
	for(int i = 1; i < 5; ++i) {
		color += tex2D(BBlurSamplerPing, texcoord + float2(sampleOffsets[i] * RFX_PixelSize.x, 0.0)) * sampleWeights[i];
		color += tex2D(BBlurSamplerPing, texcoord - float2(sampleOffsets[i] * RFX_PixelSize.x, 0.0)) * sampleWeights[i]; 
	}
	#else
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int i = 1; i < 5; ++i) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(sampleOffsets[i] * RFX_PixelSize.x, 0.0)) * sampleWeights[i];
		color += tex2D(RFX_backbufferColor, texcoord - float2(sampleOffsets[i] * RFX_PixelSize.x, 0.0)) * sampleWeights[i]; 
	}
	#endif
	return color;
}

float4 VBloomBlurPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
  
	float sampleOffsets[5] = { 0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130 };
	float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
	#if BloomTexScale != 0
	float4 color = tex2D(BBlurSamplerPong, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(BBlurSamplerPong, texcoord + float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
		color += tex2D(BBlurSamplerPong, texcoord - float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
	}
	#else
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
		color += tex2D(RFX_backbufferColor, texcoord - float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
	}
	#endif
	return color;
}

float4 V2BloomBlurPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
  
	float sampleOffsets[5] = { 0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130 };
	float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
	#if BloomTexScale >= 1
	float4 color = tex2D(BBlurSamplerPong, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(BBlurSamplerPong, texcoord + float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
		color += tex2D(BBlurSamplerPong, texcoord - float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
	}
	#else
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
		color += tex2D(RFX_backbufferColor, texcoord - float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
	}
	#endif
	return color;
}

float4 H2BloomBlurPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
  
	float sampleOffsets[5] = { 0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130 };
	float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
	#if BloomTexScale != 0
	float4 color = tex2D(BBlurSamplerPing, texcoord) * sampleWeights[0];
	[loop]
	for(int i = 1; i < 5; ++i) {
		color += tex2D(BBlurSamplerPing, texcoord + float2(sampleOffsets[i] * Bpx_size.x, 0.0)) * sampleWeights[i];
		color += tex2D(BBlurSamplerPing, texcoord - float2(sampleOffsets[i] * Bpx_size.x, 0.0)) * sampleWeights[i]; 
	}
	#else 
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int i = 1; i < 5; ++i) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(sampleOffsets[i] * Bpx_size.x, 0.0)) * sampleWeights[i];
		color += tex2D(RFX_backbufferColor, texcoord - float2(sampleOffsets[i] * Bpx_size.x, 0.0)) * sampleWeights[i]; 
	}
	#endif
	return color;
}

float4 FinalBloomPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{

	float sampleOffsets[5] = { 0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130 };
	float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
	#if BloomTexScale != 0
	#if BloomQuality >= 1
	float4 color = tex2D(BBlurSamplerPong, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(BBlurSamplerPong, texcoord + float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
		color += tex2D(BBlurSamplerPong, texcoord - float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
	}
	float4 orig = tex2D(RFX_backbufferColor, texcoord); //Original Image
	#else 
	float4 color = tex2D(BBlurSamplerPong, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(BBlurSamplerPong, texcoord + float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
		color += tex2D(BBlurSamplerPong, texcoord - float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
	}
	float4 orig = tex2D(RFX_backbufferColor, texcoord); //Original Image
	#endif
	#else
	#if BloomQuality >= 1
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
		color += tex2D(RFX_backbufferColor, texcoord - float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
	}
	float4 orig = tex2D(GBlurSamplerPing, texcoord); //Original Image
	#else
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
		color += tex2D(RFX_backbufferColor, texcoord - float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
	}
	float4 orig = tex2D(GBlurSamplerPing, texcoord); //Original Image
	#endif
	#endif
			#define BloomDebug 0
		
		#if (GaussBloomWarmth == 0)
			#if BloomDebug == 1 
			orig = (1.0 - ((1.0 - orig) * (1.0 - (pow(abs(color*2.3),2.5))*0.3)));
			#else
			//orig = lerp(orig, (1.0 - ((1.0 - orig) * (1.0 - (pow(abs(color*2.3),2.5))*0.3))), BloomStrength);
			orig = lerp(orig, (1.0 - ((0.95 - orig) * (1.05 - (pow(abs(color*2.6),2.5))*0.3))), BloomStrength);
			#endif
		#elif (GaussBloomWarmth == 1)
			#if BloomDebug == 1 
			orig = (1.0 - ((1.05 - orig) * (0.95 - (pow(abs(color*2.6),2.5))*0.3)));
			#else
			orig = lerp(orig, (1.0 - ((1.05 - orig) * (0.95 - (pow(abs(color*2.6),2.5))*0.3))), BloomStrength);
			//orig = lerp(orig, (1.0 - ((1.0 - orig) * (1.00 - (pow(abs(color*2.6),2.5))*0.3))), BloomStrength);
			#endif
		#else
			#if BloomDebug == 1 
			orig = (1.0 - ((1.0 - orig) * (1.0 - (color)))), BloomStrength);
			#else
			orig = lerp(orig, (1.0 - ((1.0 - orig) * (1.0 - (color)))), BloomStrength);  // Foggy bloom
			#endif
		#endif 
		
	return saturate(orig);
}
#endif

technique Gaussian_Tech <bool enabled = RFX_Start_Enabled; int toggle = Gaussian_ToggleKey; >
{
#if Use_Unsharpmask == 1 || Use_GaussianBlur == 1
	pass H1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = GOriginalPixel;
		RenderTarget = GBlurTex2Dping;
	}

	pass H1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = HGaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}

#if GaussQuality >= 1
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = VGaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussQuality >= 2
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussQuality >= 3	
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussQuality >= 4
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussQuality >= 5	
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussQuality >= 6	
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussQuality >= 7	
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussQuality >= 8	
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussQuality >= 9
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussQuality >= 10	
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussQuality >= 11	
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussQuality >= 12
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif
	pass VFinal
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = GaussianBlurFinalPS;
	}
#endif
#if Use_GaussianBloom == 1

	pass H1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = GOriginalPixel;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#else
		RenderTarget = GBlurTex2Dping;
		#endif
	}

	pass GD
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = GlareDetectionPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
	
	pass H1Bloom
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = HBloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
		
#if GaussBloomQuality >= 1
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = VBloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussBloomQuality >= 2
	pass V2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
	
	pass H3
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussBloomQuality >= 3
	pass V3
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
		
	pass H4
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussBloomQuality >= 4
	pass V4
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}	
	
	pass H5
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussBloomQuality >= 5	
	pass V5
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
	
	pass H6
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussBloomQuality >= 6
	pass V2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
	
	pass H3
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussBloomQuality >= 7	
	pass V2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
	
	pass H3
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussBloomQuality >= 8
	pass V2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
	
	pass H3
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussBloomQuality >= 9
	pass V2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
	
	pass H3
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussBloomQuality >= 10	
	pass V2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
	
	pass H3
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussBloomQuality >= 11	
	pass V2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
	
	pass H3
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussBloomQuality >= 12
	pass V2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
	
	pass H3
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif
	
	pass VFinal
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = FinalBloomPS;
	}
#endif
}
NAMESPACE_LEAVE()
#include CFX_SETTINGS_UNDEF
NAMESPACE_ENTER(CFX2)

#undef CoefLuma_G
#undef sharp_strength_luma_G
#undef sharp_clampG
#undef txsize
#undef Gpx_size
#undef Bpx_size
#undef Btxsize 

#define USE_GAUSS 1 //[Gaussian] //-Gaussian Blur / Bloom / Unsharpmask

//>Gaussian Blur / Unsharpmask Settings<\\
#define Use_GaussianBlur 0 //[0:1] //-0 = off, 1 = on. Blurs the image
#define BlurStrength 0.13 //[0.00:1.00] //-Strength of the blur effect
#define Use_Unsharpmask 0 //[0:1] //-0 = off, 1 = on. Sharpens the image
#define SharpStrength 0.10 //[0.00:1.00] //-Strength of the sharpening effect
#define GaussSigma 1 //[1|2|3|4] //-Makes the blur and sharpening radius wider. Only works when GaussQuality is set to 1 or higher.
#define GaussQuality 11 //[0:12] //-Higher #'s = more blur passes for Blur and Unsharp Mask (Higher performance cost).

//>Gaussian Bloom Settings<\\
#define Use_GaussianBloom 1 //[0:1] //-0 = off, 1 = on. 
#define BloomStrength 1.00 //[0.00:1.00] //-Amount of bloom effect added to the image.
#define GaussBloomWarmth 2 //[0|1|2] //-0 = neutral, 1 = warm, 2 = hazy/foggy
#define GaussThreshold 0.300 //[0.000:1.000] //-Threshold for what is considered a bright light. Lower #'s = brighter
#define GaussExposure 43.77 //[0.00:100.00] //-Exposure of the effect. Lower #'s = brighter 
#define BloomSigma 2 //[1|2|3|4] //-Makes the bloom radius wider. Only works when BloomQuality is set to 1 or higher. 
#define BloomRed 1.00 //[0.00:2.00] //-Adds a RED tint to bloom. #'s < 1.00 add color, #'s > 1.00 remove color.
#define BloomGreen 1.00 //[0.00:2.00] //-Adds a GREEN tint to bloom. #'s < 1.00 add color, #'s > 1.00 remove color.
#define BloomBlue 1.00 //[0.00:2.00] //-Adds a BLUE tint to bloom. #'s < 1.00 add color, #'s > 1.00 remove color.
#define GaussBloomQuality 8 //[0:12] //-Higher #'s = more blur passes

//>Performance and Misc Options<\\
#define GaussTexScale 0 //[0|1|2] //-0 = Off, 1 = 1/2 Resolution, 2 = 1/4 Resolution. Reduces performance cost. Works best with Quality settings > 1.
#define BloomTexScale 0 //[0|1|2] //-0 = Off, 1 = 1/2 Resolution, 2 = 1/4 Resolution. Reduces performance cost. Works best with Quality settings > 1.
#define Gaussian_ToggleKey RFX_ToggleKey //[undef] //-

#if USE_Blur == 1
#define Use_GaussianBlur 1
#endif
#if USE_Sharpening == 1 
#define Use_Unsharpmask 1
#endif
#if USE_Bloom == 1
#define Use_GaussianBloom 1 
#endif

 /**
 * Copyright (C) 2012 Jorge Jimenez (). All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *    1. Redistributions of source code must retain the above copyright notice,
 *       this list of conditions and the following disclaimer.
 *
 *    2. Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * The views and conclusions contained in the software and documentation are 
 * those of the authors and should not be interpreted as representing official
 * policies, either expressed or implied, of the copyright holders.
 */

/* This is my attempt to port the the GAUSSIAN shader by Boulotaur2024 to ReShade.
   Some settings from the original are missing and I have added some other settings to achieve certain looks.
   More info can be found at 
   http://reshade.me/forum/shader-presentation/27-gaussian-blur-bloom-unsharpmask */ 

#define CoefLuma_G            float3(0.2126, 0.7152, 0.0722)      // BT.709 & sRBG luma coefficient (Monitors and HD Television)
#define sharp_strength_luma_G (CoefLuma_G * SharpStrength + 0.2)
#define sharp_clampG        0.035

uniform int random < source = "random"; min = 0; max = 10; >;

#if Use_GaussianBlur == 0 && Use_Unsharpmask == 0 
#undef GaussTexScale 
#endif 

#if Use_GaussianBloom == 0 
#undef BloomTexScale 
#endif

#if GaussTexScale == 1 
#define txsize 2 
#elif GaussTexScale == 2 
#define txsize 4 
#else 
#define txsize 1 
#endif

#if GaussSigma == 2
#define Gpx_size (RFX_PixelSize*2)
#elif GaussSigma == 3
#define Gpx_size (RFX_PixelSize*3)
#elif GaussSigma == 4
#define Gpx_size (RFX_PixelSize*4)
#else
#define Gpx_size (RFX_PixelSize)
#endif

texture GBlurTex2Dping{ Width = BUFFER_WIDTH/txsize; Height = BUFFER_HEIGHT/txsize; Format = RGBA8; };
sampler2D GBlurSamplerPing { Texture = GBlurTex2Dping; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; AddressU = Clamp; SRGBTexture = FALSE;};
#if GaussTexScale != 0
texture GBlurTex2Dpong{ Width = BUFFER_WIDTH/txsize; Height = BUFFER_HEIGHT/txsize; Format = RGBA8; };
sampler2D GBlurSamplerPong { Texture = GBlurTex2Dpong; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; AddressU = Clamp; SRGBTexture = FALSE;};
#endif

#if BloomSigma == 2
#define Bpx_size (RFX_PixelSize*2)
#elif BloomSigma == 3
#define Bpx_size (RFX_PixelSize*3)
#elif BloomSigma == 4
#define Bpx_size (RFX_PixelSize*4)
#else
#define Bpx_size (RFX_PixelSize)
#endif

#if BloomTexScale != 0
 
#if BloomTexScale == 1 
	#define Btxsize 0.5 
#elif BloomTexScale == 2 
	#define Btxsize 0.25 
#else 
	#define Btxsize 1 
#endif

texture BBlurTex2Dping{ Width = BUFFER_WIDTH*Btxsize; Height = BUFFER_HEIGHT*Btxsize; Format = RGBA8; };
texture BBlurTex2Dpong{ Width = BUFFER_WIDTH*Btxsize; Height = BUFFER_HEIGHT*Btxsize; Format = RGBA8; };
sampler2D BBlurSamplerPing { Texture = BBlurTex2Dping; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; AddressU = Clamp; SRGBTexture = FALSE;};
sampler2D BBlurSamplerPong { Texture = BBlurTex2Dpong; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; AddressU = Clamp; SRGBTexture = FALSE;};
#endif 

float4 GOriginalPixel(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
	float4 color = tex2D(RFX_backbufferColor, texcoord);
	return saturate(color);
}

float4 HGaussianBlurPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
  
	float sampleOffsets[5] = { 0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130 };
	float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
	#if GaussTexScale != 0 
	float4 color = tex2D(GBlurSamplerPing, texcoord) * sampleWeights[0];
	[loop]
	for(int i = 1; i < 5; ++i) {
		color += tex2D(GBlurSamplerPing, texcoord + float2(sampleOffsets[i] * RFX_PixelSize.x, 0.0)) * sampleWeights[i];
		color += tex2D(GBlurSamplerPing, texcoord - float2(sampleOffsets[i] * RFX_PixelSize.x, 0.0)) * sampleWeights[i]; 
	}
	#else
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int i = 1; i < 5; ++i) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(sampleOffsets[i] * RFX_PixelSize.x, 0.0)) * sampleWeights[i];
		color += tex2D(RFX_backbufferColor, texcoord - float2(sampleOffsets[i] * RFX_PixelSize.x, 0.0)) * sampleWeights[i]; 
	}
	#endif
	return color;
}

float4 VGaussianBlurPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
  
	float sampleOffsets[5] = { 0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130 };
	float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
	#if GaussTexScale != 0
	float4 color = tex2D(GBlurSamplerPong, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(GBlurSamplerPong, texcoord + float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
		color += tex2D(GBlurSamplerPong, texcoord - float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
	}
	#else
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
		color += tex2D(RFX_backbufferColor, texcoord - float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
	}
	#endif
	return color;
}

float4 V2GaussianBlurPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
  
	float sampleOffsets[5] = { 0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130 };
	float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
	#if GaussTexScale != 0
	float4 color = tex2D(GBlurSamplerPong, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(GBlurSamplerPong, texcoord + float2(0.0, sampleOffsets[j] * Gpx_size.y)) * sampleWeights[j];
		color += tex2D(GBlurSamplerPong, texcoord - float2(0.0, sampleOffsets[j] * Gpx_size.y)) * sampleWeights[j];
	}
	#else
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(0.0, sampleOffsets[j] * Gpx_size.y)) * sampleWeights[j];
		color += tex2D(RFX_backbufferColor, texcoord - float2(0.0, sampleOffsets[j] * Gpx_size.y)) * sampleWeights[j];
	}
	#endif
	return color;
}

float4 H2GaussianBlurPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
  
	float sampleOffsets[5] = { 0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130 };
	float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
	#if GaussTexScale != 0
	float4 color = tex2D(GBlurSamplerPing, texcoord) * sampleWeights[0];
	[loop]
	for(int i = 1; i < 5; ++i) {
		color += tex2D(GBlurSamplerPing, texcoord + float2(sampleOffsets[i] * Gpx_size.x, 0.0)) * sampleWeights[i];
		color += tex2D(GBlurSamplerPing, texcoord - float2(sampleOffsets[i] * Gpx_size.x, 0.0)) * sampleWeights[i]; 
	}
	#else 
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int i = 1; i < 5; ++i) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(sampleOffsets[i] * Gpx_size.x, 0.0)) * sampleWeights[i];
		color += tex2D(RFX_backbufferColor, texcoord - float2(sampleOffsets[i] * Gpx_size.x, 0.0)) * sampleWeights[i]; 
	}
	#endif
	return color;
}

float4 GaussianBlurFinalPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
  
	float sampleOffsets[5] = { 0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130 };
	float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
	#if GaussTexScale >= 1
	#if GaussQuality >= 1
	float4 color = tex2D(GBlurSamplerPong, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(GBlurSamplerPong, texcoord + float2(0.0, sampleOffsets[j] * Gpx_size.y)) * sampleWeights[j];
		color += tex2D(GBlurSamplerPong, texcoord - float2(0.0, sampleOffsets[j] * Gpx_size.y)) * sampleWeights[j];
	}
	float4 orig = tex2D(RFX_backbufferColor, texcoord); //Original Image
	#else
	float4 color = tex2D(GBlurSamplerPong, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(GBlurSamplerPong, texcoord + float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
		color += tex2D(GBlurSamplerPong, texcoord - float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
	}
	float4 orig = tex2D(RFX_backbufferColor, texcoord); //Original Image
	#endif
	#else
	#if GaussQuality >= 1
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(0.0, sampleOffsets[j] * Gpx_size.y)) * sampleWeights[j];
		color += tex2D(RFX_backbufferColor, texcoord - float2(0.0, sampleOffsets[j] * Gpx_size.y)) * sampleWeights[j];
	}
	float4 orig = tex2D(GBlurSamplerPing, texcoord); //Original Image
	#else 
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
		color += tex2D(RFX_backbufferColor, texcoord - float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
	}
	float4 orig = tex2D(GBlurSamplerPing, texcoord); //Original Image
	#endif 
	#endif
	
	#if Use_Unsharpmask == 1 // Sharpening
	float3 sharp;
		sharp = orig.rgb - color.rgb;
		float sharp_luma1 = dot(sharp, sharp_strength_luma_G);
		sharp_luma1 = clamp(sharp_luma1, -sharp_clampG, sharp_clampG);
		orig = orig + sharp_luma1;
	#endif

	#if Use_GaussianBlur == 1
		orig = lerp(orig, color, BlurStrength);
	#endif

	return saturate(orig);
}

#if Use_GaussianBloom == 1
float3 FilmicTonemap(float3 x) {
    float A = 0.15;
    float B = 0.50;
    float C = 0.10;
    float D = 0.20;
    float E = 0.02;
    float F = 0.30;
    float W = 11.2;
    return ((x*(A*x+C*B)+D*E) / (x*(A*x+B)+D*F))- E / F;
}

float3 DoToneMap(float3 color) {
	/*
    #if TONEMAP_OPERATOR == 1 //TONEMAP_LINEAR
    return exposure * color;
    #elif TONEMAP_OPERATOR == 2 //TONEMAP_EXPONENTIAL
    color = 1.0 - exp2(-exposure * color);
    return color;
    #elif TONEMAP_OPERATOR == 3 //TONEMAP_EXPONENTIAL_HSV
    color = rgb2hsv(color);
    color.b = 1.0 - exp2(-exposure * color.b);
    color = hsv2rgb(color);
    return color;
    #elif TONEMAP_OPERATOR == 5 //TONEMAP_REINHARD
    color = xyz2Yxy(rgb2xyz(color));
    float L = color.r;
    L *= exposure;
    float LL = 1 + L / (burnout * burnout);
    float L_d = L * LL / (1 + L);
    color.r = L_d;
    color = xyz2rgb(Yxy2xyz(color));
    return color;
    #else // TONEMAP_FILMIC
	*/
    color = 2.0f * FilmicTonemap(2.00 * color);
    float3 whiteScale = 1.0f / FilmicTonemap(11.2);
    color *= whiteScale;
    return color;
}

float4 GlareDetectionPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
	#if BloomTexScale != 0
	float4 color = tex2D( BBlurSamplerPong, texcoord );
	#else
	float4 color = tex2D( RFX_backbufferColor, texcoord );
	#endif
	
	#if GaussBloomWarmth == 1
	color.rgb = lerp(color.rgb,dot(color.rgb, CoefLuma_G),-0.2);
	#else
	color.rgb = lerp(color.rgb,dot(color.rgb, CoefLuma_G),0.5);
	#endif
	
	color.rgb *= float3(BloomRed,BloomGreen,BloomBlue);
	
	color.rgb *= ( 1.0f + ( color.rgb / ( GaussThreshold * GaussThreshold ) ) );
	color.rgb *= 0.1800 / ( 0.051 );
    color.rgb -= 5.0f;

    color.rgb = max( color.rgb, 0.0f );

    color.rgb /= ( GaussExposure*0.1 + color.rgb ); 
	
	color.rgb = DoToneMap(color.rgb);
	
	return color;
}

float4 HBloomBlurPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
  
	float sampleOffsets[5] = { 0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130 };
	float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
	#if BloomTexScale >= 1 
	float4 color = tex2D(BBlurSamplerPing, texcoord) * sampleWeights[0];
	[loop]
	for(int i = 1; i < 5; ++i) {
		color += tex2D(BBlurSamplerPing, texcoord + float2(sampleOffsets[i] * RFX_PixelSize.x, 0.0)) * sampleWeights[i];
		color += tex2D(BBlurSamplerPing, texcoord - float2(sampleOffsets[i] * RFX_PixelSize.x, 0.0)) * sampleWeights[i]; 
	}
	#else
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int i = 1; i < 5; ++i) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(sampleOffsets[i] * RFX_PixelSize.x, 0.0)) * sampleWeights[i];
		color += tex2D(RFX_backbufferColor, texcoord - float2(sampleOffsets[i] * RFX_PixelSize.x, 0.0)) * sampleWeights[i]; 
	}
	#endif
	return color;
}

float4 VBloomBlurPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
  
	float sampleOffsets[5] = { 0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130 };
	float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
	#if BloomTexScale != 0
	float4 color = tex2D(BBlurSamplerPong, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(BBlurSamplerPong, texcoord + float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
		color += tex2D(BBlurSamplerPong, texcoord - float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
	}
	#else
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
		color += tex2D(RFX_backbufferColor, texcoord - float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
	}
	#endif
	return color;
}

float4 V2BloomBlurPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
  
	float sampleOffsets[5] = { 0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130 };
	float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
	#if BloomTexScale >= 1
	float4 color = tex2D(BBlurSamplerPong, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(BBlurSamplerPong, texcoord + float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
		color += tex2D(BBlurSamplerPong, texcoord - float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
	}
	#else
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
		color += tex2D(RFX_backbufferColor, texcoord - float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
	}
	#endif
	return color;
}

float4 H2BloomBlurPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{
  
	float sampleOffsets[5] = { 0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130 };
	float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
	#if BloomTexScale != 0
	float4 color = tex2D(BBlurSamplerPing, texcoord) * sampleWeights[0];
	[loop]
	for(int i = 1; i < 5; ++i) {
		color += tex2D(BBlurSamplerPing, texcoord + float2(sampleOffsets[i] * Bpx_size.x, 0.0)) * sampleWeights[i];
		color += tex2D(BBlurSamplerPing, texcoord - float2(sampleOffsets[i] * Bpx_size.x, 0.0)) * sampleWeights[i]; 
	}
	#else 
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int i = 1; i < 5; ++i) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(sampleOffsets[i] * Bpx_size.x, 0.0)) * sampleWeights[i];
		color += tex2D(RFX_backbufferColor, texcoord - float2(sampleOffsets[i] * Bpx_size.x, 0.0)) * sampleWeights[i]; 
	}
	#endif
	return color;
}

float4 FinalBloomPS(in float4 pos : SV_Position, in float2 texcoord : TEXCOORD) : COLOR
{

	float sampleOffsets[5] = { 0.0, 1.4347826, 3.3478260, 5.2608695, 7.1739130 };
	float sampleWeights[5] = { 0.16818994, 0.27276957, 0.11690125, 0.024067905, 0.0021112196 };
	#if BloomTexScale != 0
	#if BloomQuality >= 1
	float4 color = tex2D(BBlurSamplerPong, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(BBlurSamplerPong, texcoord + float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
		color += tex2D(BBlurSamplerPong, texcoord - float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
	}
	float4 orig = tex2D(RFX_backbufferColor, texcoord); //Original Image
	#else 
	float4 color = tex2D(BBlurSamplerPong, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(BBlurSamplerPong, texcoord + float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
		color += tex2D(BBlurSamplerPong, texcoord - float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
	}
	float4 orig = tex2D(RFX_backbufferColor, texcoord); //Original Image
	#endif
	#else
	#if BloomQuality >= 1
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
		color += tex2D(RFX_backbufferColor, texcoord - float2(0.0, sampleOffsets[j] * Bpx_size.y)) * sampleWeights[j];
	}
	float4 orig = tex2D(GBlurSamplerPing, texcoord); //Original Image
	#else
	float4 color = tex2D(RFX_backbufferColor, texcoord) * sampleWeights[0];
	[loop]
	for(int j = 1; j < 5; ++j) {
		color += tex2D(RFX_backbufferColor, texcoord + float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
		color += tex2D(RFX_backbufferColor, texcoord - float2(0.0, sampleOffsets[j] * RFX_PixelSize.y)) * sampleWeights[j];
	}
	float4 orig = tex2D(GBlurSamplerPing, texcoord); //Original Image
	#endif
	#endif
			#define BloomDebug 0
		
		#if (GaussBloomWarmth == 0)
			#if BloomDebug == 1 
			orig = (1.0 - ((1.0 - orig) * (1.0 - (pow(abs(color*2.3),2.5))*0.3)));
			#else
			//orig = lerp(orig, (1.0 - ((1.0 - orig) * (1.0 - (pow(abs(color*2.3),2.5))*0.3))), BloomStrength);
			orig = lerp(orig, (1.0 - ((0.95 - orig) * (1.05 - (pow(abs(color*2.6),2.5))*0.3))), BloomStrength);
			#endif
		#elif (GaussBloomWarmth == 1)
			#if BloomDebug == 1 
			orig = (1.0 - ((1.05 - orig) * (0.95 - (pow(abs(color*2.6),2.5))*0.3)));
			#else
			orig = lerp(orig, (1.0 - ((1.05 - orig) * (0.95 - (pow(abs(color*2.6),2.5))*0.3))), BloomStrength);
			//orig = lerp(orig, (1.0 - ((1.0 - orig) * (1.00 - (pow(abs(color*2.6),2.5))*0.3))), BloomStrength);
			#endif
		#else
			#if BloomDebug == 1 
			orig = (1.0 - ((1.0 - orig) * (1.0 - (color)))), BloomStrength);
			#else
			orig = lerp(orig, (1.0 - ((1.0 - orig) * (1.0 - (color)))), BloomStrength);  // Foggy bloom
			#endif
		#endif 
		
	return saturate(orig);
}
#endif

technique Gaussian_Tech <bool enabled = RFX_Start_Enabled; int toggle = Gaussian_ToggleKey; >
{
#if Use_Unsharpmask == 1 || Use_GaussianBlur == 1
	pass H1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = GOriginalPixel;
		RenderTarget = GBlurTex2Dping;
	}

	pass H1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = HGaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}

#if GaussQuality >= 1
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = VGaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussQuality >= 2
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussQuality >= 3	
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussQuality >= 4
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussQuality >= 5	
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussQuality >= 6	
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussQuality >= 7	
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussQuality >= 8	
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussQuality >= 9
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussQuality >= 10	
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussQuality >= 11	
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussQuality >= 12
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2GaussianBlurPS;
		#if GaussTexScale != 0
		RenderTarget = GBlurTex2Dpong;
		#endif
	}
#endif
	pass VFinal
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = GaussianBlurFinalPS;
	}
#endif
#if Use_GaussianBloom == 1

	pass H1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = GOriginalPixel;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#else
		RenderTarget = GBlurTex2Dping;
		#endif
	}

	pass GD
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = GlareDetectionPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
	
	pass H1Bloom
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = HBloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
		
#if GaussBloomQuality >= 1
	pass V1
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = VBloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
	
	pass H2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussBloomQuality >= 2
	pass V2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
	
	pass H3
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussBloomQuality >= 3
	pass V3
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
		
	pass H4
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussBloomQuality >= 4
	pass V4
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}	
	
	pass H5
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussBloomQuality >= 5	
	pass V5
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
	
	pass H6
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussBloomQuality >= 6
	pass V2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
	
	pass H3
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussBloomQuality >= 7	
	pass V2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
	
	pass H3
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussBloomQuality >= 8
	pass V2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
	
	pass H3
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussBloomQuality >= 9
	pass V2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
	
	pass H3
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussBloomQuality >= 10	
	pass V2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
	
	pass H3
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussBloomQuality >= 11	
	pass V2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
	
	pass H3
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif	
#if GaussBloomQuality >= 12
	pass V2
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = V2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dping;
		#endif
	}
	
	pass H3
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = H2BloomBlurPS;
		#if BloomTexScale != 0
		RenderTarget = BBlurTex2Dpong;
		#endif
	}
#endif
	
	pass VFinal
	{
		VertexShader = RFX_VS_PostProcess;
		PixelShader = FinalBloomPS;
	}
#endif
}
#endif

#include CFX_SETTINGS_UNDEF

NAMESPACE_LEAVE()
The administrator has disabled public write access.

2x same shader/shader to brighten dark. 1 year 4 months ago #12

Might there be some other way in raising the shadow/darkness a little without using liftgammagains "liftxyz".
A way that raises shadow/darkness contrast maybe, and not shadow brightness that grays it out and kills black level.
The way that a little low strength, low threshold(0,015) and low quality bloom can do?
Bloom for that job is not ideal but works quite ok. If you understand what I mean.

And about a donation I want to give for this great shader program and shaders, Is there a way I could donate to the whole project in one go?
Thanks again for your time:)
The administrator has disabled public write access.

2x same shader/shader to brighten dark. 1 year 4 months ago #13

  • Ioxa
  • Ioxa's Avatar
  • Offline
  • Posts: 296
  • Thank you received: 292
Here you go.GaussBloom

Since you're only using the bloom I got rid of the other stuff to make it a little easier.

Add these lines to CustomFX.cfg.
Warning: Spoiler! [ Click to expand ]


And this line to Pipeline.cfg.
#include EFFECT(CustomFX, GaussianBloom)
Last Edit: 1 year 4 months ago by Ioxa.
The administrator has disabled public write access.
The following user(s) said Thank You: Flygesoppen

2x same shader/shader to brighten dark. 1 year 4 months ago #14

Thank you very much:)

But ohh my god, now I have this error message when game starts:
... /ReShade/CustomFX/GaussianBloom.h(103, 20): error X3004: undeclared identifier 'FilmicTonemap'

There must be something else wrong I think..
I will write down my settings for the game, delete everything reshade
and reinstall it when I get home from a little walk, then try again.

But again thanks for this!
The administrator has disabled public write access.

2x same shader/shader to brighten dark. 1 year 4 months ago #15

  • Ioxa
  • Ioxa's Avatar
  • Offline
  • Posts: 296
  • Thank you received: 292
Whoops, I somehow uploaded the wrong file. I fixed it and edited the link, try it again.
The administrator has disabled public write access.

2x same shader/shader to brighten dark. 1 year 4 months ago #16

Yes! it kinda worked somehow:) But there is strangeness going on!
The image looks almost like some sort of nightmarish dream or something.
Non of the settings for this gauss change the horror im seeing on screen.
And the GaussBloom TexScale setting chrashes reshade if set to "0"
Do you know how I can change it so it looks more like normal gaussbloom?

This is how it looks with the new gaussbloom:
http://postimg.org/image/a9q4x64nv/

When it should look more like this:
http://postimg.org/image/9yd9y5dln/
The administrator has disabled public write access.

2x same shader/shader to brighten dark. 1 year 4 months ago #17

  • Ioxa
  • Ioxa's Avatar
  • Offline
  • Posts: 296
  • Thank you received: 292
Haha, I screwed up again. Its ok though, these are easy to fix.

Open GaussianBloom.h and scroll down to line 53, it looks like this.
#if GaussBloomTexScale != 0
Delete it.

Now go to line 67, it'll say
#endif
Delete it.

Now scroll down to line 229, it says this,
orig = color;
Delete it.

Save the file and you should be good to go.

EDIT: And if you don't feel like doing that just redownload the file, I figured I'd upload the fixed version since I fixed it to test it.
Last Edit: 1 year 4 months ago by Ioxa.
The administrator has disabled public write access.
The following user(s) said Thank You: Flygesoppen

2x same shader/shader to brighten dark. 1 year 4 months ago #18

Ahh finally:) Thank yous! Now it works as it should.
Wow this has been quite a long ride from the start to the end.
This many posts to aid a poor helpless creature hehe:)

Thanks so much to Ioxa for the main conclusion and to Ganossa and Crosire
who gave me an introduction in modifying some reshade scripts that I don't quite understand "yet".
But hopefully one day will.. Me be very grateful:)

Now back to tweaking !

Again, don't know if I should write about this in the forum..
But how can one donate to the creative people in this project?

Thanks:)
The administrator has disabled public write access.