Skip to content

Commit

Permalink
Update uborder shaders
Browse files Browse the repository at this point in the history
- Reflections code rewriten;
- New params;
  • Loading branch information
Hyllian committed Dec 8, 2024
1 parent 3e3855e commit cbe833d
Show file tree
Hide file tree
Showing 11 changed files with 497 additions and 88 deletions.
15 changes: 15 additions & 0 deletions base_presets/config/uborder-reflections.params
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
box_scale = "2.980000"
in_res_x = "326.000000"
geom_center_y = "-0.002000"
geom_curvature = "1.000000"
geom_R = "2.000000"
geom_cornersize = "0.011000"
geom_cornersmooth = "280.000000"
CN_VIG_TOGGLE = "1.000000"
CN_VIG_EXP = "0.080000"
reflection_strength = "0.250000"
frame_w = "0.495000"
frame_h = "0.651000"
bezel_w = "0.036000"
bezel_h = "0.032000"
bezel_center_y = "0.004000"
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ BORDER = "../../textures/borders/default.jpg"

box_scale = "2.980000"
in_res_x = "326.000000"
geom_center_y = "0.010000"
geom_center_y = "-0.002000"
geom_curvature = "1.000000"
geom_R = "2.000000"
geom_cornersize = "0.011000"
Expand All @@ -54,7 +54,7 @@ CN_VIG_TOGGLE = "1.000000"
CN_VIG_EXP = "0.080000"
reflection_strength = "0.250000"
frame_w = "0.495000"
frame_h = "0.654000"
bezel_w = "0.017000"
bezel_h = "0.014000"
bezel_center_y = "0.005000"
frame_h = "0.651000"
bezel_w = "0.036000"
bezel_h = "0.032000"
bezel_center_y = "0.004000"
26 changes: 5 additions & 21 deletions shaders/content_shaders/crt-nobody.slang
Original file line number Diff line number Diff line change
Expand Up @@ -56,27 +56,7 @@ layout(push_constant) uniform Push
float ub_rotate;
} params;

#pragma parameter frame_nonono "FRAME:" 0.0 0.0 1.0 1.0
#pragma parameter box_scale " Image Scale" 4.0 1.0 10.0 0.02
#pragma parameter in_res_x " Viewport Size X" 320.0 100.0 600.0 1.0
#pragma parameter in_res_y " Viewport Size Y" 240.0 64.0 512.0 1.0
#pragma parameter geom_center_x " Center X" 0.0 -1.0 1.0 0.001
#pragma parameter geom_center_y " Center Y" 0.0 -1.0 1.0 0.01
#pragma parameter ub_rotate " Rotate (TATE)" 0.0 0.0 1.0 1.0

#pragma parameter geom_nonono "GEOM'S CURVATURE:" 0.0 0.0 1.0 1.0
#pragma parameter geom_curvature " Curvature Toggle" 0.0 0.0 1.0 1.0
#pragma parameter geom_R " Curvature Radius" 2.0 0.3 10.0 0.1
#pragma parameter geom_d " Distance" 1.5 0.1 3.0 0.1
#pragma parameter geom_invert_aspect " Curvature Aspect Inversion" 0.0 0.0 1.0 1.0
#pragma parameter geom_cornersize " Corner Size" 0.006 0.006 1.0 0.005
#pragma parameter geom_cornersmooth " Corner Smoothness" 400.0 80.0 2000.0 100.0
#pragma parameter geom_x_tilt " Horizontal Tilt" 0.0 -0.5 0.5 0.01
#pragma parameter geom_y_tilt " Vertical Tilt" 0.0 -0.5 0.5 0.01
#pragma parameter geom_inner_center_x " Inner Center X" 0.0 -1.0 1.0 0.001
#pragma parameter geom_inner_center_y " Inner Center Y" 0.0 -1.0 1.0 0.001
#pragma parameter geom_overscan_x " Horiz. Overscan %" 100.0 -125.0 125.0 0.5
#pragma parameter geom_overscan_y " Vert. Overscan %" 100.0 -125.0 125.0 0.5
#include "include/uborder_params.inc"

#pragma parameter CN_NONONO "CRT-NOBODY:" 0.0 0.0 1.0 1.0
#pragma parameter CN_VSCANLINES " Vertical Scanlines" 0.0 0.0 1.0 1.0
Expand Down Expand Up @@ -338,6 +318,10 @@ float vignette(vec2 uv)

