2023-04-08 00:10:33 +10:00
|
|
|
#version 450
|
|
|
|
|
|
|
|
// Simple scanlines with curvature and mask effects lifted from crt-geom
|
|
|
|
// original by hunterk, edited by DariusG
|
|
|
|
|
|
|
|
layout(push_constant) uniform Push
|
|
|
|
{
|
|
|
|
vec4 SourceSize;
|
|
|
|
vec4 OriginalSize;
|
|
|
|
vec4 OutputSize;
|
|
|
|
uint FrameCount;
|
2023-04-27 05:36:59 +10:00
|
|
|
float SCANLINE;
|
2023-04-08 00:10:33 +10:00
|
|
|
float warpX;
|
|
|
|
float warpY;
|
|
|
|
float corner_round;
|
|
|
|
float cgwg;
|
|
|
|
float boost;
|
2023-04-27 05:36:59 +10:00
|
|
|
float SHARPNESS;
|
|
|
|
float SPEEDUP;
|
2023-04-08 00:10:33 +10:00
|
|
|
} params;
|
|
|
|
|
|
|
|
// Parameter lines go here:
|
2023-04-27 05:36:59 +10:00
|
|
|
#pragma parameter warpX "warpX" 0.02 0.0 0.125 0.01
|
2023-04-08 00:10:33 +10:00
|
|
|
#define warpX params.warpX
|
|
|
|
|
2023-04-27 05:36:59 +10:00
|
|
|
#pragma parameter warpY "warpY" 0.04 0.0 0.125 0.01
|
2023-04-08 00:10:33 +10:00
|
|
|
#define warpY params.warpY
|
|
|
|
|
|
|
|
#pragma parameter corner_round "Corner Roundness" 0.030 0.005 0.100 0.005
|
|
|
|
#define corner_round params.corner_round
|
|
|
|
|
2023-04-27 05:36:59 +10:00
|
|
|
#pragma parameter SHARPNESS "Blurriness" 0.5 0.0 0.5 0.01
|
|
|
|
#define SHARPNESS params.SHARPNESS
|
2023-04-08 00:10:33 +10:00
|
|
|
|
2023-04-27 05:36:59 +10:00
|
|
|
#pragma parameter SCANLINE "Scanline Intensity" 0.60 0.0 1.0 0.05
|
|
|
|
#define SCANLINE params.SCANLINE
|
2023-04-08 00:10:33 +10:00
|
|
|
|
2023-04-27 05:36:59 +10:00
|
|
|
#pragma parameter cgwg "CGWG mask brightness " 0.6 0.0 1.0 0.1
|
|
|
|
#define cgwg params.cgwg
|
2023-04-08 00:10:33 +10:00
|
|
|
|
|
|
|
#pragma parameter boost "Bright boost " 1.00 1.00 2.00 0.02
|
|
|
|
#define boost params.boost
|
|
|
|
|
2023-04-27 05:36:59 +10:00
|
|
|
#pragma parameter SPEEDUP "Speed-up. Warp,Gamma,Corner disabled" 0.0 0.0 1.0 1.0
|
|
|
|
#define SPEEDUP params.SPEEDUP
|
2023-04-08 00:10:33 +10:00
|
|
|
|
2023-04-27 05:36:59 +10:00
|
|
|
#define pi 3.141592654
|
|
|
|
#define in_gamma vec3(2.4)
|
|
|
|
#define out_gamma vec3(1.0 / 2.25)
|
|
|
|
|
2023-04-08 00:10:33 +10:00
|
|
|
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;
|
2023-04-27 05:36:59 +10:00
|
|
|
layout(location = 1) out float omega;
|
|
|
|
layout(location = 2) out vec2 pix;
|
2023-04-08 00:10:33 +10:00
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
gl_Position = global.MVP * Position;
|
|
|
|
vTexCoord = TexCoord * 1.0001;
|
2023-04-27 05:36:59 +10:00
|
|
|
omega = pi * params.SourceSize.y * 2.0;
|
|
|
|
pix = vec2(1.0, params.SourceSize.z/params.SourceSize.zw);
|
2023-04-08 00:10:33 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma stage fragment
|
|
|
|
layout(location = 0) in vec2 vTexCoord;
|
2023-04-27 05:36:59 +10:00
|
|
|
layout(location = 1) in float omega;
|
|
|
|
layout(location = 2) in vec2 pix;
|
2023-04-08 00:10:33 +10:00
|
|
|
layout(location = 0) out vec4 FragColor;
|
|
|
|
layout(set = 0, binding = 1) uniform sampler2D Source;
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
vec2 Warp(vec2 pos)
|
|
|
|
{
|
2023-04-27 05:36:59 +10:00
|
|
|
pos = 2.0*pos - 1.0;
|
|
|
|
pos *= vec2(1.0 + (pos.y*pos.y) * warpX,
|
|
|
|
1.0 + (pos.x*pos.x) * warpY);
|
2023-04-08 00:10:33 +10:00
|
|
|
|
|
|
|
return pos*0.5 + 0.5;
|
|
|
|
}
|
|
|
|
|
2023-04-27 05:36:59 +10:00
|
|
|
vec3 scanline(float y, vec3 frame)
|
2023-04-08 00:10:33 +10:00
|
|
|
{
|
2023-04-27 05:36:59 +10:00
|
|
|
vec3 scanline = frame*( 1.0 + SCANLINE*sin(y*omega));
|
2023-04-08 00:10:33 +10:00
|
|
|
|
2023-04-27 05:36:59 +10:00
|
|
|
return scanline;
|
2023-04-08 00:10:33 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
float corner(vec2 coord)
|
|
|
|
{
|
|
|
|
coord = (coord - vec2(0.5)) * 1.0 + vec2(0.5);
|
2023-04-27 05:36:59 +10:00
|
|
|
coord = min(coord, vec2(1.0)-coord) * pix;
|
|
|
|
vec2 cdist = vec2(corner_round);
|
2023-04-08 00:10:33 +10:00
|
|
|
coord = (cdist - min(coord,cdist));
|
2023-04-27 05:36:59 +10:00
|
|
|
float dist = sqrt(dot(coord,coord));
|
|
|
|
|
|
|
|
return clamp( (cdist.x-dist)*300.0, 0.0, 1.0);
|
2023-04-08 00:10:33 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
// mask calculation
|
2023-04-27 05:36:59 +10:00
|
|
|
vec3 Mask(float pos)
|
2023-04-08 00:10:33 +10:00
|
|
|
{
|
|
|
|
vec3 mask = vec3(1.0);
|
2023-04-27 05:36:59 +10:00
|
|
|
|
|
|
|
float mf = fract(pos*0.5);
|
|
|
|
if (mf <0.5) mask.g = cgwg;
|
|
|
|
else { mask.r = cgwg; mask.b = cgwg; };
|
|
|
|
|
|
|
|
return mask;
|
2023-04-08 00:10:33 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void main()
|
2023-04-27 05:36:59 +10:00
|
|
|
{
|
|
|
|
vec2 pos;
|
|
|
|
if (SPEEDUP == 0.0 )
|
|
|
|
pos = Warp(vTexCoord.xy);
|
|
|
|
else pos = vTexCoord;
|
2023-04-08 00:10:33 +10:00
|
|
|
|
|
|
|
//borrowed from CRT-Pi
|
2023-04-27 05:36:59 +10:00
|
|
|
vec2 OGL2Pos = pos * params.SourceSize.xy;
|
|
|
|
vec2 pC4 = floor(OGL2Pos) + 0.5;
|
|
|
|
vec2 coord = pC4 / params.SourceSize.xy;
|
|
|
|
vec2 deltas = OGL2Pos - pC4;
|
|
|
|
vec2 signs = sign(deltas);
|
2023-04-08 00:10:33 +10:00
|
|
|
deltas.x *= 2.0;
|
|
|
|
deltas = deltas * deltas;
|
|
|
|
deltas.y = deltas.y * deltas.y;
|
2023-04-27 05:36:59 +10:00
|
|
|
deltas.x *= SHARPNESS;
|
2023-04-08 00:10:33 +10:00
|
|
|
deltas.y *= 8.0;
|
|
|
|
deltas /= params.SourceSize.xy;
|
|
|
|
deltas *= signs;
|
2023-04-27 05:36:59 +10:00
|
|
|
vec2 tc = coord + deltas;
|
2023-04-08 00:10:33 +10:00
|
|
|
|
2023-04-27 05:36:59 +10:00
|
|
|
vec3 res = texture(Source, tc).rgb;
|
2023-04-08 00:10:33 +10:00
|
|
|
|
|
|
|
// mask effects look bad unless applied in linear gamma space
|
|
|
|
|
2023-04-27 05:36:59 +10:00
|
|
|
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);
|
|
|
|
|
|
|
|
if (boost != 1.0) res *= mix(1.0,boost,lum);
|
|
|
|
|
|
|
|
// apply the mask;
|
|
|
|
res *= Mask(vTexCoord.x * params.OutputSize.x * 1.0001);
|
2023-04-08 00:10:33 +10:00
|
|
|
|
2023-04-27 05:36:59 +10:00
|
|
|
// re-apply the gamma curve for the mask path
|
|
|
|
vec3 color = scanline(pos.y, res);
|
|
|
|
if (SPEEDUP == 0.0) color = pow( color, out_gamma); else color;
|
|
|
|
if (SPEEDUP == 0.0 ) color = color*corner(tc);
|
2023-04-08 00:10:33 +10:00
|
|
|
|
2023-04-27 05:36:59 +10:00
|
|
|
FragColor = vec4(color,1.0) ;
|
2023-04-08 00:10:33 +10:00
|
|
|
|
|
|
|
}
|