update crt-guest to match latest glsl

This commit is contained in:
hunterk 2019-01-28 10:49:52 -06:00
parent 368bdb8fd9
commit 0513ebd358
7 changed files with 259 additions and 187 deletions

View file

@ -1,4 +1,4 @@
shaders = 8
shaders = 7
shader0 = shaders/guest/afterglow.slang
filter_linear0 = false
@ -14,35 +14,30 @@ alias1 = temp_pass
shader2 = shaders/guest/avg-lum.slang
filter_linear2 = false
scale_type2 = source
scale2 = 0.0625
scale2 = 1.0
mipmap_input2 = true
alias2 = lum_pass
shader3 = ../stock.slang
shader3 = shaders/guest/linearize.slang
filter_linear3 = false
scale_type3 = source
scale3 = 16.0
scale3 = 1.0
float_framebuffer3 = true
alias3 = linearize_pass
shader4 = shaders/guest/linearize.slang
shader4 = shaders/guest/blur_horiz.slang
filter_linear4 = false
scale_type4 = source
scale4 = 1.0
float_framebuffer4 = true
alias4 = linearize_pass
shader5 = shaders/guest/blur_horiz.slang
shader5 = shaders/guest/blur_vert.slang
filter_linear5 = false
scale_type5 = source
scale5 = 1.0
float_framebuffer5 = true
shader6 = shaders/guest/blur_vert.slang
filter_linear6 = false
scale_type6 = source
shader6 = shaders/guest/crt-guest-dr-venom.slang
filter_linear6 = true
scale_type6 = viewport
scale6 = 1.0
float_framebuffer6 = true
shader7 = shaders/guest/crt-guest-dr-venom.slang
filter_linear7 = true
scale_type7 = viewport
scale7 = 1.0

View file

