mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-25 15:15:40 +00:00
Add some shaders and update others. (#3234)
- Add fxaa.fx, aa-shader-40.fx, bilateral.fx; - Update geom.fx, crt-geom.fx, bicubic.fx, lanczos3.fx, super-xbr.fx.
This commit is contained in:
parent
ebf50edb79
commit
ad27f8bac3
|
@ -0,0 +1,104 @@
|
|||
#include "ReShade.fxh"
|
||||
|
||||
/*
|
||||
Copyright (C) 2016 guest(r) - guest.r@gmail.com
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
uniform float2 NormalizedNativePixelSize < source = "normalized_native_pixel_size"; >;
|
||||
|
||||
sampler2D sBackBuffer{Texture=ReShade::BackBufferTex;AddressU=CLAMP;AddressV=CLAMP;AddressW=CLAMP;MagFilter=POINT;MinFilter=POINT;};
|
||||
|
||||
static const float3 dt = float3(1.0,1.0,1.0);
|
||||
|
||||
float3 texture2d(sampler2D tex, float2 coord, float4 yx) {
|
||||
|
||||
float3 s00 = tex2D(tex, coord + yx.zw).xyz;
|
||||
float3 s20 = tex2D(tex, coord + yx.xw).xyz;
|
||||
float3 s22 = tex2D(tex, coord + yx.xy).xyz;
|
||||
float3 s02 = tex2D(tex, coord + yx.zy).xyz;
|
||||
|
||||
float m1=dot(abs(s00-s22),dt)+0.001;
|
||||
float m2=dot(abs(s02-s20),dt)+0.001;
|
||||
|
||||
return 0.5*(m2*(s00+s22)+m1*(s02+s20))/(m1+m2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
float4 PS_aa_shader_40(float4 vpos: SV_Position, float2 vTexCoord : TEXCOORD0) : SV_Target
|
||||
{
|
||||
// Calculating texel coordinates
|
||||
float2 size = 4.0 / NormalizedNativePixelSize;
|
||||
float2 inv_size = 1.0 / size;
|
||||
|
||||
float4 yx = float4(inv_size, -inv_size);
|
||||
|
||||
float2 OGL2Pos = vTexCoord * size;
|
||||
|
||||
float2 fp = frac(OGL2Pos);
|
||||
float2 dx = float2(inv_size.x,0.0);
|
||||
float2 dy = float2(0.0, inv_size.y);
|
||||
float2 g1 = float2(inv_size.x,inv_size.y);
|
||||
float2 g2 = float2(-inv_size.x,inv_size.y);
|
||||
|
||||
float2 pC4 = floor(OGL2Pos) * 1.0001 * inv_size;
|
||||
|
||||
// Reading the texels
|
||||
float3 C1 = texture2d(sBackBuffer, pC4 - dy, yx);
|
||||
float3 C0 = texture2d(sBackBuffer, pC4 - g1, yx);
|
||||
float3 C2 = texture2d(sBackBuffer, pC4 - g2, yx);
|
||||
float3 C3 = texture2d(sBackBuffer, pC4 - dx, yx);
|
||||
float3 C4 = texture2d(sBackBuffer, pC4 , yx);
|
||||
float3 C5 = texture2d(sBackBuffer, pC4 + dx, yx);
|
||||
float3 C6 = texture2d(sBackBuffer, pC4 + g2, yx);
|
||||
float3 C7 = texture2d(sBackBuffer, pC4 + dy, yx);
|
||||
float3 C8 = texture2d(sBackBuffer, pC4 + g1, yx);
|
||||
|
||||
float3 ul, ur, dl, dr;
|
||||
float m1, m2;
|
||||
|
||||
m1 = dot(abs(C0-C4),dt)+0.001;
|
||||
m2 = dot(abs(C1-C3),dt)+0.001;
|
||||
ul = (m2*(C0+C4)+m1*(C1+C3))/(m1+m2);
|
||||
|
||||
m1 = dot(abs(C1-C5),dt)+0.001;
|
||||
m2 = dot(abs(C2-C4),dt)+0.001;
|
||||
ur = (m2*(C1+C5)+m1*(C2+C4))/(m1+m2);
|
||||
|
||||
m1 = dot(abs(C3-C7),dt)+0.001;
|
||||
m2 = dot(abs(C6-C4),dt)+0.001;
|
||||
dl = (m2*(C3+C7)+m1*(C6+C4))/(m1+m2);
|
||||
|
||||
m1 = dot(abs(C4-C8),dt)+0.001;
|
||||
m2 = dot(abs(C5-C7),dt)+0.001;
|
||||
dr = (m2*(C4+C8)+m1*(C5+C7))/(m1+m2);
|
||||
|
||||
float3 c11 = 0.5*((dr*fp.x+dl*(1-fp.x))*fp.y+(ur*fp.x+ul*(1-fp.x))*(1-fp.y) );
|
||||
|
||||
return float4(c11, 1.0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
technique aa_shader_40
|
||||
{
|
||||
pass
|
||||
{
|
||||
VertexShader = PostProcessVS;
|
||||
PixelShader = PS_aa_shader_40;
|
||||
}
|
||||
}
|
271
data/resources/shaders/reshade/Shaders/anti-aliasing/fxaa.fx
Normal file
271
data/resources/shaders/reshade/Shaders/anti-aliasing/fxaa.fx
Normal file
|
@ -0,0 +1,271 @@
|
|||
#include "ReShade.fxh"
|
||||
|
||||
|
||||
/**
|
||||
* @license
|
||||
* Copyright (c) 2011 NVIDIA Corporation. All rights reserved.
|
||||
*
|
||||
* TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED
|
||||
* *AS IS* AND NVIDIA AND ITS SUPPLIERS DISCLAIM ALL WARRANTIES, EITHER EXPRESS
|
||||
* OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, NONINFRINGEMENT,IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL NVIDIA
|
||||
* OR ITS SUPPLIERS BE LIABLE FOR ANY DIRECT, SPECIAL, INCIDENTAL, INDIRECT, OR
|
||||
* CONSEQUENTIAL DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS
|
||||
* OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY
|
||||
* OTHER PECUNIARY LOSS) ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
|
||||
* EVEN IF NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
||||
*/
|
||||
|
||||
/*
|
||||
FXAA_PRESET - Choose compile-in knob preset 0-5.
|
||||
------------------------------------------------------------------------------
|
||||
FXAA_EDGE_THRESHOLD - The minimum amount of local contrast required
|
||||
to apply algorithm.
|
||||
1.0/3.0 - too little
|
||||
1.0/4.0 - good start
|
||||
1.0/8.0 - applies to more edges
|
||||
1.0/16.0 - overkill
|
||||
------------------------------------------------------------------------------
|
||||
FXAA_EDGE_THRESHOLD_MIN - Trims the algorithm from processing darks.
|
||||
Perf optimization.
|
||||
1.0/32.0 - visible limit (smaller isn't visible)
|
||||
1.0/16.0 - good compromise
|
||||
1.0/12.0 - upper limit (seeing artifacts)
|
||||
------------------------------------------------------------------------------
|
||||
FXAA_SEARCH_STEPS - Maximum number of search steps for end of span.
|
||||
------------------------------------------------------------------------------
|
||||
FXAA_SEARCH_THRESHOLD - Controls when to stop searching.
|
||||
1.0/4.0 - seems to be the best quality wise
|
||||
------------------------------------------------------------------------------
|
||||
FXAA_SUBPIX_TRIM - Controls sub-pixel aliasing removal.
|
||||
1.0/2.0 - low removal
|
||||
1.0/3.0 - medium removal
|
||||
1.0/4.0 - default removal
|
||||
1.0/8.0 - high removal
|
||||
0.0 - complete removal
|
||||
------------------------------------------------------------------------------
|
||||
FXAA_SUBPIX_CAP - Insures fine detail is not completely removed.
|
||||
This is important for the transition of sub-pixel detail,
|
||||
like fences and wires.
|
||||
3.0/4.0 - default (medium amount of filtering)
|
||||
7.0/8.0 - high amount of filtering
|
||||
1.0 - no capping of sub-pixel aliasing removal
|
||||
*/
|
||||
|
||||
|
||||
uniform float2 BufferToViewportRatio < source = "buffer_to_viewport_ratio"; >;
|
||||
uniform float2 ViewportSize < source = "viewportsize"; >;
|
||||
|
||||
sampler2D sBackBuffer{Texture=ReShade::BackBufferTex;AddressU=CLAMP;AddressV=CLAMP;AddressW=CLAMP;MagFilter=LINEAR;MinFilter=LINEAR;};
|
||||
|
||||
|
||||
#ifndef FXAA_PRESET
|
||||
#define FXAA_PRESET 6
|
||||
#endif
|
||||
#if (FXAA_PRESET == 3)
|
||||
#define FXAA_EDGE_THRESHOLD (1.0/8.0)
|
||||
#define FXAA_EDGE_THRESHOLD_MIN (1.0/16.0)
|
||||
#define FXAA_SEARCH_STEPS 16
|
||||
#define FXAA_SEARCH_THRESHOLD (1.0/4.0)
|
||||
#define FXAA_SUBPIX_CAP (3.0/4.0)
|
||||
#define FXAA_SUBPIX_TRIM (1.0/4.0)
|
||||
#endif
|
||||
#if (FXAA_PRESET == 4)
|
||||
#define FXAA_EDGE_THRESHOLD (1.0/8.0)
|
||||
#define FXAA_EDGE_THRESHOLD_MIN (1.0/24.0)
|
||||
#define FXAA_SEARCH_STEPS 24
|
||||
#define FXAA_SEARCH_THRESHOLD (1.0/4.0)
|
||||
#define FXAA_SUBPIX_CAP (3.0/4.0)
|
||||
#define FXAA_SUBPIX_TRIM (1.0/4.0)
|
||||
#endif
|
||||
#if (FXAA_PRESET == 5)
|
||||
#define FXAA_EDGE_THRESHOLD (1.0/8.0)
|
||||
#define FXAA_EDGE_THRESHOLD_MIN (1.0/24.0)
|
||||
#define FXAA_SEARCH_STEPS 32
|
||||
#define FXAA_SEARCH_THRESHOLD (1.0/4.0)
|
||||
#define FXAA_SUBPIX_CAP (3.0/4.0)
|
||||
#define FXAA_SUBPIX_TRIM (1.0/4.0)
|
||||
#endif
|
||||
#if (FXAA_PRESET == 6)
|
||||
#define FXAA_EDGE_THRESHOLD (1.0/8.0)
|
||||
#define FXAA_EDGE_THRESHOLD_MIN (1.0/24.0)
|
||||
#define FXAA_SEARCH_STEPS 32
|
||||
#define FXAA_SEARCH_THRESHOLD (1.0/4.0)
|
||||
#define FXAA_SUBPIX_CAP (1.0)
|
||||
#define FXAA_SUBPIX_TRIM (0.0)
|
||||
#endif
|
||||
|
||||
#define FXAA_SUBPIX_TRIM_SCALE (1.0/(1.0 - FXAA_SUBPIX_TRIM))
|
||||
|
||||
// Return the luma, the estimation of luminance from rgb inputs.
|
||||
// This approximates luma using one FMA instruction,
|
||||
// skipping normalization and tossing out blue.
|
||||
// FxaaLuma() will range 0.0 to 2.963210702.
|
||||
float FxaaLuma(float3 rgb) {
|
||||
return rgb.y * (0.587/0.299) + rgb.x;
|
||||
}
|
||||
|
||||
float3 FxaaLerp3(float3 a, float3 b, float amountOfA) {
|
||||
return (-float3(amountOfA, amountOfA, amountOfA) * b) + ((a * float3(amountOfA, amountOfA, amountOfA)) + b);
|
||||
}
|
||||
|
||||
float4 FxaaTexOff(sampler2D tex, float2 pos, int2 off, float2 rcpFrame) {
|
||||
float x = pos.x + float(off.x) * rcpFrame.x;
|
||||
float y = pos.y + float(off.y) * rcpFrame.y;
|
||||
return tex2D(tex, float2(x, y));
|
||||
}
|
||||
|
||||
// pos is the output of FxaaVertexShader interpolated across screen.
|
||||
// xy -> actual texture position {0.0 to 1.0}
|
||||
// rcpFrame should be a uniform equal to {1.0/frameWidth, 1.0/frameHeight}
|
||||
float3 FxaaPixelShader(float2 pos, sampler2D tex, float2 rcpFrame)
|
||||
{
|
||||
float3 rgbN = FxaaTexOff(tex, pos.xy, int2( 0,-1), rcpFrame).xyz;
|
||||
float3 rgbW = FxaaTexOff(tex, pos.xy, int2(-1, 0), rcpFrame).xyz;
|
||||
float3 rgbM = FxaaTexOff(tex, pos.xy, int2( 0, 0), rcpFrame).xyz;
|
||||
float3 rgbE = FxaaTexOff(tex, pos.xy, int2( 1, 0), rcpFrame).xyz;
|
||||
float3 rgbS = FxaaTexOff(tex, pos.xy, int2( 0, 1), rcpFrame).xyz;
|
||||
|
||||
float lumaN = FxaaLuma(rgbN);
|
||||
float lumaW = FxaaLuma(rgbW);
|
||||
float lumaM = FxaaLuma(rgbM);
|
||||
float lumaE = FxaaLuma(rgbE);
|
||||
float lumaS = FxaaLuma(rgbS);
|
||||
float rangeMin = min(lumaM, min(min(lumaN, lumaW), min(lumaS, lumaE)));
|
||||
float rangeMax = max(lumaM, max(max(lumaN, lumaW), max(lumaS, lumaE)));
|
||||
|
||||
float range = rangeMax - rangeMin;
|
||||
if(range < max(FXAA_EDGE_THRESHOLD_MIN, rangeMax * FXAA_EDGE_THRESHOLD))
|
||||
{
|
||||
return rgbM;
|
||||
}
|
||||
|
||||
float3 rgbL = rgbN + rgbW + rgbM + rgbE + rgbS;
|
||||
|
||||
float lumaL = (lumaN + lumaW + lumaE + lumaS) * 0.25;
|
||||
float rangeL = abs(lumaL - lumaM);
|
||||
float blendL = max(0.0, (rangeL / range) - FXAA_SUBPIX_TRIM) * FXAA_SUBPIX_TRIM_SCALE;
|
||||
blendL = min(FXAA_SUBPIX_CAP, blendL);
|
||||
|
||||
float3 rgbNW = FxaaTexOff(tex, pos.xy, int2(-1,-1), rcpFrame).xyz;
|
||||
float3 rgbNE = FxaaTexOff(tex, pos.xy, int2( 1,-1), rcpFrame).xyz;
|
||||
float3 rgbSW = FxaaTexOff(tex, pos.xy, int2(-1, 1), rcpFrame).xyz;
|
||||
float3 rgbSE = FxaaTexOff(tex, pos.xy, int2( 1, 1), rcpFrame).xyz;
|
||||
rgbL += (rgbNW + rgbNE + rgbSW + rgbSE);
|
||||
rgbL *= (1.0/float3(9.0, 9.0, 9.0));
|
||||
|
||||
float lumaNW = FxaaLuma(rgbNW);
|
||||
float lumaNE = FxaaLuma(rgbNE);
|
||||
float lumaSW = FxaaLuma(rgbSW);
|
||||
float lumaSE = FxaaLuma(rgbSE);
|
||||
|
||||
float edgeVert =
|
||||
abs((0.25 * lumaNW) + (-0.5 * lumaN) + (0.25 * lumaNE)) +
|
||||
abs((0.50 * lumaW ) + (-1.0 * lumaM) + (0.50 * lumaE )) +
|
||||
abs((0.25 * lumaSW) + (-0.5 * lumaS) + (0.25 * lumaSE));
|
||||
float edgeHorz =
|
||||
abs((0.25 * lumaNW) + (-0.5 * lumaW) + (0.25 * lumaSW)) +
|
||||
abs((0.50 * lumaN ) + (-1.0 * lumaM) + (0.50 * lumaS )) +
|
||||
abs((0.25 * lumaNE) + (-0.5 * lumaE) + (0.25 * lumaSE));
|
||||
|
||||
bool horzSpan = edgeHorz >= edgeVert;
|
||||
float lengthSign = horzSpan ? -rcpFrame.y : -rcpFrame.x;
|
||||
|
||||
if(!horzSpan)
|
||||
{
|
||||
lumaN = lumaW;
|
||||
lumaS = lumaE;
|
||||
}
|
||||
|
||||
float gradientN = abs(lumaN - lumaM);
|
||||
float gradientS = abs(lumaS - lumaM);
|
||||
lumaN = (lumaN + lumaM) * 0.5;
|
||||
lumaS = (lumaS + lumaM) * 0.5;
|
||||
|
||||
if (gradientN < gradientS)
|
||||
{
|
||||
lumaN = lumaS;
|
||||
lumaN = lumaS;
|
||||
gradientN = gradientS;
|
||||
lengthSign *= -1.0;
|
||||
}
|
||||
|
||||
float2 posN;
|
||||
posN.x = pos.x + (horzSpan ? 0.0 : lengthSign * 0.5);
|
||||
posN.y = pos.y + (horzSpan ? lengthSign * 0.5 : 0.0);
|
||||
|
||||
gradientN *= FXAA_SEARCH_THRESHOLD;
|
||||
|
||||
float2 posP = posN;
|
||||
float2 offNP = horzSpan ? float2(rcpFrame.x, 0.0) : float2(0.0, rcpFrame.y);
|
||||
float lumaEndN = lumaN;
|
||||
float lumaEndP = lumaN;
|
||||
bool doneN = false;
|
||||
bool doneP = false;
|
||||
posN += offNP * float2(-1.0, -1.0);
|
||||
posP += offNP * float2( 1.0, 1.0);
|
||||
|
||||
for(int i = 0; i < FXAA_SEARCH_STEPS; i++) {
|
||||
if(!doneN)
|
||||
{
|
||||
lumaEndN = FxaaLuma(tex2D(tex, posN.xy).xyz);
|
||||
}
|
||||
if(!doneP)
|
||||
{
|
||||
lumaEndP = FxaaLuma(tex2D(tex, posP.xy).xyz);
|
||||
}
|
||||
|
||||
doneN = doneN || (abs(lumaEndN - lumaN) >= gradientN);
|
||||
doneP = doneP || (abs(lumaEndP - lumaN) >= gradientN);
|
||||
|
||||
if(doneN && doneP)
|
||||
{
|
||||
break;
|
||||
}
|
||||
if(!doneN)
|
||||
{
|
||||
posN -= offNP;
|
||||
}
|
||||
if(!doneP)
|
||||
{
|
||||
posP += offNP;
|
||||
}
|
||||
}
|
||||
|
||||
float dstN = horzSpan ? pos.x - posN.x : pos.y - posN.y;
|
||||
float dstP = horzSpan ? posP.x - pos.x : posP.y - pos.y;
|
||||
bool directionN = dstN < dstP;
|
||||
lumaEndN = directionN ? lumaEndN : lumaEndP;
|
||||
|
||||
if(((lumaM - lumaN) < 0.0) == ((lumaEndN - lumaN) < 0.0))
|
||||
{
|
||||
lengthSign = 0.0;
|
||||
}
|
||||
|
||||
|
||||
float spanLength = (dstP + dstN);
|
||||
dstN = directionN ? dstN : dstP;
|
||||
float subPixelOffset = (0.5 + (dstN * (-1.0/spanLength))) * lengthSign;
|
||||
float3 rgbF = tex2D(tex, float2(
|
||||
pos.x + (horzSpan ? 0.0 : subPixelOffset),
|
||||
pos.y + (horzSpan ? subPixelOffset : 0.0))).xyz;
|
||||
return FxaaLerp3(rgbL, rgbF, blendL);
|
||||
}
|
||||
|
||||
float4 PS_FXAA(float4 vpos: SV_Position, float2 vTexCoord : TEXCOORD0) : SV_Target
|
||||
{
|
||||
float3 color = FxaaPixelShader(vTexCoord, sBackBuffer, 1.0 / (ViewportSize*BufferToViewportRatio));
|
||||
|
||||
return float4(color, 1.0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
technique FXAA
|
||||
{
|
||||
pass
|
||||
{
|
||||
VertexShader = PostProcessVS;
|
||||
PixelShader = PS_FXAA;
|
||||
}
|
||||
}
|
|
@ -183,6 +183,7 @@ uniform float2 NormalizedNativePixelSize < source = "normalized_native_pixel_siz
|
|||
uniform float UpscaleMultiplier < source = "upscale_multiplier"; >;
|
||||
uniform float2 ViewportSize < source = "viewportsize"; >;
|
||||
|
||||
sampler2D sBackBuffer{Texture=ReShade::BackBufferTex;AddressU=BORDER;AddressV=BORDER;AddressW=BORDER;MagFilter=POINT;MinFilter=POINT;};
|
||||
|
||||
// Comment the next line to disable interpolation in linear gamma (and
|
||||
// gain speed).
|
||||
|
@ -199,9 +200,9 @@ uniform float2 ViewportSize < source = "viewportsize"; >;
|
|||
#define PI 3.141592653589
|
||||
|
||||
#ifdef LINEAR_PROCESSING
|
||||
# define TEX2D(c) pow(tex2D(ReShade::BackBuffer, (c)), float4(CRTgamma,CRTgamma,CRTgamma,CRTgamma))
|
||||
# define TEX2D(c) pow(tex2D(sBackBuffer, (c)), float4(CRTgamma,CRTgamma,CRTgamma,CRTgamma))
|
||||
#else
|
||||
# define TEX2D(c) tex2D(ReShade::BackBuffer, (c))
|
||||
# define TEX2D(c) tex2D(sBackBuffer, (c))
|
||||
#endif
|
||||
|
||||
// aspect ratio
|
||||
|
|
166
data/resources/shaders/reshade/Shaders/denoisers/bilateral.fx
Normal file
166
data/resources/shaders/reshade/Shaders/denoisers/bilateral.fx
Normal file
|
@ -0,0 +1,166 @@
|
|||
#include "ReShade.fxh"
|
||||
|
||||
/*
|
||||
Bilateral - Smart
|
||||
|
||||
Copyright (C) 2024 guest(r)
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
uniform float FRANGE <
|
||||
ui_type = "drag";
|
||||
ui_min = 1.0;
|
||||
ui_max = 10.0;
|
||||
ui_step = 1.0;
|
||||
ui_label = "Filter Range";
|
||||
> = 5.0;
|
||||
|
||||
uniform float FBSMOOTH <
|
||||
ui_type = "drag";
|
||||
ui_min = 0.05;
|
||||
ui_max = 1.0;
|
||||
ui_step = 0.025;
|
||||
ui_label = "Filter Base Smoothing";
|
||||
> = 0.3;
|
||||
|
||||
uniform float FSIGMA <
|
||||
ui_type = "drag";
|
||||
ui_min = 0.15;
|
||||
ui_max = 1.5;
|
||||
ui_step = 0.05;
|
||||
ui_label = "Filter Strength";
|
||||
> = 1.0;
|
||||
|
||||
uniform float2 NormalizedNativePixelSize < source = "normalized_native_pixel_size"; >;
|
||||
uniform float2 BufferToViewportRatio < source = "buffer_to_viewport_ratio"; >;
|
||||
uniform float2 ViewportSize < source = "viewportsize"; >;
|
||||
|
||||
sampler2D sBackBuffer{Texture=ReShade::BackBufferTex;AddressU=CLAMP;AddressV=CLAMP;AddressW=CLAMP;MagFilter=POINT;MinFilter=POINT;};
|
||||
|
||||
texture2D tBilateral_P0{Width=BUFFER_WIDTH;Height=BUFFER_HEIGHT;Format=RGBA8;};
|
||||
sampler2D sBilateral_P0{Texture=tBilateral_P0;AddressU=CLAMP;AddressV=CLAMP;AddressW=CLAMP;MagFilter=POINT;MinFilter=POINT;};
|
||||
|
||||
#define FSIGMA1 (1.0/FSIGMA)
|
||||
|
||||
#define COMPAT_TEXTURE(c,d) tex2D(c,d)
|
||||
|
||||
float wt(float3 A, float3 B)
|
||||
{
|
||||
return clamp(FBSMOOTH - 2.33*dot(abs(A-B),1.0.xxx)/(dot(A+B,1.0.xxx)+1.0), 0.0, 0.25);
|
||||
}
|
||||
|
||||
|
||||
float getw(float x, float3 c, float3 p)
|
||||
{
|
||||
float y = pow(max(1.0-x,0.0), FSIGMA1);
|
||||
float d = wt(c,p);
|
||||
return y*d;
|
||||
}
|
||||
|
||||
|
||||
|
||||
float4 PS_Bilateral_X(float4 position: SV_Position, float2 vTexCoord : TEXCOORD) : SV_Target
|
||||
{
|
||||
float4 SourceSize = float4((ViewportSize*BufferToViewportRatio), 1.0/(ViewportSize*BufferToViewportRatio));
|
||||
// float4 SourceSize = float4(1.0/NormalizedNativePixelSize, NormalizedNativePixelSize);
|
||||
float2 pos = vTexCoord * SourceSize.xy;
|
||||
float f = 0.5-frac(pos.x);
|
||||
float2 tex = floor(pos)*SourceSize.zw + 0.5*SourceSize.zw;
|
||||
float2 dx = float2(SourceSize.z, 0.0);
|
||||
|
||||
float w, fp;
|
||||
float wsum = 0.0;
|
||||
float3 pixel;
|
||||
float FPR = FRANGE;
|
||||
float FPR1 = 1.0/FPR;
|
||||
float LOOPSIZE = FPR;
|
||||
float x = -FPR;
|
||||
|
||||
float3 comp = COMPAT_TEXTURE(sBackBuffer, tex).rgb;
|
||||
float3 color = 0.0.xxx;
|
||||
|
||||
do
|
||||
{
|
||||
pixel = COMPAT_TEXTURE(sBackBuffer, tex + x*dx).rgb;
|
||||
fp = min(abs(x+f),FPR)*FPR1;
|
||||
w = getw(fp,comp,pixel);
|
||||
color = color + w * pixel;
|
||||
wsum = wsum + w;
|
||||
|
||||
x = x + 1.0;
|
||||
|
||||
} while (x <= LOOPSIZE);
|
||||
|
||||
color = color / wsum;
|
||||
|
||||
return float4(color, 1.0);
|
||||
}
|
||||
|
||||
|
||||
float4 PS_Bilateral_Y(float4 position: SV_Position, float2 vTexCoord : TEXCOORD) : SV_Target
|
||||
{
|
||||
float4 SourceSize = float4((ViewportSize*BufferToViewportRatio), 1.0/(ViewportSize*BufferToViewportRatio));
|
||||
float2 pos = vTexCoord * SourceSize.xy;
|
||||
float f = 0.5-frac(pos.y);
|
||||
float2 tex = floor(pos)*SourceSize.zw + 0.5*SourceSize.zw;
|
||||
float2 dy = float2(0.0, SourceSize.w);
|
||||
|
||||
float w, fp;
|
||||
float wsum = 0.0;
|
||||
float3 pixel;
|
||||
float FPR = FRANGE;
|
||||
float FPR1 = 1.0/FPR;
|
||||
float LOOPSIZE = FPR;
|
||||
float y = -FPR;
|
||||
|
||||
float3 comp = COMPAT_TEXTURE(sBilateral_P0, tex).rgb;
|
||||
float3 color = 0.0.xxx;
|
||||
|
||||
do
|
||||
{
|
||||
pixel = COMPAT_TEXTURE(sBilateral_P0, tex + y*dy).rgb;
|
||||
fp = min(abs(y+f),FPR)*FPR1;
|
||||
w = getw(fp,comp,pixel);
|
||||
color = color + w * pixel;
|
||||
wsum = wsum + w;
|
||||
|
||||
y = y + 1.0;
|
||||
|
||||
} while (y <= LOOPSIZE);
|
||||
|
||||
color = color / wsum;
|
||||
|
||||
return float4(color, 1.0);
|
||||
}
|
||||
|
||||
technique Bilateral
|
||||
{
|
||||
|
||||
pass
|
||||
{
|
||||
VertexShader = PostProcessVS;
|
||||
PixelShader = PS_Bilateral_X;
|
||||
RenderTarget = tBilateral_P0;
|
||||
}
|
||||
pass
|
||||
{
|
||||
VertexShader = PostProcessVS;
|
||||
PixelShader = PS_Bilateral_Y;
|
||||
}
|
||||
|
||||
}
|
|
@ -32,7 +32,7 @@ uniform float XBR_EDGE_STR_P0 <
|
|||
ui_min = 0.0;
|
||||
ui_max = 5.0;
|
||||
ui_step = 0.5;
|
||||
ui_label = "Xbr - Edge Strength p0";
|
||||
ui_label = "Xbr - Edge Strength";
|
||||
> = 5.0;
|
||||
|
||||
uniform float XBR_WEIGHT <
|
||||
|
@ -76,7 +76,7 @@ uniform float2 BufferToViewportRatio < source = "buffer_to_viewport_ratio"; >;
|
|||
uniform float2 NormalizedNativePixelSize < source = "normalized_native_pixel_size"; >;
|
||||
|
||||
texture2D tBackBufferY{Width=BUFFER_WIDTH;Height=BUFFER_HEIGHT;Format=RGBA8;};
|
||||
sampler2D sBackBufferY{Texture=tBackBufferY;AddressU=BORDER;AddressV=BORDER;AddressW=BORDER;MagFilter=POINT;MinFilter=POINT;};
|
||||
sampler2D sBackBufferY{Texture=tBackBufferY;AddressU=CLAMP;AddressV=CLAMP;AddressW=CLAMP;MagFilter=POINT;MinFilter=POINT;};
|
||||
|
||||
texture2D tSuper_xBR_P0 < pooled = true; > {Width=BUFFER_WIDTH;Height=BUFFER_HEIGHT;Format=RGBA8;};
|
||||
sampler2D sSuper_xBR_P0{Texture=tSuper_xBR_P0;AddressU=CLAMP;AddressV=CLAMP;AddressW=CLAMP;MagFilter=POINT;MinFilter=POINT;};
|
||||
|
@ -87,8 +87,11 @@ sampler2D sSuper_xBR_P1{Texture=tSuper_xBR_P1;AddressU=CLAMP;AddressV=CLAMP;Addr
|
|||
texture2D tSuper_xBR_P2 < pooled = true; > {Width=BUFFER_WIDTH;Height=BUFFER_HEIGHT;Format=RGBA8;};
|
||||
sampler2D sSuper_xBR_P2{Texture=tSuper_xBR_P2;AddressU=CLAMP;AddressV=CLAMP;AddressW=CLAMP;MagFilter=POINT;MinFilter=POINT;};
|
||||
|
||||
#define Y float3(.2126,.7152,.0722)
|
||||
#define weight1 (XBR_WEIGHT*1.29633/10.0)
|
||||
#define weight2 (XBR_WEIGHT*1.75068/10.0/2.0)
|
||||
#define limits (XBR_EDGE_STR_P0+0.000001)
|
||||
|
||||
static const float3 Y = float3(.2126,.7152,.0722);
|
||||
static const float wp0[6] = {2.0, 1.0, -1.0, 4.0, -1.0, 1.0};
|
||||
static const float wp1[6] = {1.0, 0.0, 0.0, 0.0, 0.0, 0.0};
|
||||
static const float wp2[6] = {0.0, 0.0, 0.0, 1.0, 0.0, 0.0};
|
||||
|
@ -153,15 +156,11 @@ float3 super_xbr(float wp[6], float4 P0, float4 B, float4 C, float4 P1, float4
|
|||
/* Calc edgeness in horizontal/vertical directions. */
|
||||
float hv_edge = (hv_wd(wp, f, i, e, h, c, i5, b, h5) - hv_wd(wp, e, f, h, i, d, f4, g, i4));
|
||||
|
||||
float limits = XBR_EDGE_STR_P0 + 0.000001;
|
||||
float edge_strength = smoothstep(0.0, limits, abs(d_edge));
|
||||
|
||||
float4 w1, w2;
|
||||
float3 c3, c4;
|
||||
|
||||
float weight1 = (XBR_WEIGHT*1.29633/10.0);
|
||||
float weight2 = (XBR_WEIGHT*1.75068/10.0/2.0);
|
||||
|
||||
/* Filter weights. Two taps only. */
|
||||
w1 = float4(-weight1, weight1+0.50, weight1+0.50, -weight1);
|
||||
w2 = float4(-weight2, weight2+0.25, weight2+0.25, -weight2);
|
||||
|
@ -183,7 +182,7 @@ float3 super_xbr(float wp[6], float4 P0, float4 B, float4 C, float4 P1, float4
|
|||
return color;
|
||||
}
|
||||
|
||||
float4 BackBufferY(float4 pos: SV_Position, float2 vTexCoord : TEXCOORD) : SV_Target
|
||||
float4 PS_BackBufferY(float4 pos: SV_Position, float2 vTexCoord : TEXCOORD) : SV_Target
|
||||
{
|
||||
float3 color = tex2D(ReShade::BackBuffer, vTexCoord.xy).rgb;
|
||||
|
||||
|
@ -191,7 +190,7 @@ float4 BackBufferY(float4 pos: SV_Position, float2 vTexCoord : TEXCOORD) : SV_Ta
|
|||
}
|
||||
|
||||
|
||||
float4 Super_xBR_P0(float4 pos: SV_Position, float2 vTexCoord : TEXCOORD) : SV_Target
|
||||
float4 PS_Super_xBR_P0(float4 pos: SV_Position, float2 vTexCoord : TEXCOORD) : SV_Target
|
||||
{
|
||||
float2 ps = NormalizedNativePixelSize;
|
||||
|
||||
|
@ -223,7 +222,7 @@ float4 Super_xBR_P0(float4 pos: SV_Position, float2 vTexCoord : TEXCOORD) : SV_T
|
|||
|
||||
|
||||
|
||||
float4 Super_xBR_P1(float4 pos: SV_Position, float2 vTexCoord : TEXCOORD) : SV_Target
|
||||
float4 PS_Super_xBR_P1(float4 pos: SV_Position, float2 vTexCoord : TEXCOORD) : SV_Target
|
||||
{
|
||||
float2 ps = NormalizedNativePixelSize;
|
||||
|
||||
|
@ -266,7 +265,7 @@ float4 Super_xBR_P1(float4 pos: SV_Position, float2 vTexCoord : TEXCOORD) : SV_T
|
|||
}
|
||||
|
||||
|
||||
float4 Super_xBR_P2(float4 pos: SV_Position, float2 vTexCoord : TEXCOORD) : SV_Target
|
||||
float4 PS_Super_xBR_P2(float4 pos: SV_Position, float2 vTexCoord : TEXCOORD) : SV_Target
|
||||
{
|
||||
float2 ps = 0.5*NormalizedNativePixelSize;
|
||||
|
||||
|
@ -325,7 +324,7 @@ float4 resampler(float4 x)
|
|||
}
|
||||
|
||||
|
||||
float4 Jinc2(float4 pos: SV_Position, float2 vTexCoord : TEXCOORD) : SV_Target
|
||||
float4 PS_Jinc2(float4 pos: SV_Position, float2 vTexCoord : TEXCOORD) : SV_Target
|
||||
{
|
||||
float2 ps = 0.5*NormalizedNativePixelSize;
|
||||
|
||||
|
@ -391,33 +390,33 @@ float4 Jinc2(float4 pos: SV_Position, float2 vTexCoord : TEXCOORD) : SV_Target
|
|||
|
||||
technique Super_xBR
|
||||
{
|
||||
pass PS_BackBufferY
|
||||
pass
|
||||
{
|
||||
VertexShader = PostProcessVS;
|
||||
PixelShader = BackBufferY;
|
||||
PixelShader = PS_BackBufferY;
|
||||
RenderTarget = tBackBufferY;
|
||||
}
|
||||
pass PS_Super_xBR_P0
|
||||
pass
|
||||
{
|
||||
VertexShader = PostProcessVS;
|
||||
PixelShader = Super_xBR_P0;
|
||||
PixelShader = PS_Super_xBR_P0;
|
||||
RenderTarget = tSuper_xBR_P0;
|
||||
}
|
||||
pass PS_Super_xBR_P1
|
||||
pass
|
||||
{
|
||||
VertexShader = PostProcessVS;
|
||||
PixelShader = Super_xBR_P1;
|
||||
PixelShader = PS_Super_xBR_P1;
|
||||
RenderTarget = tSuper_xBR_P1;
|
||||
}
|
||||
pass PS_Super_xBR_P2
|
||||
pass
|
||||
{
|
||||
VertexShader = PostProcessVS;
|
||||
PixelShader = Super_xBR_P2;
|
||||
PixelShader = PS_Super_xBR_P2;
|
||||
RenderTarget = tSuper_xBR_P2;
|
||||
}
|
||||
pass PS_Jinc2
|
||||
pass
|
||||
{
|
||||
VertexShader = PostProcessVS;
|
||||
PixelShader = Jinc2;
|
||||
PixelShader = PS_Jinc2;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ float3 bicubic_ar(float fp, float3 C0, float3 C1, float3 C2, float3 C3)
|
|||
}
|
||||
|
||||
|
||||
float4 Bicubic_X(float4 pos: SV_Position, float2 uv_tx : TEXCOORD) : SV_Target
|
||||
float4 PS_Bicubic_X(float4 pos: SV_Position, float2 uv_tx : TEXCOORD) : SV_Target
|
||||
{
|
||||
// Both dimensions are unfiltered, so it looks for lores pixels.
|
||||
float2 ps = NormalizedNativePixelSize;
|
||||
|
@ -106,7 +106,7 @@ float4 Bicubic_X(float4 pos: SV_Position, float2 uv_tx : TEXCOORD) : SV_Target
|
|||
}
|
||||
|
||||
|
||||
float4 Bicubic_Y(float4 pos: SV_Position, float2 uv_tx : TEXCOORD) : SV_Target
|
||||
float4 PS_Bicubic_Y(float4 pos: SV_Position, float2 uv_tx : TEXCOORD) : SV_Target
|
||||
{
|
||||
// One must be careful here. Horizontal dimension is already filtered, so it looks for x in hires.
|
||||
float2 ps = float2(1.0/(ViewportSize.x*BufferToViewportRatio.x), NormalizedNativePixelSize.y);
|
||||
|
@ -128,16 +128,16 @@ float4 Bicubic_Y(float4 pos: SV_Position, float2 uv_tx : TEXCOORD) : SV_Target
|
|||
technique Bicubic
|
||||
{
|
||||
|
||||
pass PS_Bicubic_X
|
||||
pass
|
||||
{
|
||||
VertexShader = PostProcessVS;
|
||||
PixelShader = Bicubic_X;
|
||||
PixelShader = PS_Bicubic_X;
|
||||
RenderTarget = tBicubic_P0;
|
||||
}
|
||||
pass PS_Bicubic_Y
|
||||
pass
|
||||
{
|
||||
VertexShader = PostProcessVS;
|
||||
PixelShader = Bicubic_Y;
|
||||
PixelShader = PS_Bicubic_Y;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ float3 lanczos3ar(float fp, float3 C0, float3 C1, float3 C2, float3 C3, float3 C
|
|||
}
|
||||
|
||||
|
||||
float4 Lanczos3_X(float4 pos: SV_Position, float2 uv_tx : TEXCOORD) : SV_Target
|
||||
float4 PS_Lanczos3_X(float4 pos: SV_Position, float2 uv_tx : TEXCOORD) : SV_Target
|
||||
{
|
||||
// Both dimensions are unfiltered, so it looks for lores pixels.
|
||||
float2 ps = NormalizedNativePixelSize;
|
||||
|
@ -103,7 +103,7 @@ float4 Lanczos3_X(float4 pos: SV_Position, float2 uv_tx : TEXCOORD) : SV_Target
|
|||
}
|
||||
|
||||
|
||||
float4 Lanczos3_Y(float4 pos: SV_Position, float2 uv_tx : TEXCOORD) : SV_Target
|
||||
float4 PS_Lanczos3_Y(float4 pos: SV_Position, float2 uv_tx : TEXCOORD) : SV_Target
|
||||
{
|
||||
// One must be careful here. Horizontal dimension is already filtered, so it looks for x in hires.
|
||||
float2 ps = float2(1.0/(ViewportSize.x*BufferToViewportRatio.x), NormalizedNativePixelSize.y);
|
||||
|
@ -129,16 +129,16 @@ float4 Lanczos3_Y(float4 pos: SV_Position, float2 uv_tx : TEXCOORD) : SV_Target
|
|||
technique Lanczos3
|
||||
{
|
||||
|
||||
pass PS_Lanczos3_X
|
||||
pass
|
||||
{
|
||||
VertexShader = PostProcessVS;
|
||||
PixelShader = Lanczos3_X;
|
||||
PixelShader = PS_Lanczos3_X;
|
||||
RenderTarget = tLanczos3_P0;
|
||||
}
|
||||
pass PS_Lanczos3_Y
|
||||
pass
|
||||
{
|
||||
VertexShader = PostProcessVS;
|
||||
PixelShader = Lanczos3_Y;
|
||||
PixelShader = PS_Lanczos3_Y;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -141,6 +141,8 @@ uniform float2 BufferViewportRatio < source = "buffer_to_viewport_ratio"; >;
|
|||
uniform float2 NormalizedNativePixelSize < source = "normalized_native_pixel_size"; >;
|
||||
uniform float2 ViewportSize < source = "viewportsize"; >;
|
||||
|
||||
sampler2D sBackBuffer{Texture=ReShade::BackBufferTex;AddressU=BORDER;AddressV=BORDER;AddressW=BORDER;MagFilter=LINEAR;MinFilter=LINEAR;};
|
||||
|
||||
// Comment the next line to disable interpolation in linear gamma (and
|
||||
// gain speed).
|
||||
#define LINEAR_PROCESSING
|
||||
|
@ -156,9 +158,9 @@ uniform float2 ViewportSize < source = "viewportsize"; >;
|
|||
#define PI 3.141592653589
|
||||
|
||||
#ifdef LINEAR_PROCESSING
|
||||
# define TEX2D(c) pow(tex2D(ReShade::BackBuffer, (c)), float4(geom_target_gamma,geom_target_gamma,geom_target_gamma,geom_target_gamma))
|
||||
# define TEX2D(c) pow(tex2D(sBackBuffer, (c)), float4(geom_target_gamma,geom_target_gamma,geom_target_gamma,geom_target_gamma))
|
||||
#else
|
||||
# define TEX2D(c) tex2D(ReShade::BackBuffer, (c))
|
||||
# define TEX2D(c) tex2D(sBackBuffer, (c))
|
||||
#endif
|
||||
|
||||
// aspect ratio
|
||||
|
|
Loading…
Reference in a new issue