Shaders: Add new pack of shaders (reshade) (#3232)

- Add crt-geom, super-xbr, geom, multi-LUT, deblur-luma, bicubic and lanczos3. All .fx shaders;
- Added some LUTs.
This commit is contained in:
Hyllian
2024-06-23 21:16:51 -03:00
committed by GitHub
parent 6021e435ba
commit 9189588554
10 changed files with 1931 additions and 0 deletions

View File

@ -0,0 +1,143 @@
#include "../ReShade.fxh"
/*
Bicubic multipass Shader
Copyright (C) 2011-2022 Hyllian - sergiogdb@gmail.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
uniform int BICUBIC_FILTER <
ui_type = "combo";
ui_items = "Bicubic\0Catmull-Rom\0B-Spline\0Hermite\0";
ui_label = "Bicubic Filter";
ui_tooltip = "Bicubic: balanced. Catmull-Rom: sharp. B-Spline: blurred. Hermite: soft pixelized.";
> = 0;
uniform bool B_ANTI_RINGING <
ui_type = "radio";
ui_label = "Bicubic Anti-Ringing";
> = false;
uniform float2 NormalizedNativePixelSize < source = "normalized_native_pixel_size"; >;
uniform float2 BufferToViewportRatio < source = "buffer_to_viewport_ratio"; >;
uniform float2 ViewportSize < source = "viewportsize"; >;
texture2D tBicubic_P0{Width=BUFFER_WIDTH;Height=BUFFER_HEIGHT;Format=RGBA8;};
sampler2D sBicubic_P0{Texture=tBicubic_P0;AddressU=CLAMP;AddressV=CLAMP;AddressW=CLAMP;MagFilter=POINT;MinFilter=POINT;};
#define AR_STRENGTH 1.0
// Classic Mitchell-Netravali bicubic parameters
float4x4 get_inv()
{
float bf = 1.0/3.0;
float cf = 1.0/3.0;
if (BICUBIC_FILTER == 1) {bf = 0.0; cf = 0.5;}
if (BICUBIC_FILTER == 2) {bf = 1.0; cf = 0.0;}
if (BICUBIC_FILTER == 3) {bf = 0.0; cf = 0.0;}
return float4x4( (-bf - 6.0*cf)/6.0, (3.0*bf + 12.0*cf)/6.0, (-3.0*bf - 6.0*cf)/6.0, bf/6.0,
(12.0 - 9.0*bf - 6.0*cf)/6.0, (-18.0 + 12.0*bf + 6.0*cf)/6.0, 0.0, (6.0 - 2.0*bf)/6.0,
-(12.0 - 9.0*bf - 6.0*cf)/6.0, (18.0 - 15.0*bf - 12.0*cf)/6.0, (3.0*bf + 6.0*cf)/6.0, bf/6.0,
(bf + 6.0*cf)/6.0, -cf, 0.0, 0.0);
}
float3 bicubic_ar(float fp, float3 C0, float3 C1, float3 C2, float3 C3)
{
float4 weights = mul(get_inv(), float4(fp*fp*fp, fp*fp, fp, 1.0));
float3 color = mul(weights, float4x3( C0, C1, C2, C3 ));
// Anti-ringing
if (B_ANTI_RINGING == true)
{
float3 aux = color;
float3 min_sample = min(min(C0, C1), min(C2, C3));
float3 max_sample = max(max(C0, C1), max(C2, C3));
color = clamp(color, min_sample, max_sample);
color = lerp(aux, color, step(0.0, (C0-C1)*(C2-C3)));
}
return color;
}
float4 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;
float2 posi = uv_tx.xy + ps * float2(0.5, 0.0);
float2 fp = frac(posi / ps);
float2 tc = posi - (fp + 0.5) * ps;
float3 C0 = tex2D(ReShade::BackBuffer, tc + ps*float2(-1.0, 1.0)).rgb;
float3 C1 = tex2D(ReShade::BackBuffer, tc + ps*float2( 0.0, 1.0)).rgb;
float3 C2 = tex2D(ReShade::BackBuffer, tc + ps*float2( 1.0, 1.0)).rgb;
float3 C3 = tex2D(ReShade::BackBuffer, tc + ps*float2( 2.0, 1.0)).rgb;
float3 color = bicubic_ar(fp.x, C0, C1, C2, C3);
return float4(color, 1.0);
}
float4 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);
float2 posi = uv_tx.xy + ps * float2(0.5, 0.5);
float2 fp = frac(posi / ps);
float2 tc = posi - (fp + 0.5) * ps;
float3 C0 = tex2D(sBicubic_P0, tc + ps*float2(1.0, -1.0)).rgb;
float3 C1 = tex2D(sBicubic_P0, tc + ps*float2(1.0, 0.0)).rgb;
float3 C2 = tex2D(sBicubic_P0, tc + ps*float2(1.0, 1.0)).rgb;
float3 C3 = tex2D(sBicubic_P0, tc + ps*float2(1.0, 2.0)).rgb;
float3 color = bicubic_ar(fp.y, C0, C1, C2, C3);
return float4(color, 1.0);
}
technique Bicubic
{
pass PS_Bicubic_X
{
VertexShader = PostProcessVS;
PixelShader = Bicubic_X;
RenderTarget = tBicubic_P0;
}
pass PS_Bicubic_Y
{
VertexShader = PostProcessVS;
PixelShader = Bicubic_Y;
}
}

View File

@ -0,0 +1,144 @@
#include "ReShade.fxh"
/*
Lanczos3 - Multipass code by Hyllian 2022.
*/
/*
Copyright (C) 2010 Team XBMC
http://www.xbmc.org
Copyright (C) 2011 Stefanos A.
http://www.opentk.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, 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 XBMC; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
http://www.gnu.org/copyleft/gpl.html
*/
uniform bool LANCZOS3_ANTI_RINGING <
ui_type = "radio";
ui_label = "Lanczos3 Anti-Ringing";
> = true;
uniform float2 NormalizedNativePixelSize < source = "normalized_native_pixel_size"; >;
uniform float2 BufferToViewportRatio < source = "buffer_to_viewport_ratio"; >;
uniform float2 ViewportSize < source = "viewportsize"; >;
texture2D tLanczos3_P0{Width=BUFFER_WIDTH;Height=BUFFER_HEIGHT;Format=RGBA8;};
sampler2D sLanczos3_P0{Texture=tLanczos3_P0;AddressU=CLAMP;AddressV=CLAMP;AddressW=CLAMP;MagFilter=POINT;MinFilter=POINT;};
#define AR_STRENGTH 1.0
#define FIX(c) (max(abs(c),1e-5))
#define PI 3.1415926535897932384626433832795
#define radius 3.0
float3 weight3(float x)
{
float3 Sample = FIX(2.0 * PI * float3(x - 1.5, x - 0.5, x + 0.5));
// Lanczos3. Note: we normalize outside this function, so no point in multiplying by radius.
return sin(Sample) * sin(Sample / radius) / (Sample * Sample);
}
float3 lanczos3ar(float fp, float3 C0, float3 C1, float3 C2, float3 C3, float3 C4, float3 C5)
{
float3 w1 = weight3(0.5 - fp * 0.5);
float3 w2 = weight3(1.0 - fp * 0.5);
float sum = dot( w1, float3(1.,1.,1.)) + dot( w2, float3(1.,1.,1.));
w1 /= sum;
w2 /= sum;
float3 color = mul(w1, float3x3( C0, C2, C4 )) + mul(w2, float3x3( C1, C3, C5));
// Anti-ringing
if (LANCZOS3_ANTI_RINGING == true)
{
float3 aux = color;
float3 min_sample = min(min(C1, C2), min(C3, C4));
float3 max_sample = max(max(C1, C2), max(C3, C4));
color = clamp(color, min_sample, max_sample);
color = lerp(aux, color, AR_STRENGTH*step(0.0, (C1-C2)*(C3-C4)));
}
return color;
}
float4 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;
float2 posi = uv_tx.xy + ps * float2(0.5, 0.0);
float2 fp = frac(posi / ps);
float2 xystart = posi - (fp + 0.5) * ps;
float ypos = xystart.y + ps.y;
float3 C0 = tex2D(ReShade::BackBuffer, float2(xystart.x - ps.x * 2.0, ypos)).rgb;
float3 C1 = tex2D(ReShade::BackBuffer, float2(xystart.x - ps.x * 1.0, ypos)).rgb;
float3 C2 = tex2D(ReShade::BackBuffer, float2(xystart.x , ypos)).rgb;
float3 C3 = tex2D(ReShade::BackBuffer, float2(xystart.x + ps.x * 1.0, ypos)).rgb;
float3 C4 = tex2D(ReShade::BackBuffer, float2(xystart.x + ps.x * 2.0, ypos)).rgb;
float3 C5 = tex2D(ReShade::BackBuffer, float2(xystart.x + ps.x * 3.0, ypos)).rgb;
float3 color = lanczos3ar(fp.x, C0, C1, C2, C3, C4, C5);
return float4(color, 1.0);
}
float4 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);
float2 posi = uv_tx.xy + ps * float2(0.5, 0.5);
float2 fp = frac(posi / ps);
float2 xystart = posi - (fp + 0.5) * ps;
float xpos = xystart.x + ps.x;
float3 C0 = tex2D(sLanczos3_P0, float2(xpos, xystart.y - ps.y * 2.0)).rgb;
float3 C1 = tex2D(sLanczos3_P0, float2(xpos, xystart.y - ps.y * 1.0)).rgb;
float3 C2 = tex2D(sLanczos3_P0, float2(xpos, xystart.y )).rgb;
float3 C3 = tex2D(sLanczos3_P0, float2(xpos, xystart.y + ps.y * 1.0)).rgb;
float3 C4 = tex2D(sLanczos3_P0, float2(xpos, xystart.y + ps.y * 2.0)).rgb;
float3 C5 = tex2D(sLanczos3_P0, float2(xpos, xystart.y + ps.y * 3.0)).rgb;
float3 color = lanczos3ar(fp.y, C0, C1, C2, C3, C4, C5);
return float4(color, 1.0);
}
technique Lanczos3
{
pass PS_Lanczos3_X
{
VertexShader = PostProcessVS;
PixelShader = Lanczos3_X;
RenderTarget = tLanczos3_P0;
}
pass PS_Lanczos3_Y
{
VertexShader = PostProcessVS;
PixelShader = Lanczos3_Y;
}
}