fake crt-geom speed-up

Removed unwanted code, simplified, added speed-up option. Gained 10% speed-up on normal operation and 30% on speed-up option enabled.
This commit is contained in:
metallic77 2023-04-26 22:36:59 +03:00 committed by GitHub
parent bd3cbebeee
commit 8b299c5a89
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -9,54 +9,45 @@ layout(push_constant) uniform Push
vec4 OriginalSize; vec4 OriginalSize;
vec4 OutputSize; vec4 OutputSize;
uint FrameCount; uint FrameCount;
float SCANLINE_BASE_BRIGHTNESS; float SCANLINE;
float SCANLINE_SINE_COMP_A;
float SCANLINE_SINE_COMP_B;
float warpX; float warpX;
float warpY; float warpY;
float corner_round; float corner_round;
float cgwg; float cgwg;
float crt_gamma;
float monitor_gamma;
float boost; float boost;
float SHARPNESS;
float SPEEDUP;
} params; } params;
// Parameter lines go here: // Parameter lines go here:
#pragma parameter SCANLINE_SINE_COMP_B "Scanline Intensity" 0.60 0.0 1.0 0.05 #pragma parameter warpX "warpX" 0.02 0.0 0.125 0.01
#define SCANLINE_SINE_COMP_B params.SCANLINE_SINE_COMP_B
#pragma parameter warpX "warpX" 0.03 0.0 0.125 0.01
#define warpX params.warpX #define warpX params.warpX
#pragma parameter warpY "warpY" 0.05 0.0 0.125 0.01 #pragma parameter warpY "warpY" 0.04 0.0 0.125 0.01
#define warpY params.warpY #define warpY params.warpY
#pragma parameter corner_round "Corner Roundness" 0.030 0.005 0.100 0.005 #pragma parameter corner_round "Corner Roundness" 0.030 0.005 0.100 0.005
#define corner_round params.corner_round #define corner_round params.corner_round
#pragma parameter cgwg "CGWG mask str. " 0.5 0.0 1.0 0.1 #pragma parameter SHARPNESS "Blurriness" 0.5 0.0 0.5 0.01
#define SHARPNESS params.SHARPNESS
#pragma parameter SCANLINE "Scanline Intensity" 0.60 0.0 1.0 0.05
#define SCANLINE params.SCANLINE
#pragma parameter cgwg "CGWG mask brightness " 0.6 0.0 1.0 0.1
#define cgwg params.cgwg #define cgwg params.cgwg
#pragma parameter crt_gamma "CRT Gamma" 2.5 1.0 4.0 0.05
#define crt_gamma params.crt_gamma
#pragma parameter monitor_gamma "Monitor Gamma" 2.2 1.0 4.0 0.05
#define monitor_gamma params.monitor_gamma
#pragma parameter boost "Bright boost " 1.00 1.00 2.00 0.02 #pragma parameter boost "Bright boost " 1.00 1.00 2.00 0.02
#define boost params.boost #define boost params.boost
#pragma parameter SCANLINE_SINE_COMP_A "Scanline Sine Comp A" 0.0 0.0 0.10 0.01 #pragma parameter SPEEDUP "Speed-up. Warp,Gamma,Corner disabled" 0.0 0.0 1.0 1.0
#define SCANLINE_SINE_COMP_A params.SCANLINE_SINE_COMP_A #define SPEEDUP params.SPEEDUP
#pragma parameter SCANLINE_BASE_BRIGHTNESS "Scanline Base Brightness" 0.95 0.0 1.0 0.01
#define SCANLINE_BASE_BRIGHTNESS params.SCANLINE_BASE_BRIGHTNESS
#define pi 3.141592654
#define in_gamma vec3(2.4)
#define out_gamma vec3(1.0 / 2.25)
layout(std140, set = 0, binding = 0) uniform UBO layout(std140, set = 0, binding = 0) uniform UBO
{ {
mat4 MVP; mat4 MVP;
@ -66,15 +57,21 @@ layout(std140, set = 0, binding = 0) uniform UBO
layout(location = 0) in vec4 Position; layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord; layout(location = 1) in vec2 TexCoord;
layout(location = 0) out vec2 vTexCoord; layout(location = 0) out vec2 vTexCoord;
layout(location = 1) out float omega;
layout(location = 2) out vec2 pix;
void main() void main()
{ {
gl_Position = global.MVP * Position; gl_Position = global.MVP * Position;
vTexCoord = TexCoord * 1.0001; vTexCoord = TexCoord * 1.0001;
omega = pi * params.SourceSize.y * 2.0;
pix = vec2(1.0, params.SourceSize.z/params.SourceSize.zw);
} }
#pragma stage fragment #pragma stage fragment
layout(location = 0) in vec2 vTexCoord; layout(location = 0) in vec2 vTexCoord;
layout(location = 1) in float omega;
layout(location = 2) in vec2 pix;
layout(location = 0) out vec4 FragColor; layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 1) uniform sampler2D Source; layout(set = 0, binding = 1) uniform sampler2D Source;
@ -83,85 +80,84 @@ layout(set = 0, binding = 1) uniform sampler2D Source;
vec2 Warp(vec2 pos) vec2 Warp(vec2 pos)
{ {
pos = pos*2.0-1.0; pos = 2.0*pos - 1.0;
pos *= vec2(1.0 + (pos.y*pos.y)*warpX, 1.0 + (pos.x*pos.x)*warpY); pos *= vec2(1.0 + (pos.y*pos.y) * warpX,
1.0 + (pos.x*pos.x) * warpY);
return pos*0.5 + 0.5; return pos*0.5 + 0.5;
} }
vec4 scanline(vec2 coord, vec4 frame) vec3 scanline(float y, vec3 frame)
{ {
vec3 scanline = frame*( 1.0 + SCANLINE*sin(y*omega));
vec2 omega = vec2(3.1415 * params.OutputSize.x, 2.0 * 3.1415 * params.SourceSize.y); return scanline;
vec2 sine_comp = vec2(SCANLINE_SINE_COMP_A, SCANLINE_SINE_COMP_B);
vec3 res = frame.xyz;
vec3 scanline = res * (SCANLINE_BASE_BRIGHTNESS + dot(sine_comp * sin(coord * omega), vec2(1.0, 1.0)));
return vec4(scanline.x, scanline.y, scanline.z, 1.0);
} }
float corner(vec2 coord) float corner(vec2 coord)
{ {
coord = (coord - vec2(0.5)) * 1.0 + vec2(0.5); coord = (coord - vec2(0.5)) * 1.0 + vec2(0.5);
coord = min(coord, vec2(1.0)-coord) * vec2(1.0, params.SourceSize.z/params.SourceSize.zw); coord = min(coord, vec2(1.0)-coord) * pix;
vec2 cdist = vec2(corner_round); vec2 cdist = vec2(corner_round);
coord = (cdist - min(coord,cdist)); coord = (cdist - min(coord,cdist));
float dist = sqrt(dot(coord,coord)); float dist = sqrt(dot(coord,coord));
return clamp((cdist.x-dist)*300.0,0.0, 1.0);
return clamp( (cdist.x-dist)*300.0, 0.0, 1.0);
} }
// mask calculation // mask calculation
// cgwg mask. vec3 Mask(float pos)
vec4 Mask(vec2 pos)
{ {
vec3 mask = vec3(1.0); vec3 mask = vec3(1.0);
{
float mf = floor(mod(pos.x,2.0)); float mf = fract(pos*0.5);
float mc = 1.0 - cgwg; if (mf <0.5) mask.g = cgwg;
if (mf == 0.0) { mask.g = mc; } else { mask.r = cgwg; mask.b = cgwg; };
else { mask.r = mc; mask.b = mc; };
} return mask;
return vec4(mask, 1.0);
} }
/////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////
void main() void main()
{ {
vec2 pos = Warp(vTexCoord.xy); vec2 pos;
if (SPEEDUP == 0.0 )
pos = Warp(vTexCoord.xy);
else pos = vTexCoord;
//borrowed from CRT-Pi //borrowed from CRT-Pi
vec2 OGL2Pos = pos * params.SourceSize.xy; vec2 OGL2Pos = pos * params.SourceSize.xy;
vec2 pC4 = floor(OGL2Pos) + 0.5; vec2 pC4 = floor(OGL2Pos) + 0.5;
vec2 coord = pC4 / params.SourceSize.xy; vec2 coord = pC4 / params.SourceSize.xy;
vec2 deltas = OGL2Pos - pC4; vec2 deltas = OGL2Pos - pC4;
vec2 signs = sign(deltas); vec2 signs = sign(deltas);
deltas.x *= 2.0; deltas.x *= 2.0;
deltas = deltas * deltas; deltas = deltas * deltas;
deltas.y = deltas.y * deltas.y; deltas.y = deltas.y * deltas.y;
deltas.x *= 0.5; deltas.x *= SHARPNESS;
deltas.y *= 8.0; deltas.y *= 8.0;
deltas /= params.SourceSize.xy; deltas /= params.SourceSize.xy;
deltas *= signs; deltas *= signs;
vec2 tc = coord + deltas; vec2 tc = coord + deltas;
vec3 res = texture(Source, tc).rgb;
// mask effects look bad unless applied in linear gamma space // mask effects look bad unless applied in linear gamma space
vec4 in_gamma = vec4(crt_gamma, crt_gamma, crt_gamma, 1.0);
vec4 out_gamma = vec4(1.0 / monitor_gamma, 1.0 / monitor_gamma, 1.0 / monitor_gamma, 1.0);
vec4 res = texture(Source, tc); float lum = max(max(res.r,res.b),res.b);
if (SPEEDUP == 0.0) res = pow(res,in_gamma); else res *= mix(0.82,1.05,lum);
res=pow(res,in_gamma);
if (boost != 1.0) res *= mix(1.0,boost,lum);
// apply the mask; looks bad with vert scanlines so make them mutually exclusive // apply the mask;
res *= Mask(vTexCoord * params.OutputSize.xy * 1.0001); res *= Mask(vTexCoord.x * params.OutputSize.x * 1.0001);
// re-apply the gamma curve for the mask path // re-apply the gamma curve for the mask path
vec4 color = pow(scanline(pos, res), out_gamma); vec3 color = scanline(pos.y, res);
float lum = color.r*0.3+color.g*0.6+color.b*0.1; if (SPEEDUP == 0.0) color = pow( color, out_gamma); else color;
color*= mix(1.0,boost,lum); if (SPEEDUP == 0.0 ) color = color*corner(tc);
FragColor = color*corner(tc);
FragColor = vec4(color,1.0) ;
} }