mirror of
https://github.com/libretro/slang-shaders.git
synced 2024-11-26 18:10:33 +00:00
Update geom.slang (#606)
* Update geom.slang - Change some var names to not conflict with other shaders. * FIx for Geom shader - Fix moire artifacts; - Rename all vars using 'geom_' prefix to not conflict with other shaders vars; - Added geom-append preset.
This commit is contained in:
parent
89dfd9bbd0
commit
3796d44482
9
misc/geom-append.slangp
Normal file
9
misc/geom-append.slangp
Normal file
@ -0,0 +1,9 @@
|
||||
shaders = 1
|
||||
|
||||
shader0 = shaders/geom.slang
|
||||
filter_linear0 = true
|
||||
scale_type0 = viewport
|
||||
wrap_mode0 = "clamp_to_border"
|
||||
mipmap_input0 = "true"
|
||||
|
||||
geom_lod_bias = "0.500000"
|
@ -1,5 +1,12 @@
|
||||
shaders = 1
|
||||
shaders = 2
|
||||
|
||||
shader0 = shaders/geom.slang
|
||||
shader0 = ../stock.slang
|
||||
filter_linear0 = false
|
||||
scale_type0 = viewport
|
||||
wrap_mode0 = "clamp_to_border"
|
||||
|
||||
shader1 = shaders/geom.slang
|
||||
filter_linear1 = true
|
||||
scale_type1 = viewport
|
||||
wrap_mode1 = "clamp_to_border"
|
||||
mipmap_input1 = "true"
|
||||
|
||||
|
@ -3,24 +3,22 @@
|
||||
layout(push_constant) uniform Push
|
||||
{
|
||||
uint FrameCount;
|
||||
float targetgamma;
|
||||
float monitorgamma;
|
||||
float d;
|
||||
float R;
|
||||
float cornersize;
|
||||
float cornersmooth;
|
||||
float x_tilt;
|
||||
float y_tilt;
|
||||
float overscan_x;
|
||||
float overscan_y;
|
||||
float SHARPER;
|
||||
float CURVATURE;
|
||||
float interlace_detect;
|
||||
float lum;
|
||||
float invert_aspect;
|
||||
float xsize;
|
||||
float ysize;
|
||||
} registers;
|
||||
float geom_target_gamma;
|
||||
float geom_monitor_gamma;
|
||||
float geom_d;
|
||||
float geom_R;
|
||||
float geom_cornersize;
|
||||
float geom_cornersmooth;
|
||||
float geom_x_tilt;
|
||||
float geom_y_tilt;
|
||||
float geom_overscan_x;
|
||||
float geom_overscan_y;
|
||||
float geom_sharper;
|
||||
float geom_curvature;
|
||||
float geom_lum;
|
||||
float geom_invert_aspect;
|
||||
float geom_lod_bias;
|
||||
} reg;
|
||||
|
||||
layout(std140, set = 0, binding = 0) uniform UBO
|
||||
{
|
||||
@ -29,34 +27,29 @@ layout(std140, set = 0, binding = 0) uniform UBO
|
||||
vec4 SourceSize;
|
||||
} global;
|
||||
|
||||
#pragma parameter targetgamma "Geom Target Gamma" 2.4 0.1 5.0 0.1
|
||||
#pragma parameter monitorgamma "Geom Monitor Gamma" 2.2 0.1 5.0 0.1
|
||||
#pragma parameter d "Geom Distance" 1.5 0.1 3.0 0.1
|
||||
#pragma parameter CURVATURE "Geom Curvature Toggle" 1.0 0.0 1.0 1.0
|
||||
#pragma parameter invert_aspect "Geom Curvature Aspect Inversion" 0.0 0.0 1.0 1.0
|
||||
#pragma parameter R "Geom Curvature Radius" 2.0 0.1 10.0 0.1
|
||||
#pragma parameter cornersize "Geom Corner Size" 0.03 0.001 1.0 0.005
|
||||
#pragma parameter cornersmooth "Geom Corner Smoothness" 1000.0 80.0 2000.0 100.0
|
||||
#pragma parameter x_tilt "Geom Horizontal Tilt" 0.0 -0.5 0.5 0.05
|
||||
#pragma parameter y_tilt "Geom Vertical Tilt" 0.0 -0.5 0.5 0.05
|
||||
#pragma parameter overscan_x "Geom Horiz. Overscan %" 100.0 -125.0 125.0 0.5
|
||||
#pragma parameter overscan_y "Geom Vert. Overscan %" 100.0 -125.0 125.0 0.5
|
||||
#pragma parameter SHARPER "Geom Sharpness" 1.0 1.0 3.0 1.0
|
||||
#pragma parameter lum "Geom Luminance" 1.0 0.5 2.0 0.01
|
||||
#pragma parameter interlace_detect "Geom Interlacing Simulation" 1.0 0.0 1.0 1.0
|
||||
#pragma parameter geom_params "[ GEOM USER PARAMETERS ]" 0.0 0.0 1.0 1.0
|
||||
#pragma parameter geom_curvature "Geom Curvature Toggle" 1.0 0.0 1.0 1.0
|
||||
#pragma parameter geom_R "Geom Curvature Radius" 2.0 0.1 10.0 0.1
|
||||
#pragma parameter geom_d "Geom Distance" 1.5 0.1 3.0 0.1
|
||||
#pragma parameter geom_invert_aspect "Geom Curvature Aspect Inversion" 0.0 0.0 1.0 1.0
|
||||
#pragma parameter geom_cornersize "Geom Corner Size" 0.03 0.001 1.0 0.005
|
||||
#pragma parameter geom_cornersmooth "Geom Corner Smoothness" 1000.0 80.0 2000.0 100.0
|
||||
#pragma parameter geom_x_tilt "Geom Horizontal Tilt" 0.0 -0.5 0.5 0.05
|
||||
#pragma parameter geom_y_tilt "Geom Vertical Tilt" 0.0 -0.5 0.5 0.05
|
||||
#pragma parameter geom_overscan_x "Geom Horiz. Overscan %" 100.0 -125.0 125.0 0.5
|
||||
#pragma parameter geom_overscan_y "Geom Vert. Overscan %" 100.0 -125.0 125.0 0.5
|
||||
#pragma parameter geom_lod_bias "Geom Anti-Aliasing Boost" 0.0 0.0 1.0 0.05
|
||||
#pragma parameter geom_sharper "Geom Sharpness" 1.0 1.0 3.0 1.0
|
||||
#pragma parameter geom_lum "Geom Luminance" 1.0 0.5 2.0 0.01
|
||||
#pragma parameter geom_target_gamma "Geom Target Gamma" 2.4 0.1 5.0 0.1
|
||||
#pragma parameter geom_monitor_gamma "Geom Monitor Gamma" 2.2 0.1 5.0 0.1
|
||||
|
||||
#pragma parameter xsize "Simulated Width (0==Auto)" 0.0 0.0 1920.0 16.0
|
||||
#pragma parameter ysize "Simulated Height (0==Auto)" 0.0 0.0 1080.0 16.0
|
||||
|
||||
vec2 height = (registers.ysize > 0.001) ? vec2(registers.ysize, 1./registers.ysize) : global.SourceSize.yw;
|
||||
vec2 width = (registers.xsize > 0.001) ? vec2(registers.xsize, 1./registers.xsize) : global.SourceSize.xz;
|
||||
vec4 SourceSize = vec4(width.x, height.x, width.y, height.y);
|
||||
|
||||
/*
|
||||
Geom Shader - a modified CRT-Geom without CRT features made to be appended/integrated
|
||||
into any other shaders and provide curvature/warping/oversampling features.
|
||||
|
||||
Adaptation by Hyllian (2024).
|
||||
Adapted by Hyllian (2024).
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -96,13 +89,13 @@ vec4 SourceSize = vec4(width.x, height.x, width.y, height.y);
|
||||
#define PI 3.141592653589
|
||||
|
||||
#ifdef LINEAR_PROCESSING
|
||||
# define TEX2D(c) pow(texture(Source, (c)), vec4(registers.targetgamma))
|
||||
# define TEX2D(c) pow(trilinear(Source, (c), TextureSize), vec4(reg.geom_target_gamma))
|
||||
#else
|
||||
# define TEX2D(c) texture(Source, (c))
|
||||
#endif
|
||||
|
||||
// aspect ratio
|
||||
vec2 aspect = vec2(registers.invert_aspect > 0.5 ? (0.75, 1.0) : (1.0, 0.75));
|
||||
vec2 aspect = vec2(reg.geom_invert_aspect > 0.5 ? (0.75, 1.0) : (1.0, 0.75));
|
||||
vec2 overscan = vec2(1.01, 1.01);
|
||||
|
||||
#pragma stage vertex
|
||||
@ -112,14 +105,13 @@ layout(location = 0) out vec2 vTexCoord;
|
||||
layout(location = 1) out vec2 sinangle;
|
||||
layout(location = 2) out vec2 cosangle;
|
||||
layout(location = 3) out vec3 stretch;
|
||||
layout(location = 4) out vec2 ilfac;
|
||||
layout(location = 5) out vec2 TextureSize;
|
||||
layout(location = 4) out vec2 TextureSize;
|
||||
|
||||
float intersect(vec2 xy)
|
||||
{
|
||||
float A = dot(xy,xy) + registers.d*registers.d;
|
||||
float B = 2.0*(registers.R*(dot(xy,sinangle)-registers.d*cosangle.x*cosangle.y)-registers.d*registers.d);
|
||||
float C = registers.d*registers.d + 2.0*registers.R*registers.d*cosangle.x*cosangle.y;
|
||||
float A = dot(xy,xy) + reg.geom_d*reg.geom_d;
|
||||
float B = 2.0*(reg.geom_R*(dot(xy,sinangle)-reg.geom_d*cosangle.x*cosangle.y)-reg.geom_d*reg.geom_d);
|
||||
float C = reg.geom_d*reg.geom_d + 2.0*reg.geom_R*reg.geom_d*cosangle.x*cosangle.y;
|
||||
|
||||
return (-B-sqrt(B*B-4.0*A*C))/(2.0*A);
|
||||
}
|
||||
@ -127,7 +119,7 @@ float intersect(vec2 xy)
|
||||
vec2 bkwtrans(vec2 xy)
|
||||
{
|
||||
float c = intersect(xy);
|
||||
vec2 point = (vec2(c, c)*xy - vec2(-registers.R, -registers.R)*sinangle) / vec2(registers.R, registers.R);
|
||||
vec2 point = (vec2(c, c)*xy - vec2(-reg.geom_R, -reg.geom_R)*sinangle) / vec2(reg.geom_R, reg.geom_R);
|
||||
vec2 poc = point/cosangle;
|
||||
|
||||
vec2 tang = sinangle/cosangle;
|
||||
@ -137,24 +129,24 @@ vec2 bkwtrans(vec2 xy)
|
||||
|
||||
float a = (-B + sqrt(B*B - 4.0*A*C))/(2.0*A);
|
||||
vec2 uv = (point - a*sinangle)/cosangle;
|
||||
float r = FIX(registers.R*acos(a));
|
||||
float r = FIX(reg.geom_R*acos(a));
|
||||
|
||||
return uv*r/sin(r/registers.R);
|
||||
return uv*r/sin(r/reg.geom_R);
|
||||
}
|
||||
|
||||
vec2 fwtrans(vec2 uv)
|
||||
{
|
||||
float r = FIX(sqrt(dot(uv,uv)));
|
||||
uv *= sin(r/registers.R)/r;
|
||||
float x = 1.0-cos(r/registers.R);
|
||||
float D = registers.d/registers.R + x*cosangle.x*cosangle.y+dot(uv,sinangle);
|
||||
uv *= sin(r/reg.geom_R)/r;
|
||||
float x = 1.0-cos(r/reg.geom_R);
|
||||
float D = reg.geom_d/reg.geom_R + x*cosangle.x*cosangle.y+dot(uv,sinangle);
|
||||
|
||||
return registers.d*(uv*cosangle-x*sinangle)/D;
|
||||
return reg.geom_d*(uv*cosangle-x*sinangle)/D;
|
||||
}
|
||||
|
||||
vec3 maxscale()
|
||||
{
|
||||
vec2 c = bkwtrans(-registers.R * sinangle / (1.0 + registers.R/registers.d*cosangle.x*cosangle.y));
|
||||
vec2 c = bkwtrans(-reg.geom_R * sinangle / (1.0 + reg.geom_R/reg.geom_d*cosangle.x*cosangle.y));
|
||||
vec2 a = vec2(0.5,0.5)*aspect;
|
||||
|
||||
vec2 lo = vec2(fwtrans(vec2(-a.x, c.y)).x,
|
||||
@ -175,13 +167,11 @@ void main()
|
||||
|
||||
// Precalculate a bunch of useful values we'll need in the fragment
|
||||
// shader.
|
||||
sinangle = sin(vec2(registers.x_tilt, registers.y_tilt));
|
||||
cosangle = cos(vec2(registers.x_tilt, registers.y_tilt));
|
||||
sinangle = sin(vec2(reg.geom_x_tilt, reg.geom_y_tilt));
|
||||
cosangle = cos(vec2(reg.geom_x_tilt, reg.geom_y_tilt));
|
||||
stretch = maxscale();
|
||||
|
||||
TextureSize = vec2(registers.SHARPER * SourceSize.x, SourceSize.y);
|
||||
|
||||
ilfac = vec2(1.0, clamp(floor(SourceSize.y/(registers.interlace_detect > 0.5 ? 200.0 : 1000)), 1.0, 2.0));
|
||||
TextureSize = vec2(reg.geom_sharper * global.SourceSize.x, global.SourceSize.y);
|
||||
}
|
||||
|
||||
#pragma stage fragment
|
||||
@ -189,18 +179,17 @@ layout(location = 0) in vec2 vTexCoord;
|
||||
layout(location = 1) in vec2 sinangle;
|
||||
layout(location = 2) in vec2 cosangle;
|
||||
layout(location = 3) in vec3 stretch;
|
||||
layout(location = 4) in vec2 ilfac;
|
||||
layout(location = 5) in vec2 TextureSize;
|
||||
layout(location = 4) in vec2 TextureSize;
|
||||
layout(location = 0) out vec4 FragColor;
|
||||
layout(set = 0, binding = 2) uniform sampler2D Source;
|
||||
|
||||
float intersect(vec2 xy)
|
||||
{
|
||||
float A = dot(xy,xy) + registers.d*registers.d;
|
||||
float A = dot(xy,xy) + reg.geom_d*reg.geom_d;
|
||||
float B, C;
|
||||
|
||||
B = 2.0*(registers.R*(dot(xy,sinangle) - registers.d*cosangle.x*cosangle.y) - registers.d*registers.d);
|
||||
C = registers.d*registers.d + 2.0*registers.R*registers.d*cosangle.x*cosangle.y;
|
||||
B = 2.0*(reg.geom_R*(dot(xy,sinangle) - reg.geom_d*cosangle.x*cosangle.y) - reg.geom_d*reg.geom_d);
|
||||
C = reg.geom_d*reg.geom_d + 2.0*reg.geom_R*reg.geom_d*cosangle.x*cosangle.y;
|
||||
|
||||
return (-B-sqrt(B*B - 4.0*A*C))/(2.0*A);
|
||||
}
|
||||
@ -208,7 +197,7 @@ float intersect(vec2 xy)
|
||||
vec2 bkwtrans(vec2 xy)
|
||||
{
|
||||
float c = intersect(xy);
|
||||
vec2 point = (vec2(c, c)*xy - vec2(-registers.R, -registers.R)*sinangle) / vec2(registers.R, registers.R);
|
||||
vec2 point = (vec2(c, c)*xy - vec2(-reg.geom_R, -reg.geom_R)*sinangle) / vec2(reg.geom_R, reg.geom_R);
|
||||
vec2 poc = point/cosangle;
|
||||
vec2 tang = sinangle/cosangle;
|
||||
|
||||
@ -218,26 +207,26 @@ vec2 bkwtrans(vec2 xy)
|
||||
|
||||
float a = (-B + sqrt(B*B - 4.0*A*C)) / (2.0*A);
|
||||
vec2 uv = (point - a*sinangle) / cosangle;
|
||||
float r = FIX(registers.R*acos(a));
|
||||
float r = FIX(reg.geom_R*acos(a));
|
||||
|
||||
return uv*r/sin(r/registers.R);
|
||||
return uv*r/sin(r/reg.geom_R);
|
||||
}
|
||||
|
||||
vec2 fwtrans(vec2 uv)
|
||||
{
|
||||
float r = FIX(sqrt(dot(uv, uv)));
|
||||
uv *= sin(r/registers.R)/r;
|
||||
float x = 1.0 - cos(r/registers.R);
|
||||
uv *= sin(r/reg.geom_R)/r;
|
||||
float x = 1.0 - cos(r/reg.geom_R);
|
||||
float D;
|
||||
|
||||
D = registers.d/registers.R + x*cosangle.x*cosangle.y + dot(uv,sinangle);
|
||||
D = reg.geom_d/reg.geom_R + x*cosangle.x*cosangle.y + dot(uv,sinangle);
|
||||
|
||||
return registers.d*(uv*cosangle - x*sinangle)/D;
|
||||
return reg.geom_d*(uv*cosangle - x*sinangle)/D;
|
||||
}
|
||||
|
||||
vec3 maxscale()
|
||||
{
|
||||
vec2 c = bkwtrans(-registers.R * sinangle / (1.0 + registers.R/registers.d*cosangle.x*cosangle.y));
|
||||
vec2 c = bkwtrans(-reg.geom_R * sinangle / (1.0 + reg.geom_R/reg.geom_d*cosangle.x*cosangle.y));
|
||||
vec2 a = vec2(0.5, 0.5)*aspect;
|
||||
|
||||
vec2 lo = vec2(fwtrans(vec2(-a.x, c.y)).x,
|
||||
@ -254,18 +243,34 @@ vec2 transform(vec2 coord)
|
||||
coord = (coord - vec2(0.5, 0.5))*aspect*stretch.z + stretch.xy;
|
||||
|
||||
return (bkwtrans(coord) /
|
||||
vec2(registers.overscan_x / 100.0, registers.overscan_y / 100.0)/aspect + vec2(0.5, 0.5));
|
||||
vec2(reg.geom_overscan_x / 100.0, reg.geom_overscan_y / 100.0)/aspect + vec2(0.5, 0.5));
|
||||
}
|
||||
|
||||
float corner(vec2 coord)
|
||||
{
|
||||
coord = (coord - vec2(0.5)) * vec2(registers.overscan_x / 100.0, registers.overscan_y / 100.0) + vec2(0.5, 0.5);
|
||||
coord = (coord - vec2(0.5)) * vec2(reg.geom_overscan_x / 100.0, reg.geom_overscan_y / 100.0) + vec2(0.5, 0.5);
|
||||
coord = min(coord, vec2(1.0) - coord) * aspect;
|
||||
vec2 cdist = vec2(registers.cornersize);
|
||||
vec2 cdist = vec2(reg.geom_cornersize);
|
||||
coord = (cdist - min(coord, cdist));
|
||||
float dist = sqrt(dot(coord, coord));
|
||||
|
||||
return clamp((cdist.x - dist)*registers.cornersmooth, 0.0, 1.0);
|
||||
return clamp((cdist.x - dist)*reg.geom_cornersmooth, 0.0, 1.0);
|
||||
}
|
||||
|
||||
// Code provided by fishku.
|
||||
vec4 trilinear(sampler2D Src, vec2 uv, vec2 texsize)
|
||||
{
|
||||
const vec2 d_uv_dx = dFdx(uv) * texsize.xy;
|
||||
const vec2 d_uv_dy = dFdy(uv) * texsize.xy;
|
||||
|
||||
// Anisotropic trilinear filtering.
|
||||
// Implement in software because current implementation is broken. See:
|
||||
// https://github.com/libretro/RetroArch/issues/16567
|
||||
const float lambda_base = max(0.0, 0.5 * log2(max(dot(d_uv_dx, d_uv_dx), dot(d_uv_dy, d_uv_dy)))) + reg.geom_lod_bias;
|
||||
float lambda_i;
|
||||
const float lambda_f = modf(lambda_base, lambda_i);
|
||||
|
||||
return mix(textureLod(Src, uv, lambda_i), textureLod(Src, uv, lambda_i + 1.0), lambda_f);
|
||||
}
|
||||
|
||||
void main()
|
||||
@ -273,37 +278,27 @@ void main()
|
||||
// Texture coordinates of the texel containing the active pixel.
|
||||
vec2 xy;
|
||||
|
||||
if (registers.CURVATURE > 0.5)
|
||||
if (reg.geom_curvature > 0.5)
|
||||
xy = transform(vTexCoord);
|
||||
else
|
||||
xy = vTexCoord;
|
||||
|
||||
float cval = corner(xy);
|
||||
|
||||
// Of all the pixels that are mapped onto the texel we are
|
||||
// currently rendering, which pixel are we currently rendering?
|
||||
vec2 ilvec;
|
||||
ilvec = vec2(0.0, ilfac.y * registers.interlace_detect > 1.5 ? mod(float(registers.FrameCount), 2.0) : 0.0);
|
||||
|
||||
vec2 ratio_scale = (xy * TextureSize - vec2(0.5, 0.5) + ilvec) / ilfac;
|
||||
vec2 uv_ratio = fract(ratio_scale);
|
||||
|
||||
// Snap to the center of the underlying texel.
|
||||
xy = (floor(ratio_scale)*ilfac + vec2(0.5, 0.5) - ilvec) / TextureSize;
|
||||
vec2 uv_ratio = fract((xy * TextureSize - vec2(0.5, 0.5)) / TextureSize);
|
||||
|
||||
vec4 col = TEX2D(xy);
|
||||
|
||||
|
||||
#ifndef LINEAR_PROCESSING
|
||||
col = pow(col , vec4(registers.targetgamma));
|
||||
col = pow(col , vec4(reg.geom_target_gamma));
|
||||
#endif
|
||||
|
||||
col.rgb *= (registers.lum * step(0.0, uv_ratio.y));
|
||||
col.rgb *= (reg.geom_lum * step(0.0, uv_ratio.y));
|
||||
|
||||
vec3 mul_res = col.rgb * vec3(cval);
|
||||
|
||||
// Convert the image gamma for display on our output device.
|
||||
mul_res = pow(mul_res, vec3(1.0 / registers.monitorgamma));
|
||||
mul_res = pow(mul_res, vec3(1.0 / reg.geom_monitor_gamma));
|
||||
|
||||
FragColor = vec4(mul_res, 1.0);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user