void main()
{
float draw = step(max(vTexCoord.x, vTexCoord.y), 1.0) * step(0.0, min(vTexCoord.x, vTexCoord.y));

if (draw < 0.5) discard;

vec2 uv = vTexCoord;
float cval = 1.0;

Expand Down
11 changes: 11 additions & 0 deletions shaders/content_shaders/include/uborder_frame_params.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Yeah, it's redundant, but I won't create inner 'includes' over and over, because Retroarch
// crawls to unroll these f***rs.

#pragma parameter frame_nonono "FRAME:" 0.0 0.0 1.0 1.0
#pragma parameter box_scale " Image Scale" 4.0 1.0 10.0 0.02
#pragma parameter in_res_x " Viewport Size X" 320.0 100.0 600.0 1.0
#pragma parameter in_res_y " Viewport Size Y" 240.0 64.0 512.0 1.0
#pragma parameter geom_center_x " Center X" 0.0 -1.0 1.0 0.001
#pragma parameter geom_center_y " Center Y" 0.0 -1.0 1.0 0.002
#pragma parameter ub_rotate " Rotate (TATE)" 0.0 0.0 1.0 1.0

21 changes: 21 additions & 0 deletions shaders/content_shaders/include/uborder_params.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma parameter frame_nonono "FRAME:" 0.0 0.0 1.0 1.0
#pragma parameter box_scale " Image Scale" 4.0 1.0 10.0 0.02
#pragma parameter in_res_x " Viewport Size X" 320.0 100.0 600.0 1.0
#pragma parameter in_res_y " Viewport Size Y" 240.0 64.0 512.0 1.0
#pragma parameter geom_center_x " Center X" 0.0 -1.0 1.0 0.001
#pragma parameter geom_center_y " Center Y" 0.0 -1.0 1.0 0.002
#pragma parameter ub_rotate " Rotate (TATE)" 0.0 0.0 1.0 1.0

#pragma parameter geom_nonono "GEOM'S CURVATURE:" 0.0 0.0 1.0 1.0
#pragma parameter geom_curvature " Curvature Toggle" 0.0 0.0 1.0 1.0
#pragma parameter geom_R " Curvature Radius" 2.0 0.3 10.0 0.1
#pragma parameter geom_d " Distance" 1.5 0.1 3.0 0.1
#pragma parameter geom_invert_aspect " Curvature Aspect Inversion" 0.0 0.0 1.0 1.0
#pragma parameter geom_cornersize " Corner Size" 0.006 0.006 1.0 0.005
#pragma parameter geom_cornersmooth " Corner Smoothness" 400.0 80.0 2000.0 100.0
#pragma parameter geom_x_tilt " Horizontal Tilt" 0.0 -0.5 0.5 0.01
#pragma parameter geom_y_tilt " Vertical Tilt" 0.0 -0.5 0.5 0.01
#pragma parameter geom_inner_center_x " Inner Center X" 0.0 -1.0 1.0 0.001
#pragma parameter geom_inner_center_y " Inner Center Y" 0.0 -1.0 1.0 0.001
#pragma parameter geom_overscan_x " Horiz. Overscan %" 100.0 -125.0 125.0 0.5
#pragma parameter geom_overscan_y " Vert. Overscan %" 100.0 -125.0 125.0 0.5
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
#version 450

/*
G-sharp resampler 2.0 horizontal - dynamic range (upscaler, downsampler)

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.

*/

layout(push_constant) uniform Push
{
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
float GSHARP0;
float GMAXSHARP;
float GPAR;
float GBOOST;
} params;

#pragma parameter gsharp_nonono "G-SHARP2 DOWNSAMPLE:" 0.0 0.0 1.0 1.0

#pragma parameter GSHARP0 " Filter Range" 1.0 0.75 8.0 0.05
#define GSHARP0 params.GSHARP0

#pragma parameter GBOOST " Filter Boost (same range, speedup)" 1.70 1.0 2.5 0.05
#define GBOOST params.GBOOST
float GBOOST1 = 1.0/GBOOST;

#pragma parameter GMAXSHARP " Filter Sharpness" 0.10 0.0 0.25 0.01
float GMAXSHARP = 0.5*GBOOST*GBOOST*params.GMAXSHARP;

#pragma parameter GPAR " Anti-Ringing" 0.50 0.0 1.0 0.10
#define GPAR params.GPAR

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 * 1.00001;
}

#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 smothstep(float x)
{
return exp(-1.75*x*x);
}

float getw(float x)
{
float z = x*GBOOST1;
float y = smothstep(z);
return max(y*y*y - GMAXSHARP, mix(-GMAXSHARP, 0.0, x-1.0));
}

void main()
{
vec2 pos = vTexCoord * SourceSize.xy-0.5;
float f = -fract(pos.x);
vec2 tex = floor(pos)*SourceSize.zw + 0.5*SourceSize.zw;
vec3 color = 0.0.xxx;
vec2 dx = vec2(SourceSize.z, 0.0);

float w, fp;
float wsum = 0.0;
vec3 pixel;
vec3 cmax = 0.0.xxx;
vec3 cmin = 1.0.xxx;
float FPRi = 1.0/GSHARP0;
float FPR2 = 2.0*GSHARP0;
float FPR3 = FPR2*FPR2;
float LOOPSIZE = ceil(FPR2);
float x = -LOOPSIZE+1.0;

do
{
fp = min(abs(x+f),FPR2);
pixel = COMPAT_TEXTURE(Source, tex + x*dx).rgb;
fp = fp*FPRi;
w = getw(fp);
if (w > 0.0) { cmin = min(cmin, pixel); cmax = max(cmax, pixel); }
color = color + w * pixel;
wsum = wsum + w;

x = x + 1.0;

} while (x <= LOOPSIZE);

color = color / wsum;

color = mix(clamp(color, 0.0, 1.0), clamp(color, cmin, cmax), GPAR);

FragColor = vec4(color, 1.0);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
#version 450

/*
G-sharp resampler 2.0 vertical - dynamic range (upscaler, downsampler)

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.

*/

layout(push_constant) uniform Push
{
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
float GSHARP0;
float GMAXSHARP;
float GPAR;
float GBOOST;
} params;


#pragma parameter GSHARP0 " Filter Range" 1.0 0.75 8.0 0.05
#define GSHARP0 params.GSHARP0

#pragma parameter GBOOST " Filter Boost (same range, speedup)" 1.70 1.0 2.5 0.05
#define GBOOST params.GBOOST
float GBOOST1 = 1.0/GBOOST;

#pragma parameter GMAXSHARP " Filter Sharpness" 0.10 0.0 0.25 0.01
float GMAXSHARP = 0.5*GBOOST*GBOOST*params.GMAXSHARP;

#pragma parameter GPAR " Anti-Ringing" 0.50 0.0 1.0 0.10
#define GPAR params.GPAR

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 * 1.00001;
}

#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 smothstep(float x)
{
return exp(-1.75*x*x);
}

float getw(float x)
{
float z = x*GBOOST1;
float y = smothstep(z);
return max(y*y*y - GMAXSHARP, mix(-GMAXSHARP, 0.0, x-1.0));
}

void main()
{
vec2 pos = vTexCoord * SourceSize.xy-0.5;
float f = -fract(pos.y);
vec2 tex = floor(pos)*SourceSize.zw + 0.5*SourceSize.zw;
vec3 color = 0.0.xxx;
vec2 dy = vec2(0.0, SourceSize.w);

float w, fp;
float wsum = 0.0;
vec3 pixel;
vec3 cmax = 0.0.xxx;
vec3 cmin = 1.0.xxx;
float FPRi = 1.0/GSHARP0;
float FPR2 = 2.0*GSHARP0;
float FPR3 = FPR2*FPR2;
float LOOPSIZE = ceil(FPR2);
float y = -LOOPSIZE+1.0;

do
{
fp = min(abs(y+f),FPR2);
pixel = COMPAT_TEXTURE(Source, tex + y*dy).rgb;
fp = fp*FPRi;
w = getw(fp);
if (w > 0.0) { cmin = min(cmin, pixel); cmax = max(cmax, pixel); }
color = color + w * pixel;
wsum = wsum + w;

y = y + 1.0;

} while (y <= LOOPSIZE);

color = color / wsum;

color = mix(clamp(color, 0.0, 1.0), clamp(color, cmin, cmax), GPAR);

FragColor = vec4(color, 1.0);
}
8 changes: 6 additions & 2 deletions shaders/support_shaders/noshame-blur.slang
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ layout(std140, set = 0, binding = 0) uniform UBO
mat4 MVP;
} global;

const vec3 Y = vec3(.2126, .7152, .0722);

#pragma stage vertex
layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord;
Expand All @@ -21,7 +23,7 @@ layout(location = 0) out vec2 vTexCoord;
void main()
{
gl_Position = global.MVP * Position;
vTexCoord = TexCoord;
vTexCoord = TexCoord*vec2(1.01, 1.01); // Fix shifted Mipmap when lod > 3.0.
}

#pragma stage fragment
Expand All @@ -31,5 +33,7 @@ layout(set = 0, binding = 2) uniform sampler2D Source;

void main()
{
FragColor = vec4(textureLod(Source, vTexCoord, 4.0).rgb, 1.0);
vec3 color = textureLod(Source, vTexCoord, 4.0).rgb;

FragColor = vec4(color, dot(color, Y));
}
Loading

0 comments on commit cbe833d

Please sign in to comment.