@ -29,12 +29,9 @@ layout(push_constant) uniform Push
vec4 OutputSize;
uint FrameCount;
float grade;
float mixfactor;
} params;
#pragma parameter mixfactor "Motionblur Fadeout" 0.75 0.0 1.0 0.01
#pragma parameter grade "Blooming grade" 0.70 0.10 1.0 0.05
#pragma parameter grade "Raster Bloom Grade" 0.65 0.10 1.0 0.05
layout(std140, set = 0, binding = 0) uniform UBO
{
@ -56,17 +53,25 @@ void main()
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
layout(set = 0, binding = 3) uniform sampler2D PassFeedback3;
void main()
{
float mip_level = max(log2(params.SourceSize.x), log2(params.SourceSize.y));
vec4 current = pow(textureLod(Source, vTexCoord, 8), vec4(2.2));
vec4 fdback = pow(textureLod(PassFeedback3, vTexCoord, 8), vec4(2.2));
vec4 mixed = (1.0 - params.mixfactor) * current + params.mixfactor * fdback;
mixed = pow(mixed, vec4(1.0 / 2.2));
float black_compensation = (params.SourceSize.x*params.SourceSize.y)/(params.SourceSize.x*params.SourceSize.y);
float lum = length(mixed.rgb * black_compensation);
lum = lum * inversesqrt(3.0);
FragColor = vec4(pow(lum, params.grade));
float xtotal = floor(params.SourceSize.x/32.0);
float ytotal = floor(params.SourceSize.y/32.0);
float ltotal = 0.0;
vec2 dx = vec2(params.SourceSize.z, 0.0)*32.0;
vec2 dy = vec2(0.0, params.SourceSize.w)*32.0;
for (float i = 0.0; i <= xtotal; i++)
{
for (float j = 0.0; j <= ytotal; j++)
{
ltotal += length(textureLod(Source, i*dx + j*dy, 5.0).rgb);
}
}
ltotal = inversesqrt(3.0)*ltotal / ((xtotal+1.0)*(ytotal+1.0));
FragColor = vec4(pow(ltotal, params.grade));
}

View file

@ -13,8 +13,8 @@ layout(push_constant) uniform Push
float GLOW_FALLOFF_H;
} params;
#pragma parameter TAPSH "H. Glow Radius" 4.0 1.0 6.0 1.0
#pragma parameter GLOW_FALLOFF_H "GLOW_FALLOFF H" 0.30 0.10 1.0 0.01
#pragma parameter TAPSH "H. Glow Radius" 4.0 1.0 10.0 1.0
#pragma parameter GLOW_FALLOFF_H "Horizontal Glow Grade" 0.30 0.0 1.0 0.01
layout(std140, set = 0, binding = 0) uniform UBO
{

View file

@ -13,8 +13,8 @@ layout(push_constant) uniform Push
float GLOW_FALLOFF_V;
} params;
#pragma parameter TAPSV "V. Glow Radius" 4.0 1.0 6.0 1.0
#pragma parameter GLOW_FALLOFF_V "GLOW_FALLOFF_V" 0.30 0.10 1.0 0.01
#pragma parameter TAPSV "V. Glow Radius" 4.0 1.0 10.0 1.0
#pragma parameter GLOW_FALLOFF_V "Vertical Glow Grade" 0.30 0.0 1.0 0.01
layout(std140, set = 0, binding = 0) uniform UBO
{

View file

@ -3,7 +3,9 @@
/*
CRT - Guest - Dr. Venom
Copyright (C) 2018 guest(r) - guest.r@gmail.com
Copyright (C) 2018-2019 guest(r) - guest.r@gmail.com
Incorporates many good ideas and suggestions from Dr. Venom.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@ -25,61 +27,74 @@ layout(push_constant) uniform Push
{
vec4 SourceSize;
vec4 OutputSize;
float OS;
float BLOOM;
float brightboost;
float saturation;
float scanline;
float beam_min;
float beam_max;
float h_sharp;
float l_sharp;
float gamma_out;
float warpX;
float warpY;
float glow;
float shadowMask;
float maskDark;
float maskLight;
float CGWG;
float GTW;
float TATE; // Screen orientation
float IOS; // Smart Integer Scaling
float OS; // Do overscan
float BLOOM; // Bloom overscan percentage
float brightboost; // adjust brightness
float saturation; // 1.0 is normal saturation
float gsl; // Alternate scanlines
float scanline; // scanline param, vertical sharpness
float beam_min; // dark area beam min - wide
float beam_max; // bright area beam max - narrow
float h_sharp; // pixel sharpness
float s_sharp; // substractive sharpness
float csize; // corner size
float warpX; // Curvature X
float warpY; // Curvature Y
float glow; // Glow Strength
float shadowMask; // Mask Style
float maskDark; // Dark "Phosphor"
float maskLight; // Light "Phosphor"
float CGWG; // CGWG Mask Strength
float GTW; // Gamma tweak
float gamma_out; // output gamma
} params;
#pragma parameter OS "Do Overscan" 1.0 0.0 2.0 1.0
#pragma parameter TATE "TATE Mode" 0.0 0.0 1.0 1.0
#define TATE params.TATE
#pragma parameter IOS "Smart Integer Scaling" 0.0 0.0 1.0 1.0
#define IOS params.IOS
#pragma parameter OS "R. Bloom Overscan Mode" 2.0 0.0 2.0 1.0
#define OS params.OS
#pragma parameter BLOOM "Bloom percentage" 5.0 0.0 20.0 1.0
#pragma parameter BLOOM "Raster bloom %" 0.0 0.0 20.0 1.0
#define BLOOM params.BLOOM
#pragma parameter brightboost "Bright boost" 1.10 0.50 2.00 0.01
#define brightboost params.brightboost
#pragma parameter saturation "Saturation adjustment" 1.0 0.1 2.0 0.05
#define saturation params.saturation
#pragma parameter gsl "Alternate scanlines" 0.0 0.0 1.0 1.0
#define gsl params.gsl
#pragma parameter scanline "Scanline adjust" 8.0 1.0 12.0 1.0
#define scanline params.scanline
#pragma parameter beam_min "Scanline dark" 1.40 0.5 2.0 0.05
#pragma parameter beam_min "Scanline dark" 1.30 0.5 2.0 0.05
#define beam_min params.beam_min
#pragma parameter beam_max "Scanline bright" 0.80 0.5 2.0 0.05
#pragma parameter beam_max "Scanline bright" 1.0 0.5 2.0 0.05
#define beam_max params.beam_max
#pragma parameter h_sharp "Horizontal sharpness" 5.0 1.5 20.0 0.25
#define h_sharp params.h_sharp
#pragma parameter l_sharp "Substractive sharpness" 0.0 0.0 0.30 0.01
#define l_sharp params.l_sharp
#pragma parameter gamma_out "Gamma out" 2.4 1.0 3.0 0.05
#define gamma_out params.gamma_out
#pragma parameter warpX "warpX" 0.031 0.0 0.125 0.01
#pragma parameter s_sharp "Substractive sharpness" 0.0 0.0 0.20 0.01
#define s_sharp params.s_sharp
#pragma parameter csize "Corner size" 0.0 0.0 0.05 0.01
#define csize params.csize
#pragma parameter warpX "CurvatureX (default 0.03)" 0.0 0.0 0.125 0.01
#define warpX params.warpX
#pragma parameter warpY "warpY" 0.041 0.0 0.125 0.01
#pragma parameter warpY "CurvatureY (default 0.04)" 0.0 0.0 0.125 0.01
#define warpY params.warpY
#pragma parameter glow "Glow Strength" 0.06 0.0 0.5 0.01
#pragma parameter glow "Glow Strength" 0.04 0.0 0.5 0.01
#define glow params.glow
#pragma parameter shadowMask "Mask Style (0 = CGWG)" 0.0 0.0 4.0 1.0
#pragma parameter shadowMask "Mask Style (0 = CGWG)" 0.0 -1.0 5.0 1.0
#define shadowMask params.shadowMask
#pragma parameter maskDark "Lottes maskDark" 0.5 0.0 2.0 0.1
#define maskDark params.maskDark
#pragma parameter maskLight "Lottes maskLight" 1.5 0.0 2.0 0.1
#define maskLight params.maskLight
#pragma parameter CGWG "CGWG Mask Str." 0.4 0.0 1.0 0.1
#pragma parameter CGWG "CGWG Mask Str." 0.4 0.0 1.0 0.05
#define CGWG params.CGWG
#pragma parameter GTW "Gamma Tweak" 1.10 0.5 1.5 0.01
#define GTW params.GTW
#pragma parameter gamma_out "Gamma out" 2.4 1.0 3.0 0.05
#define gamma_out params.gamma_out
layout(std140, set = 0, binding = 0) uniform UBO
{
@ -106,6 +121,10 @@ layout(set = 0, binding = 4) uniform sampler2D linearize_pass;
#define eps 1e-10
float b_min = 1.0 + 7.0*(beam_min - 0.5)*0.666666666;
float b_max = 1.0 + 7.0*(beam_max - 0.5)*0.666666666;
float scn_s = 0.3 + 0.7*(scanline - 1.0)*0.090909090;
vec3 sw(float x, vec3 color)
{
vec3 tmp = mix(vec3(beam_min),vec3(beam_max), color);
@ -113,23 +132,43 @@ vec3 sw(float x, vec3 color)
return exp2(-scanline*ex*ex);
}
vec3 sw2(float x, vec3 c)
{
vec3 s = mix(vec3(b_min), vec3(b_max), c);
return clamp(smoothstep(vec3(0.0), vec3(scn_s), pow(vec3(x),s)), 0.0001, 1.0);
}
// Shadow mask (mostly from PD Lottes shader).
vec3 Mask(vec2 pos)
{
vec3 mask = vec3(maskDark, maskDark, maskDark);
// Phosphor.
if (params.shadowMask == 0.0)
{
float mf = floor(mod(pos.x,2.0));
float mf2 = floor(mod(pos.x + pos.y,2.0));
float mc = 1.0 - CGWG;
if (mf == 0.0) { mask.r = 1.0; mask.g = mc; mask.b = 1.0; }
else { mask.r = mc; mask.g = 1.0; mask.b = mc; };
float mc2 = mc * 0.7;
// No mask
if (shadowMask == -1.0)
{
mask = vec3(1.0);
}
// Light mask.
else if (shadowMask == 5.0)
{
if (mf2 == 0.0) { mask = vec3(1.0); }
else { mask = vec3(mc2); }
}
// Phosphor.
else if (shadowMask == 0.0)
{
if (mf == 0.0) { mask.r = 1.0; mask.g = mc; mask.b = 1.0; }
else { mask.r = mc; mask.g = 1.0; mask.b = mc; }
}
// Very compressed TV style shadow mask.
else if (params.shadowMask == 1.0)
else if (shadowMask == 1.0)
{
float line = maskLight;
float odd = 0.0;
@ -148,7 +187,7 @@ vec3 Mask(vec2 pos)
}
// Aperture-grille.
else if (params.shadowMask == 2.0)
else if (shadowMask == 2.0)
{
pos.x = fract(pos.x/3.0);
@ -158,7 +197,7 @@ vec3 Mask(vec2 pos)
}
// Stretched VGA style shadow mask (same as prior shaders).
else if (params.shadowMask == 3.0)
else if (shadowMask == 3.0)
{
pos.x += pos.y*3.0;
pos.x = fract(pos.x/6.0);
@ -169,7 +208,7 @@ vec3 Mask(vec2 pos)
}
// VGA style shadow mask.
else if (params.shadowMask == 4.0)
else if (shadowMask == 4.0)
{
pos.xy = floor(pos.xy*vec2(1.0, 0.5));
pos.x += pos.y*3.0;
@ -197,40 +236,57 @@ vec2 Overscan(vec2 pos, float dx, float dy){
return pos*0.5+0.5;
}
float Overscan2(float pos, float dy){
pos=pos*2.0-1.0;
pos*=dy;
return pos*0.5+0.5;
}
// Borrowed from cgwg's crt-geom, under GPL
float corner(vec2 coord)
{
coord *= params.SourceSize.xy / params.SourceSize.xy;
coord = (coord - vec2(0.5)) * 1.0 + vec2(0.5);
coord = min(coord, vec2(1.0)-coord) * vec2(1.0, params.SourceSize.y/params.SourceSize.x);
vec2 cdist = vec2(0.003);
coord = min(coord, vec2(1.0)-coord) * vec2(1.0, params.OutputSize.y*params.OutputSize.z);
vec2 cdist = vec2(max(csize,0.002));
coord = (cdist - min(coord,cdist));
float dist = sqrt(dot(coord,coord));
return clamp((cdist.x-dist)*600.0,0.0, 1.0);
return clamp((cdist.x-dist)*700.0,0.0, 1.0);
}
const float sqrt3 = 1.732050807568877;
vec3 gamma_correct(vec3 color, vec3 tmp)
{
float l = length(color)/sqrt3;
float g = mix(1.0/GTW, 1.0, max(max(tmp.r,tmp.g),tmp.b));
l = pow(l,g)*sqrt3;
return l*normalize(color + vec3(eps));
return color*mix(GTW, 1.0, max(max(tmp.r,tmp.g),tmp.b));
}
void main()
{
vec3 lum = texture(lum_pass, vec2(0.1,0.1)).xyz;
vec3 lum = texture(lum_pass, vec2(0.33,0.33)).xyz;
// Calculating texel coordinates
vec2 texcoord = vTexCoord.xy;
if (IOS == 1.0){
vec2 ofactor = params.OutputSize.xy*params.SourceSize.zw;
vec2 intfactor = round(ofactor);
vec2 diff = ofactor/intfactor;
vec2 smartcoord;
smartcoord.x = Overscan2(vTexCoord.x, diff.x);
smartcoord.y = Overscan2(vTexCoord.y, diff.y);
texcoord = (TATE > 0.5) ? vec2(smartcoord.x, texcoord.y) :
vec2(texcoord.x, smartcoord.y);
}
float factor = 1.00 + (1.0-0.5*OS)*BLOOM/100.0 - lum.x*BLOOM/100.0;
vec2 texcoord = Overscan(vTexCoord.xy*(params.SourceSize.xy/params.SourceSize.xy), factor, factor)*(params.SourceSize.xy/params.SourceSize.xy);
texcoord = Overscan(texcoord, factor, factor);
vec2 pos = Warp(texcoord);
vec2 pos0 = Warp(texcoord);
vec2 pos0 = Warp(vTexCoord.xy);
vec2 ps = params.SourceSize.zw;
vec2 OGL2Pos = pos * params.SourceSize.xy - vec2(0.0,0.5);
vec2 OGL2Pos = pos * params.SourceSize.xy - ((TATE < 0.5) ?
vec2(0.0,0.5) : vec2(0.5, 0.0));
vec2 fp = fract(OGL2Pos);
vec2 dx = vec2(ps.x,0.0);
vec2 dy = vec2(0.0, ps.y);
@ -239,42 +295,57 @@ void main()
// Reading the texels
vec2 x2 = 2.0*dx;
vec2 y2 = 2.0*dy;
float wl = exp2(-h_sharp*0.36)*l_sharp;
vec2 offx = dx;
vec2 off2 = x2;
vec2 offy = dy;
float fpx = fp.x;
if(TATE > 0.5)
{
offx = dy;
off2 = y2;
offy = dx;
fpx = fp.y;
}
float wl2 = 1.5 + fp.x; wl2*=wl2; wl2 = exp2(-h_sharp*wl2); wl2 = max(wl2 - wl, -wl2);
float wl1 = 0.5 + fp.x; wl1*=wl1; wl1 = exp2(-h_sharp*wl1); wl1 = max(wl1 - wl, -0.25);
float wct = 0.5 - fp.x; wct*=wct; wct = exp2(-h_sharp*wct);
float wr1 = 1.5 - fp.x; wr1*=wr1; wr1 = exp2(-h_sharp*wr1); wr1 = max(wr1 - wl, -0.25);
float wr2 = 2.5 - fp.x; wr2*=wr2; wr2 = exp2(-h_sharp*wr2); wr2 = max(wr2 - wl, -wr2);
bool sharp = (s_sharp > 0.0);
float wl2 = 1.5 + fpx; wl2*=wl2; wl2 = exp2(-h_sharp*wl2); wl2 = max(wl2 - s_sharp, -wl2);
float wl1 = 0.5 + fpx; wl1*=wl1; wl1 = exp2(-h_sharp*wl1); wl1 = max(wl1 - s_sharp, -0.4*s_sharp);
float wct = 0.5 - fpx; wct*=wct; wct = exp2(-h_sharp*wct); wct = max(wct - s_sharp, s_sharp);
float wr1 = 1.5 - fpx; wr1*=wr1; wr1 = exp2(-h_sharp*wr1); wr1 = max(wr1 - s_sharp, -0.4*s_sharp);
float wr2 = 2.5 - fpx; wr2*=wr2; wr2 = exp2(-h_sharp*wr2); wr2 = max(wr2 - s_sharp, -wr2);
float wt = 1.0/(wl2+wl1+wct+wr1+wr2);
vec3 l2 = texture(linearize_pass, pC4 -x2).xyz;
vec3 l1 = texture(linearize_pass, pC4 -dx).xyz;
vec3 l2 = texture(linearize_pass, pC4 -off2).xyz;
vec3 l1 = texture(linearize_pass, pC4 -offx).xyz;
vec3 ct = texture(linearize_pass, pC4 ).xyz;
vec3 r1 = texture(linearize_pass, pC4 +dx).xyz;
vec3 r2 = texture(linearize_pass, pC4 +x2).xyz;
vec3 r1 = texture(linearize_pass, pC4 +offx).xyz;
vec3 r2 = texture(linearize_pass, pC4 +off2).xyz;
vec3 color1 = (l2*wl2 + l1*wl1 + ct*wct + r1*wr1 + r2*wr2)*wt;
if (l_sharp > 0.0) color1 = clamp(color1, 0.8*min(min(l1,r1),ct), 1.2*max(max(l1,r1),ct));
if (sharp) color1 = clamp(color1, min(min(l1,r1),ct), max(max(l1,r1),ct));
l2 = texture(linearize_pass, pC4 -x2 +dy).xyz;
l1 = texture(linearize_pass, pC4 -dx +dy).xyz;
ct = texture(linearize_pass, pC4 +dy).xyz;
r1 = texture(linearize_pass, pC4 +dx +dy).xyz;
r2 = texture(linearize_pass, pC4 +x2 +dy).xyz;
l2 = texture(linearize_pass, pC4 -off2 +offy).xyz;
l1 = texture(linearize_pass, pC4 -offx +offy).xyz;
ct = texture(linearize_pass, pC4 +offy).xyz;
r1 = texture(linearize_pass, pC4 +offx +offy).xyz;
r2 = texture(linearize_pass, pC4 +off2 +offy).xyz;
vec3 color2 = (l2*wl2 + l1*wl1 + ct*wct + r1*wr1 + r2*wr2)*wt;
if (l_sharp > 0.0) color2 = clamp(color2, 0.8*min(min(l1,r1),ct), 1.2*max(max(l1,r1),ct));
if (sharp) color2 = clamp(color2, min(min(l1,r1),ct), max(max(l1,r1),ct));
// calculating scanlines
// calculating scanlines
float f = fp.y;
float f = (TATE < 0.5) ? fp.y : fp.x;
vec3 w1 = sw(f,color1);
vec3 w2 = sw(1.0-f,color2);
if (gsl == 1.0) { w1 = sw2(1.0-f,color1); w2 = sw2(f,color2);}
vec3 color = color1*w1 + color2*w2;
vec3 ctmp = color/(w1+w2);
@ -286,9 +357,10 @@ void main()
color = pow(color, vec3(gamma_out));
color = min(color, 1.0);
// Apply Mask
// Apply Mask
color = color*Mask(vTexCoord * params.OutputSize.xy);
color *= (TATE < 0.5) ? Mask(gl_FragCoord.xy * 1.000001) :
Mask(gl_FragCoord.yx * 1.000001);
vec3 Bloom = texture(Source, pos).xyz;

View file

@ -9,7 +9,7 @@ layout(push_constant) uniform Push
float WP;
} params;
#pragma parameter WP "D65 to D50 strength %" 0.0 -100.0 100.0 10.0
#pragma parameter WP "D65 to D50 strength %" 0.0 -100.0 100.0 5.0
layout(std140, set = 0, binding = 0) uniform UBO
{

View file

@ -9,7 +9,7 @@ layout(push_constant) uniform Push
float GAMMA_INPUT;
} params;
#pragma parameter GAMMA_INPUT "Gamma Input" 2.4 0.1 5.0 0.01
#pragma parameter GAMMA_INPUT "Gamma Input" 2.4 0.1 5.0 0.05
layout(std140, set = 0, binding = 0) uniform UBO
{