Commit b27af2e1 authored by hunterk's avatar hunterk
Browse files

add fubax_vr, g-sharp_resampler; cleanups for stereoscopic, dithering shaders

parent 8e0b10aa
shaders = 1
shader0 = shaders/g-sharp_resampler.slang
scale0 = 1.0
scale_type0 = source
shaders = 1
shader0 = shaders/jinc2-dedither.slang
scale0 = 1.0
scale_type0 = source
......@@ -57,7 +57,7 @@ layout(location = 0) out vec2 vTexCoord;
void main()
{
gl_Position = global.MVP * Position;
vTexCoord = TexCoord;
vTexCoord = TexCoord * 1.00001;
}
#pragma stage fragment
......@@ -84,4 +84,4 @@ finalRGB.b = find_closest(x, y, rgb.b);
float final = find_closest(x, y, grayscale);
FragColor = vec4(finalRGB, 1.0);
}
\ No newline at end of file
}
#version 450
/*
G-sharp resampler - dynamic range, resizable
Copyright (C) 2020 - 2021 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.
Anti-Ringing inspired by Hyllian
*/
layout(push_constant) uniform Push
{
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
float SIGMA_HV;
float HSHARP0;
float HAR;
float SHAR;
} params;
#pragma parameter HSHARP0 "Filter Range" 1.2 1.0 6.0 0.1
#define HSHARP0 params.HSHARP0
#pragma parameter SIGMA_HV "Gaussian Blur Sigma" 0.75 0.1 7.0 0.05
#define SIGMA_HV params.SIGMA_HV
#pragma parameter SHAR "Sharpness Definition" 0.5 0.0 2.0 0.05
#define SHAR params.SHAR
#pragma parameter HAR "Anti-Ringing" 0.5 0.0 1.0 0.10
#define HAR params.HAR
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
} global;
#pragma stage vertex
layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord;
layout(location = 0) out vec2 vTexCoord;
void main()
{
gl_Position = global.MVP * Position;
vTexCoord = TexCoord;
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
#define COMPAT_TEXTURE(c,d) texture(c,d)
#define SourceSize params.SourceSize
float invsqrsigma_h = 1.0/(2.0*SIGMA_HV*SIGMA_HV);
float gaussian(float x, float y)
{
return exp(-(x*x + y*y)*invsqrsigma_h);
}
void main()
{
vec2 f = fract(SourceSize.xy * vTexCoord.xy);
f = 0.5 - f;
vec2 tex = floor(SourceSize.xy * vTexCoord)*SourceSize.zw + 0.5*SourceSize.zw;
vec2 dx = vec2(SourceSize.z, 0.0);
vec2 dy = vec2(0.0, SourceSize.w);
vec3 colorx = 0.0.xxx;
vec3 colory = 0.0.xxx;
float wx, wy;
float wsumx = 0.0;
float wsumy = 0.0;
vec3 pixel;
float x;
vec3 xcmax = 0.0.xxx;
vec3 xcmin = 1.0.xxx;
float sharp = gaussian(HSHARP0, 0.0);
float maxsharp = 0.07;
float FPR = HSHARP0;
float fpx = 1.0;
float LOOPSIZE = ceil(2.0*FPR);
float y = -LOOPSIZE;
do
{
x = -LOOPSIZE;
do
{
pixel = COMPAT_TEXTURE(Source, tex + x*dx + y*dy).rgb;
wx = gaussian(x+f.x, y+f.y) - sharp;
fpx = (sqrt(dot(vec2(x+f.x,y+f.y),vec2(x+f.x,y+f.y)))-FPR)/FPR;
if (((x*x) + (y*y)) < 1.25*FPR) { xcmax = max(xcmax, pixel); xcmin = min(xcmin, pixel); }
if (wx < 0.0) wx = clamp(wx, mix(-maxsharp, 0.0, pow(abs(fpx), SHAR)), 0.0);
colorx = colorx + wx * pixel;
wsumx = wsumx + wx;
x = x + 1.0;
} while (x <= LOOPSIZE);
y = y + 1.0;
} while (y <= LOOPSIZE);
vec3 color = colorx/wsumx;
color = mix(clamp(color, 0.0, 1.0), clamp(color, xcmin, xcmax), HAR);
FragColor = vec4(color, 1.0);
}
shaders = 5
shader0 = ../stock.slang
scale_type0 = viewport
scale0 = 1.0
shader1 = shaders/fubax_vr/VR.slang
scale_type1 = viewport
scale1 = 1.0
filter_linear1 = true
shader2 = shaders/fubax_vr/Chromatic.slang
scale_type2 = viewport
scale2 = 1.0
filter_linear2 = true
shader3 = shaders/fubax_vr/FilmicSharpen.slang
scale_type3 = viewport
scale3 = 1.0
filter_linear3 = true
shader4 = shaders/fubax_vr/VR_nose.slang
scale_type4 = viewport
scale4 = 1.0
filter_linear4 = true
textures = "noseTex"
noseTex = shaders/fubax_vr/nose.png
#version 450
/*
/// VR shader ///
Make any game VR and any screen with lenses a VR headset.
Thanks to this shader you'll be able to correct distortions of any lens types
(DIY, experimental) and chromatic aberration.
Also if a game outputs depth pass you can have a stereo-3D vision thanks to
the parallax mapping (which needs some further improvement).
Copyright (c) 2019 Jacob Max Fober
This work is licensed under the Creative Commons
Attribution-NonCommercial-ShareAlike 4.0 International License.
To view a copy of this license, visit
http://creativecommons.org/licenses/by-nc-sa/4.0/
If you want to use it commercially, contact me at jakub.m.fober@pm.me
If you have questions, visit https://reshade.me/forum/shader-discussion/
I'm author of most of equations present here,
beside Brown-Conrady distortion correction model and
Parallax Steep and Occlusion mapping which
I changed and adopted from various sources.
Version 0.4.2 alpha
*/
layout(push_constant) uniform Push
{
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
} params;
#include "fubax_vr_params.inc"
#pragma stage vertex
layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord;
layout(location = 0) out vec2 texcoord;
void main()
{
gl_Position = global.MVP * Position;
texcoord = TexCoord;
}
#pragma stage fragment
layout(location = 0) in vec2 texcoord;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
#include "fubax_vr_shared_funcs.inc"
void main()
{
// Bypass chromatic aberration switch
if(!ChromaticAbrSwitch)
{
FragColor = vec4(texture(Source, texcoord).rgb, 1.0);
return;
}
// Get display aspect ratio (horizontal/vertical resolution)
float rAspect = params.OutputSize.x*params.OutputSize.w;
// Generate negative-positive stereo mask
float SideScreenSwitch = step(0.5, texcoord.x)*2.0-1.0;
// Divide screen in two if stereo vision mode enabled
vec2 CenterCoord = StereoSwitch? StereoVision(texcoord, IPD) : texcoord;
CenterCoord = CenterCoord*2.0-1.0; // Center coordinates
CenterCoord.x *= rAspect; // Correct aspect ratio
float Diagonal = rAspect;
Diagonal *= StereoSwitch ? 0.5 : 1.0;
Diagonal = length(vec2(Diagonal, 1.0));
CenterCoord /= Diagonal; // Normalize diagonally
// Left/right eye mask
float L = step(0.5, 1.0-texcoord.x);
float R = step(0.5, texcoord.x);
// Offset center green
vec2 CoordGreen = ChGreenOffsetL * L + ChGreenOffsetR * R;
CoordGreen.x *= -1.0;
CoordGreen = 0.01 * CoordGreen + CenterCoord;
// Offset center blue
vec2 CoordBlue = ChBlueOffsetL * L + ChBlueOffsetR * R;
CoordBlue.x *= -1.0;
CoordBlue = 0.01 * CoordBlue + CenterCoord;
// float RadiusGreen = dot(CoordGreen, CoordGreen); // Radius squared (techically accurate)
// float RadiusBlue = dot(CoordBlue, CoordBlue); // Radius squared (techically accurate)
float RadiusGreen = length(CoordGreen); // Radius
float RadiusBlue = length(CoordBlue); // Radius
// Calculate radial distortion K
float correctionGreenK = (1.0+ChGreenK.x)*kRadial(RadiusGreen, ChGreenK.y, ChGreenK.z, ChGreenK.w, 0.0);
float correctionBlueK = (1.0+ChBlueK.x)*kRadial(RadiusBlue, ChBlueK.y, ChBlueK.z, ChBlueK.w, 0.0);
// Apply chromatic aberration correction
CoordGreen = CoordGreen * correctionGreenK;
CoordBlue = CoordBlue * correctionBlueK;
CoordGreen *= Diagonal; CoordBlue *= Diagonal; // Back to vertical normalization
CoordGreen.x /= rAspect; CoordBlue.x /= rAspect; // Back to square
// Move origin to left top corner
CoordGreen = CoordGreen * 0.5 + 0.5; CoordBlue = CoordBlue * 0.5 + 0.5;
// Generate border mask for green and blue channel
float MaskBlue, MaskGreen; if(StereoSwitch)
{
// Mask compensation for center cut
float CenterCut = 0.5+(0.5-IPD)*SideScreenSwitch;
// Mask sides and center cut for blue channel
vec2 MaskCoordBlue;
MaskCoordBlue.x = CoordBlue.x*2.0 - CenterCut; // Compensate for 2 views
MaskCoordBlue.y = CoordBlue.y;
MaskBlue = BorderMaskAA(MaskCoordBlue);
// Mask sides and center cut for green channel
vec2 MaskCoordGreen;
MaskCoordGreen.x = CoordGreen.x*2.0 - CenterCut; // Compensate for 2 views
MaskCoordGreen.y = CoordGreen.y;
MaskGreen = BorderMaskAA(MaskCoordGreen);
// Reverse stereo coordinates to single view
CoordGreen = InvStereoVision(CoordGreen, int(SideScreenSwitch), IPD);
CoordBlue = InvStereoVision(CoordBlue, int(SideScreenSwitch), IPD);
}
else
{
MaskBlue = BorderMaskAA(CoordBlue);
MaskGreen = BorderMaskAA(CoordGreen);
};
vec3 Image;
// Sample image red
Image.r = texture(Source, texcoord).r;
// Sample image green
Image.g = mix(
texture(Source, CoordGreen).g,
0.0, // Black borders
MaskGreen // Anti-aliased border mask
);
// Sample image blue
Image.b = mix(
texture(Source, CoordBlue).b,
0.0, // Black borders
MaskBlue // Anti-aliased border mask
);
// Display chromatic aberration
FragColor = vec4(Image, 1.0);
}
#version 450
/*
/// VR shader ///
Make any game VR and any screen with lenses a VR headset.
Thanks to this shader you'll be able to correct distortions of any lens types
(DIY, experimental) and chromatic aberration.
Also if a game outputs depth pass you can have a stereo-3D vision thanks to
the parallax mapping (which needs some further improvement).
Copyright (c) 2019 Jacob Max Fober
This work is licensed under the Creative Commons
Attribution-NonCommercial-ShareAlike 4.0 International License.
To view a copy of this license, visit
http://creativecommons.org/licenses/by-nc-sa/4.0/
If you want to use it commercially, contact me at jakub.m.fober@pm.me
If you have questions, visit https://reshade.me/forum/shader-discussion/
I'm author of most of equations present here,
beside Brown-Conrady distortion correction model and
Parallax Steep and Occlusion mapping which
I changed and adopted from various sources.
Version 0.4.2 alpha
*/
layout(push_constant) uniform Push
{
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
} params;
#include "fubax_vr_params.inc"
#pragma stage vertex
layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord;
layout(location = 0) out vec2 texcoord;
void main()
{
gl_Position = global.MVP * Position;
texcoord = TexCoord;
}
#pragma stage fragment
layout(location = 0) in vec2 texcoord;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
#include "fubax_vr_shared_funcs.inc"
void main()
{
vec2 UvCoord = texcoord;
// Bypass sharpening
if(!Sharpen)
{
FragColor = vec4(texture(Source, UvCoord).rgb, 1.0);
return;
}
vec2 Pixel = (texcoord.xy * params.OutputSize.xy) * Offset;
// Sample display image
vec3 ImgSource = texture(Source, UvCoord).rgb;
vec2 NorSouWesEst[4] = {
vec2(UvCoord.x, UvCoord.y + Pixel.y),
vec2(UvCoord.x, UvCoord.y - Pixel.y),
vec2(UvCoord.x + Pixel.x, UvCoord.y),
vec2(UvCoord.x - Pixel.x, UvCoord.y)
};
// Luma high-pass
float HighPass = 0.0;
for(int i=0; i<4; i++)
{
HighPass += Luma(texture(Source, NorSouWesEst[i]).rgb);
}
HighPass = 0.5 - 0.5 * (HighPass * 0.25 - Luma(ImgSource));
// Sharpen strength
HighPass = mix(0.5, HighPass, Strength * 0.01);
// Clamping sharpen
HighPass = (Clamp != 1.0) ? max(min(HighPass, Clamp), 1.0 - Clamp) : HighPass;
vec3 Sharpen = vec3(
Overlay(ImgSource.r, HighPass),
Overlay(ImgSource.g, HighPass),
Overlay(ImgSource.b, HighPass)
);
FragColor.rgb = (Preview) ? vec3(HighPass) : Sharpen;
FragColor.a = 1.0;
}
#version 450
/*
/// VR shader ///
Make any game VR and any screen with lenses a VR headset.
Thanks to this shader you'll be able to correct distortions of any lens types
(DIY, experimental) and chromatic aberration.
Also if a game outputs depth pass you can have a stereo-3D vision thanks to
the parallax mapping (which needs some further improvement).
Copyright (c) 2019 Jacob Max Fober
This work is licensed under the Creative Commons
Attribution-NonCommercial-ShareAlike 4.0 International License.
To view a copy of this license, visit
http://creativecommons.org/licenses/by-nc-sa/4.0/
If you want to use it commercially, contact me at jakub.m.fober@pm.me
If you have questions, visit https://reshade.me/forum/shader-discussion/
I'm author of most of equations present here,
beside Brown-Conrady distortion correction model and
Parallax Steep and Occlusion mapping which
I changed and adopted from various sources.
Version 0.4.2 alpha
*/
layout(push_constant) uniform Push
{
vec4 SourceSize;
vec4 OutputSize;
uint FrameCount;
} params;
#include "fubax_vr_params.inc"
#pragma stage vertex
layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord;
layout(location = 0) out vec2 texcoord;
void main()
{
gl_Position = global.MVP * Position;
texcoord = TexCoord * 1.00001;
}
#pragma stage fragment
layout(location = 0) in vec2 texcoord;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
#include "fubax_vr_shared_funcs.inc"
void main()
{
// Get display aspect ratio (horizontal/vertical resolution)
const float rAspect = params.OutputSize.x*params.OutputSize.w;
// Divide screen in two
vec2 UvCoord = StereoSwitch? StereoVision(texcoord, IPD) : texcoord;
// Generate negative-positive stereo mask
float StereoMask = step(0.5, texcoord.x)*2.0-1.0;
// Correct lens distortion
if(PerspectiveSwitch)
{
// Center coordinates
UvCoord = UvCoord*2.0-1.0;
UvCoord.x *= rAspect;
vec2 StereoCoord = UvCoord; // Save coordinates for Brown-Conrady correction
// Base distortion correction
if(bool(FOV)) // If FOV is not equal 0
{
float radFOV = radians(FOV);
// Calculate radius
float Radius = length(UvCoord);
// Apply base lens correction
switch(LensType)
{
case 0:
{ UvCoord *= Orthographic(radFOV, Radius); break; }
case 1:
{ UvCoord *= Equisolid(radFOV, Radius); break; }
case 2:
{ UvCoord *= Equidistant(radFOV, Radius); break; }
case 3:
{ UvCoord *= Stereographic(radFOV, Radius); break; }
}
};
// Lens geometric aberration correction (Brown-Conrady model)
float Diagonal = rAspect;
Diagonal *= StereoSwitch ? 0.5 : 1.0;
Diagonal = length(vec2(Diagonal, 1.0));
float InvDiagonal2 = 1.0 / pow(Diagonal, 2);
StereoCoord /= Diagonal; // Normalize diagonally
float Radius2 = dot(StereoCoord, StereoCoord); // Squared radius
float correctionK = kRadial(Radius2, K.x, K.y, K.z, K.w);
// Apply negative-positive stereo mask for tangental distortion (flip side)
float SideScreenSwitch = (StereoSwitch) ? StereoMask : 1.0;
vec2 correctionP = pTangental(
StereoCoord,
Radius2,
P.x * SideScreenSwitch,
P.y,
P.z,
0.0
);
// Expand background to vertical border (but not for test grid for ease of calibration)
UvCoord /= TestGrid ? vec2(1.0) : vec2(kRadial(InvDiagonal2, K.x, K.y, K.z, K.w));
UvCoord = UvCoord * correctionK + correctionP; // Apply lens correction
// Scale image
UvCoord /= TestGrid ? vec2(1.0) : vec2(ImageScale);
// Revert aspect ratio to square
UvCoord.x /= rAspect;
// Move origin back to left top corner
UvCoord = UvCoord*0.5 + vec2(0.5);
}
// Display test grid
if(TestGrid) {
FragColor = vec4(Grid(UvCoord, rAspect), 1.0);
return;
}
/* Disable for RetroArch since there's no depth buffer
// Create parallax effect
if(ParallaxSwitch)
{
float ParallaxDirection = ParallaxOffset*0.01;
// For stereo-vison flip direction on one side
ParallaxDirection *= StereoSwitch ? StereoMask : 1.0;
// Apply parallax effect
UvCoord = Parallax(
UvCoord,
ParallaxDirection,
ParallaxCenter,
ParallaxMaskScalar,
ParallaxSteps
);
}
*/
// added by hunterk to adjust aspect ratio of the image
vec2 corrected_size = params.SourceSize.xy * vec2(img_ar.x / img_ar.y, 1.0)
* vec2(params.SourceSize.y / params.SourceSize.x, 1.0);
float full_scale = params.OutputSize.y / params.SourceSize.y;
vec2 scale = (params.OutputSize.xy / corrected_size) / full_scale;
vec2 middle = vec2(0.49999, 0.49999);
vec2 diff = UvCoord.xy - middle;
vec2 screen_coord = middle + diff * scale;
UvCoord = ((screen_coord - vec2(0.5)) * imgzoom) + vec2(0.5);
// Sample image with black borders to display
vec3 Image = mix(
texture(Source, UvCoord).rgb, // Display image
vec3(0.0), // Black borders
BorderMaskAA(UvCoord) // Anti-aliased border mask
);
// Display image
FragColor = vec4(Image, 1.0);
}