mirror of
https://github.com/italicsjenga/slang-shaders.git
synced 2024-11-23 00:01:31 +11:00
Merge pull request #462 from metallic77/slang
Update fake-crt-geom.slang
This commit is contained in:
commit
3e5801626f
|
@ -9,53 +9,50 @@ layout(push_constant) uniform Push
|
|||
vec4 OriginalSize;
|
||||
vec4 OutputSize;
|
||||
uint FrameCount;
|
||||
float SCANLINE;
|
||||
float SCANLINE_SINE_COMP_B;
|
||||
float warpX;
|
||||
float warpY;
|
||||
float corner_round;
|
||||
float cgwg;
|
||||
float boost;
|
||||
float SHARPNESS;
|
||||
float SPEEDUP;
|
||||
float WP;
|
||||
float sat;
|
||||
float boost,monitor_gamma,crt_gamma;
|
||||
float SIZE,GLOW_LINE;
|
||||
|
||||
} params;
|
||||
|
||||
// Parameter lines go here:
|
||||
#pragma parameter warpX "warpX" 0.02 0.0 0.125 0.01
|
||||
#pragma parameter SCANLINE_SINE_COMP_B "Scanline Intensity" 0.3 0.0 1.0 0.05
|
||||
#pragma parameter SIZE "Scanline size" 1.0 0.5 2.0 0.5
|
||||
#pragma parameter warpX "warpX" 0.03 0.0 0.125 0.01
|
||||
#pragma parameter warpY "warpY" 0.05 0.0 0.125 0.01
|
||||
#pragma parameter corner_round "Corner Roundness" 0.030 0.005 0.100 0.005
|
||||
#pragma parameter cgwg "CGWG mask brightness" 0.7 0.0 1.0 0.1
|
||||
#pragma parameter crt_gamma "CRT Gamma" 2.4 1.0 4.0 0.05
|
||||
#pragma parameter monitor_gamma "Monitor Gamma" 2.25 1.0 4.0 0.05
|
||||
#pragma parameter boost "Bright boost " 0.20 0.00 1.00 0.02
|
||||
#pragma parameter GLOW_LINE "Glowing line" 0.006 0.00 0.20 0.001
|
||||
|
||||
|
||||
#define SCANLINE_SINE_COMP_B params.SCANLINE_SINE_COMP_B
|
||||
#define SIZE params.SIZE
|
||||
#define warpX params.warpX
|
||||
|
||||
#pragma parameter warpY "warpY" 0.04 0.0 0.125 0.01
|
||||
#define warpY params.warpY
|
||||
|
||||
#pragma parameter corner_round "Corner Roundness" 0.020 0.005 0.100 0.01
|
||||
#define corner_round params.corner_round
|
||||
|
||||
#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
|
||||
|
||||
#pragma parameter boost " Bright boost " 1.00 1.00 2.00 0.02
|
||||
#define crt_gamma params.crt_gamma
|
||||
#define monitor_gamma params.monitor_gamma
|
||||
#define boost params.boost
|
||||
#define GLOW_LINE params.GLOW_LINE
|
||||
|
||||
#pragma parameter sat " Saturation" 1.0 0.0 2.0 0.05
|
||||
#define sat params.sat
|
||||
|
||||
#pragma parameter WP " Color Temperature" 0.0 -0.25 0.25 0.01
|
||||
#define WP params.WP
|
||||
#define OutputSize params.OutputSize
|
||||
#define SourceSize params.SourceSize
|
||||
#define OriginalSize params.OriginalSize
|
||||
#define FrameCount params.FrameCount
|
||||
#define pi 3.141592
|
||||
#define in_gamma vec4(crt_gamma, crt_gamma, crt_gamma, 1.0)
|
||||
#define out_gamma vec4(1.0 / monitor_gamma, 1.0 / monitor_gamma, 1.0 / monitor_gamma, 1.0)
|
||||
#define scale vec4(SourceSize.xy/OriginalSize.xy,OriginalSize.xy/SourceSize.xy)
|
||||
|
||||
#pragma parameter SPEEDUP "Speed-up. Warp,Gamma,Corner disabled" 0.0 0.0 1.0 1.0
|
||||
#define SPEEDUP params.SPEEDUP
|
||||
|
||||
#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
|
||||
{
|
||||
|
@ -66,114 +63,105 @@ layout(std140, set = 0, binding = 0) uniform UBO
|
|||
layout(location = 0) in vec4 Position;
|
||||
layout(location = 1) in vec2 TexCoord;
|
||||
layout(location = 0) out vec2 vTexCoord;
|
||||
layout(location = 1) out float omega;
|
||||
layout(location = 2) out vec2 pix;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = global.MVP * Position;
|
||||
vTexCoord = TexCoord * 1.0001;
|
||||
omega = pi * params.SourceSize.y * 2.0;
|
||||
pix = vec2(1.0, params.SourceSize.z/params.SourceSize.zw);
|
||||
}
|
||||
|
||||
#pragma stage fragment
|
||||
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(set = 0, binding = 1) uniform sampler2D Source;
|
||||
|
||||
#define iTimer (float(FrameCount)*60.0)
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
vec4 scanline(vec2 coord, vec4 frame, float l)
|
||||
{
|
||||
float SCANLINE_SINE_COMP = mix(SCANLINE_SINE_COMP_B*1.5,SCANLINE_SINE_COMP_B,l);
|
||||
vec3 res = frame.xyz;
|
||||
vec3 scanline = res * (SCANLINE_SINE_COMP*sin(fract(coord.y*SIZE*SourceSize.y)*pi)+1.0- SCANLINE_SINE_COMP);
|
||||
|
||||
return vec4(scanline, 1.0);
|
||||
}
|
||||
|
||||
|
||||
// Distortion of scanlines, and end of screen alpha.
|
||||
vec2 Warp(vec2 pos)
|
||||
{
|
||||
pos = 2.0*pos - 1.0;
|
||||
pos *= vec2(1.0 + (pos.y*pos.y) * warpX,
|
||||
1.0 + (pos.x*pos.x) * warpY);
|
||||
pos = pos*2.0-1.0;
|
||||
pos *= vec2(1.0 + (pos.y*pos.y)*warpX, 1.0 + (pos.x*pos.x)*warpY);
|
||||
|
||||
return pos*0.5 + 0.5;
|
||||
}
|
||||
|
||||
vec3 scanline(float y, vec3 frame)
|
||||
{
|
||||
vec3 scanline = frame*( 1.0 + SCANLINE*sin(y*omega));
|
||||
|
||||
return scanline;
|
||||
}
|
||||
|
||||
float corner(vec2 coord)
|
||||
{
|
||||
|
||||
coord *= scale.xy;
|
||||
coord = (coord - vec2(0.5)) * 1.0 + vec2(0.5);
|
||||
coord = min(coord, vec2(1.0)-coord) * pix;
|
||||
coord = min(coord, vec2(1.0)-coord) * vec2(1.0, OriginalSize.y/OriginalSize.x);
|
||||
vec2 cdist = vec2(corner_round);
|
||||
coord = (cdist - min(coord,cdist));
|
||||
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
|
||||
vec3 Mask(float pos)
|
||||
// cgwg mask.
|
||||
vec4 Mask(vec2 pos)
|
||||
{
|
||||
vec3 mask = vec3(1.0);
|
||||
|
||||
float mf = fract(pos*0.5);
|
||||
if (mf <0.5) mask.g = cgwg;
|
||||
else { mask.r = cgwg; mask.b = cgwg; };
|
||||
float m = fract(pos.x*0.5);
|
||||
if (m<0.5) return vec4(cgwg,cgwg,cgwg,1.0);
|
||||
else return vec4(mask,1.0);
|
||||
|
||||
return mask;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
float randomPass(vec2 coords)
|
||||
{
|
||||
return fract(smoothstep(-120.0, 0.0, coords.y - (SourceSize.y + 120.0) * fract(iTimer * 0.00015)));
|
||||
}
|
||||
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 pos;
|
||||
if (SPEEDUP == 0.0 )
|
||||
pos = Warp(vTexCoord.xy);
|
||||
else pos = vTexCoord;
|
||||
|
||||
//borrowed from CRT-Pi
|
||||
vec2 OGL2Pos = pos * params.SourceSize.xy;
|
||||
vec2 pos = Warp(vTexCoord.xy*(scale.xy))*scale.zw;
|
||||
vec2 OGL2Pos = pos * SourceSize.xy;
|
||||
vec2 pC4 = floor(OGL2Pos) + 0.5;
|
||||
vec2 coord = pC4 / params.SourceSize.xy;
|
||||
vec2 deltas = OGL2Pos - pC4;
|
||||
vec2 signs = sign(deltas);
|
||||
deltas.x *= 2.0;
|
||||
deltas = deltas * deltas;
|
||||
deltas.y = deltas.y * deltas.y;
|
||||
deltas.x *= SHARPNESS;
|
||||
deltas.y *= 8.0;
|
||||
deltas /= params.SourceSize.xy;
|
||||
deltas *= signs;
|
||||
vec2 tc = coord + deltas;
|
||||
vec2 coord = pC4 / SourceSize.xy;
|
||||
|
||||
vec3 res = texture(Source, tc).rgb;
|
||||
vec2 tc = vec2(pos.x, coord.y);
|
||||
|
||||
// mask effects look bad unless applied in linear gamma space
|
||||
vec4 res = texture(Source, tc);
|
||||
float l = max(max(res.r,res.g),res.b);
|
||||
res = scanline(pos,res,l);
|
||||
res = scanline(1.0-pos,res,l);
|
||||
res = scanline(1.0+pos,res,l);
|
||||
res = pow(res,in_gamma);
|
||||
|
||||
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);
|
||||
// apply the mask; looks bad with vert scanlines so make them mutually exclusive
|
||||
res *= Mask(vTexCoord *OutputSize.xy * 1.0001);
|
||||
|
||||
if (boost != 1.0) res *= mix(1.0,boost,lum);
|
||||
#if defined GL_ES
|
||||
// hacky clamp fix for GLES
|
||||
vec2 bordertest = (tc);
|
||||
if ( bordertest.x > 0.0001 && bordertest.x < 0.9999 && bordertest.y > 0.0001 && bordertest.y < 0.9999)
|
||||
res = res;
|
||||
else
|
||||
res = vec4(0.,0.,0.,0.);
|
||||
#endif
|
||||
vec4 color = res;
|
||||
|
||||
// apply the mask;
|
||||
res *= Mask(vTexCoord.x * params.OutputSize.x * 1.0001);
|
||||
|
||||
// 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);
|
||||
color.rgb *= vec3(1.0+WP,1.0,1.0-WP);
|
||||
|
||||
vec3 lumweight=vec3(0.3,0.6,0.1);
|
||||
float gray = dot(color,lumweight);
|
||||
vec3 graycolour = vec3(gray);
|
||||
color = vec3(mix(graycolour,color,sat));
|
||||
|
||||
|
||||
FragColor = vec4(color,1.0) ;
|
||||
// re-apply the gamma curve for the mask path
|
||||
color = pow(color, out_gamma);
|
||||
color += boost*color;
|
||||
color += randomPass(tc * SourceSize.xy) * GLOW_LINE;
|
||||
FragColor = color*corner(tc);
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue