diff --git a/crt/crt-guest-dr-venom.slangp b/crt/crt-guest-dr-venom.slangp new file mode 100644 index 0000000..ad54cfe --- /dev/null +++ b/crt/crt-guest-dr-venom.slangp @@ -0,0 +1,48 @@ +shaders = 8 + +shader0 = shaders/guest/afterglow.slang +filter_linear0 = false +scale_type0 = source +scale0 = 1.0 + +shader1 = shaders/guest/d65-d50.slang +filter_linear1 = false +scale_type1 = source +scale1 = 1.0 +alias1 = temp_pass + +shader2 = shaders/guest/avg-lum.slang +filter_linear2 = false +scale_type2 = source +scale2 = 0.0625 +mipmap_input2 = true +alias2 = lum_pass + +shader3 = ../stock.slang +filter_linear3 = false +scale_type3 = source +scale3 = 16.0 + +shader4 = shaders/guest/linearize.slang +filter_linear4 = false +scale_type4 = source +scale4 = 1.0 +float_framebuffer4 = true +alias4 = linearize_pass + +shader5 = shaders/guest/blur_horiz.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 +scale6 = 1.0 +float_framebuffer6 = true + +shader7 = shaders/guest/crt-guest-dr-venom.slang +filter_linear7 = true +scale_type7 = viewport +scale7 = 1.0 diff --git a/crt/shaders/guest/afterglow.slang b/crt/shaders/guest/afterglow.slang new file mode 100644 index 0000000..03dc4a3 --- /dev/null +++ b/crt/shaders/guest/afterglow.slang @@ -0,0 +1,104 @@ +#version 450 + +/* + Phosphor Afterglow Shader + + Copyright (C) 2018 guest(r) - guest.r@gmail.com + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +layout(push_constant) uniform Push +{ + vec4 SourceSize; + vec4 OriginalSize; + vec4 OutputSize; + uint FrameCount; + float SW; + float AR; + float PR; + float AG; + float PG; + float AB; + float PB; + float sat; + float GTH; +} params; + +#pragma parameter SW "Afterglow switch ON/OFF" 1.0 0.0 1.0 1.0 +#pragma parameter AR "Afterglow Red (more is more)" 0.07 0.0 1.0 0.01 +#pragma parameter PR "Persistence Red (more is less)" 0.05 0.0 1.0 0.01 +#pragma parameter AG "Afterglow Green" 0.07 0.0 1.0 0.01 +#pragma parameter PG "Persistence Green" 0.05 0.0 1.0 0.01 +#pragma parameter AB "Afterglow Blue" 0.07 0.0 1.0 0.01 +#pragma parameter PB "Persistence Blue" 0.05 0.0 1.0 0.01 +#pragma parameter sat "Afterglow saturation" 0.10 0.0 1.0 0.01 +#pragma parameter GTH "Afterglow threshold" 5.0 0.0 255.0 1.0 + +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; + +void main() +{ + gl_Position = global.MVP * Position; + vTexCoord = TexCoord; +} + +#pragma stage fragment +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 OriginalHistory1; +layout(set = 0, binding = 4) uniform sampler2D OriginalHistory2; +layout(set = 0, binding = 5) uniform sampler2D OriginalHistory3; +layout(set = 0, binding = 6) uniform sampler2D OriginalHistory4; +layout(set = 0, binding = 7) uniform sampler2D OriginalHistory5; +layout(set = 0, binding = 8) uniform sampler2D OriginalHistory6; + +#define eps 1e-4 + +vec3 afterglow(float number) +{ + return vec3(params.AR, params.AG, params.AB)*exp2(-vec3(params.PR, params.PG, params.PB)*vec3(number*number)); +} + +void main() +{ + vec3 color = texture(Source, vTexCoord.xy).rgb; + vec3 color1 = texture(OriginalHistory1, vTexCoord.xy).rgb * afterglow(1.0); + vec3 color2 = texture(OriginalHistory2, vTexCoord.xy).rgb * afterglow(2.0); + vec3 color3 = texture(OriginalHistory3, vTexCoord.xy).rgb * afterglow(3.0); + vec3 color4 = texture(OriginalHistory4, vTexCoord.xy).rgb * afterglow(4.0); + vec3 color5 = texture(OriginalHistory5, vTexCoord.xy).rgb * afterglow(5.0); + vec3 color6 = texture(OriginalHistory6, vTexCoord.xy).rgb * afterglow(6.0); + + vec3 glow = color1 + color2 + color3 + color4 + color5 + color6; + + float l = length(glow); + glow = normalize(pow(glow + vec3(eps), vec3(params.sat)))*l; + + float w = 1.0; + if ((color.r + color.g + color.b) > params.GTH/255.0) w = 0.0; + + FragColor = vec4(color + params.SW*w*glow,1.0); +} \ No newline at end of file diff --git a/crt/shaders/guest/avg-lum.slang b/crt/shaders/guest/avg-lum.slang new file mode 100644 index 0000000..ce3214a --- /dev/null +++ b/crt/shaders/guest/avg-lum.slang @@ -0,0 +1,64 @@ +#version 450 + +/* + Average Luminance Shader + + Copyright (C) 2018 guest(r) - guest.r@gmail.com + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + + Thanks to HunterK for the mipmap hint. :D +*/ + +layout(push_constant) uniform Push +{ + vec4 SourceSize; + vec4 OriginalSize; + vec4 OutputSize; + uint FrameCount; + float grade; +} params; + +#pragma parameter grade "Blooming grade" 0.70 0.10 1.0 0.05 + +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; + +void main() +{ + gl_Position = global.MVP * Position; + vTexCoord = TexCoord; +} + +#pragma stage fragment +layout(location = 0) in vec2 vTexCoord; +layout(location = 0) out vec4 FragColor; +layout(set = 0, binding = 2) uniform sampler2D Source; + +void main() +{ + float mip_level = max(log2(params.SourceSize.x), log2(params.SourceSize.y)); + float black_compensation = (params.SourceSize.x*params.SourceSize.y)/(params.SourceSize.x*params.SourceSize.y); + float lum = length(textureLod(Source, vTexCoord.xy, mip_level).rgb * black_compensation); + lum = lum * inversesqrt(3.0); + FragColor = vec4(pow(lum, params.grade)); +} \ No newline at end of file diff --git a/crt/shaders/guest/blur_horiz.slang b/crt/shaders/guest/blur_horiz.slang new file mode 100644 index 0000000..8027d29 --- /dev/null +++ b/crt/shaders/guest/blur_horiz.slang @@ -0,0 +1,55 @@ +#version 450 + +// Higher value, more centered glow. +// Lower values might need more taps. + +layout(push_constant) uniform Push +{ + vec4 SourceSize; + vec4 OriginalSize; + vec4 OutputSize; + uint FrameCount; + float TAPSH; + 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 + +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; + +void main() +{ + gl_Position = global.MVP * Position; + vTexCoord = TexCoord; +} + +#pragma stage fragment +layout(location = 0) in vec2 vTexCoord; +layout(location = 0) out vec4 FragColor; +layout(set = 0, binding = 2) uniform sampler2D Source; + +#define kernel(x) exp(-params.GLOW_FALLOFF_H * (x) * (x)) + +void main() +{ + vec3 col = vec3(0.0); + float dx = params.SourceSize.z; + + float k_total = 0.; + for (float i = -params.TAPSH; i <= params.TAPSH; i++) + { + float k = kernel(i); + k_total += k; + col += k * texture(Source, vTexCoord + vec2(float(i) * dx, 0.0)).rgb; + } + FragColor = vec4(col / k_total, 1.0); +} \ No newline at end of file diff --git a/crt/shaders/guest/blur_vert.slang b/crt/shaders/guest/blur_vert.slang new file mode 100644 index 0000000..4603a31 --- /dev/null +++ b/crt/shaders/guest/blur_vert.slang @@ -0,0 +1,55 @@ +#version 450 + +// Higher value, more centered glow. +// Lower values might need more taps. + +layout(push_constant) uniform Push +{ + vec4 SourceSize; + vec4 OriginalSize; + vec4 OutputSize; + uint FrameCount; + float TAPSV; + 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 + +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; + +void main() +{ + gl_Position = global.MVP * Position; + vTexCoord = TexCoord; +} + +#pragma stage fragment +layout(location = 0) in vec2 vTexCoord; +layout(location = 0) out vec4 FragColor; +layout(set = 0, binding = 2) uniform sampler2D Source; + +#define kernel(x) exp(-params.GLOW_FALLOFF_V * (x) * (x)) + +void main() +{ + vec3 col = vec3(0.0); + float dy = params.SourceSize.w; + + float k_total = 0.; + for (float i = -params.TAPSV; i <= params.TAPSV; i++) + { + float k = kernel(i); + k_total += k; + col += k * texture(Source, vTexCoord + vec2(0.0, float(i) * dy)).rgb; + } + FragColor = vec4(col / k_total, 1.0); +} \ No newline at end of file diff --git a/crt/shaders/guest/crt-guest-dr-venom.slang b/crt/shaders/guest/crt-guest-dr-venom.slang new file mode 100644 index 0000000..d68aa81 --- /dev/null +++ b/crt/shaders/guest/crt-guest-dr-venom.slang @@ -0,0 +1,300 @@ +#version 450 + +/* + CRT - Guest - Dr. Venom + + Copyright (C) 2018 guest(r) - guest.r@gmail.com + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +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; +} params; + +#pragma parameter OS "Do Overscan" 1.0 0.0 2.0 1.0 +#define OS params.OS +#pragma parameter BLOOM "Bloom percentage" 5.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 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 +#define beam_min params.beam_min +#pragma parameter beam_max "Scanline bright" 0.80 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 +#define warpX params.warpX +#pragma parameter warpY "warpY" 0.041 0.0 0.125 0.01 +#define warpY params.warpY +#pragma parameter glow "Glow Strength" 0.06 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 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 +#define CGWG params.CGWG +#pragma parameter GTW "Gamma Tweak" 1.10 0.5 1.5 0.01 +#define GTW params.GTW + +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; + +void main() +{ + gl_Position = global.MVP * Position; + vTexCoord = TexCoord * 1.0001; +} + +#pragma stage fragment +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 lum_pass; +layout(set = 0, binding = 4) uniform sampler2D linearize_pass; + +#define eps 1e-10 + +vec3 sw(float x, vec3 color) +{ + vec3 tmp = mix(vec3(beam_min),vec3(beam_max), color); + vec3 ex = vec3(x)*tmp; + return exp2(-scanline*ex*ex); +} + +// 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 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; }; + } + + + // Very compressed TV style shadow mask. + else if (params.shadowMask == 1.0) + { + float line = maskLight; + float odd = 0.0; + + if (fract(pos.x/6.0) < 0.5) + odd = 1.0; + if (fract((pos.y + odd)/2.0) < 0.5) + line = maskDark; + + pos.x = fract(pos.x/3.0); + + if (pos.x < 0.333) mask.r = maskLight; + else if (pos.x < 0.666) mask.g = maskLight; + else mask.b = maskLight; + mask*=line; + } + + // Aperture-grille. + else if (params.shadowMask == 2.0) + { + pos.x = fract(pos.x/3.0); + + if (pos.x < 0.333) mask.r = maskLight; + else if (pos.x < 0.666) mask.g = maskLight; + else mask.b = maskLight; + } + + // Stretched VGA style shadow mask (same as prior shaders). + else if (params.shadowMask == 3.0) + { + pos.x += pos.y*3.0; + pos.x = fract(pos.x/6.0); + + if (pos.x < 0.333) mask.r = maskLight; + else if (pos.x < 0.666) mask.g = maskLight; + else mask.b = maskLight; + } + + // VGA style shadow mask. + else if (params.shadowMask == 4.0) + { + pos.xy = floor(pos.xy*vec2(1.0, 0.5)); + pos.x += pos.y*3.0; + pos.x = fract(pos.x/6.0); + + if (pos.x < 0.333) mask.r = maskLight; + else if (pos.x < 0.666) mask.g = maskLight; + else mask.b = maskLight; + } + + return mask; +} + +// Distortion of scanlines, and end of screen alpha (PD Lottes Curvature) +vec2 Warp(vec2 pos) +{ + 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; +} + +vec2 Overscan(vec2 pos, float dx, float dy){ + pos=pos*2.0-1.0; + pos*=vec2(dx,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 = (cdist - min(coord,cdist)); + float dist = sqrt(dot(coord,coord)); + return clamp((cdist.x-dist)*600.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)); +} + +void main() +{ + vec3 lum = texture(lum_pass, vec2(0.1,0.1)).xyz; + + 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); + vec2 pos = Warp(texcoord); + vec2 pos0 = Warp(texcoord); + + vec2 ps = params.SourceSize.zw; + vec2 OGL2Pos = pos * params.SourceSize.xy - vec2(0.0,0.5); + vec2 fp = fract(OGL2Pos); + vec2 dx = vec2(ps.x,0.0); + vec2 dy = vec2(0.0, ps.y); + + vec2 pC4 = floor(OGL2Pos) * ps + 0.5*ps; + + // Reading the texels + vec2 x2 = 2.0*dx; + + float wl = exp2(-h_sharp*0.36)*l_sharp; + + 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); + + 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 ct = texture(linearize_pass, pC4 ).xyz; + vec3 r1 = texture(linearize_pass, pC4 +dx).xyz; + vec3 r2 = texture(linearize_pass, pC4 +x2).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)); + + 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; + + 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)); + +// calculating scanlines + + float f = fp.y; + + vec3 w1 = sw(f,color1); + vec3 w2 = sw(1.0-f,color2); + + vec3 color = color1*w1 + color2*w2; + vec3 ctmp = color/(w1+w2); + + color = pow(color, vec3(1.0/gamma_out)); + float l = length(color); + color = normalize(pow(color + vec3(eps), vec3(saturation,saturation,saturation)))*l; + color*=brightboost; + color = gamma_correct(color,ctmp); + color = pow(color, vec3(gamma_out)); + color = min(color, 1.0); + +// Apply Mask + + color = color*Mask(vTexCoord * params.OutputSize.xy); + + vec3 Bloom = texture(Source, pos).xyz; + + color+=glow*Bloom; + color = min(color, 1.0); + + color = pow(color, vec3(1.0/gamma_out)); + FragColor = vec4(color*corner(pos0), 1.0); +} \ No newline at end of file diff --git a/crt/shaders/guest/d65-d50.slang b/crt/shaders/guest/d65-d50.slang new file mode 100644 index 0000000..398a28a --- /dev/null +++ b/crt/shaders/guest/d65-d50.slang @@ -0,0 +1,57 @@ +#version 450 + +layout(push_constant) uniform Push +{ + vec4 SourceSize; + vec4 OriginalSize; + vec4 OutputSize; + uint FrameCount; + float WP; +} params; + +#pragma parameter WP "D65 to D50 strength %" 0.0 -100.0 100.0 10.0 + +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; + +void main() +{ + gl_Position = global.MVP * Position; + vTexCoord = TexCoord; +} + +#pragma stage fragment +layout(location = 0) in vec2 vTexCoord; +layout(location = 0) out vec4 FragColor; +layout(set = 0, binding = 2) uniform sampler2D Source; + +const mat3 D65 = mat3 ( + 0.5767309, 0.2973769, 0.0270343, + 0.1855540, 0.6273491, 0.0706872, + 0.1881852, 0.0752741, 0.9911085); + +const mat3 D50 = mat3 ( + 1.7552599, -0.5441336, 0.0063467, + -0.4836786, 1.5068789, -0.0175761, + -0.2530000, 0.0215528, 1.2256959); + +void main() +{ + vec3 color = texture(Source, vTexCoord.xy).rgb; + + vec3 c65 = D65*color; + vec3 c50 = D50*c65; + + float m = params.WP/100.0; + + color = (1.0-m)*color + m*c50; + + FragColor = vec4(color,1.0); +} \ No newline at end of file diff --git a/crt/shaders/guest/linearize.slang b/crt/shaders/guest/linearize.slang new file mode 100644 index 0000000..cf65ec3 --- /dev/null +++ b/crt/shaders/guest/linearize.slang @@ -0,0 +1,38 @@ +#version 450 + +layout(push_constant) uniform Push +{ + vec4 SourceSize; + vec4 OriginalSize; + vec4 OutputSize; + uint FrameCount; + float GAMMA_INPUT; +} params; + +#pragma parameter GAMMA_INPUT "Gamma Input" 2.4 0.1 5.0 0.01 + +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; + +void main() +{ + gl_Position = global.MVP * Position; + vTexCoord = TexCoord; +} + +#pragma stage fragment +layout(location = 0) in vec2 vTexCoord; +layout(location = 0) out vec4 FragColor; +layout(set = 0, binding = 2) uniform sampler2D temp_pass; + +void main() +{ + FragColor = pow(vec4(texture(temp_pass, vTexCoord)), vec4(params.GAMMA_INPUT)); +} \ No newline at end of file diff --git a/presets/crt-royale-sony_bvm.slangp b/presets/crt-royale-sony_bvm.slangp new file mode 100644 index 0000000..6e5bf6d --- /dev/null +++ b/presets/crt-royale-sony_bvm.slangp @@ -0,0 +1,256 @@ +# IMPORTANT: +# Shader passes need to know details about the image in the mask_texture LUT +# files, so set the following constants in user-cgp-constants.h accordingly: +# 1.) mask_triads_per_tile = (number of horizontal triads in mask texture LUT's) +# 2.) mask_texture_small_size = (texture size of mask*texture_small LUT's) +# 3.) mask_texture_large_size = (texture size of mask*texture_large LUT's) +# 4.) mask_grille_avg_color = (avg. brightness of mask_grille_texture* LUT's, in [0, 1]) +# 5.) mask_slot_avg_color = (avg. brightness of mask_slot_texture* LUT's, in [0, 1]) +# 6.) mask_shadow_avg_color = (avg. brightness of mask_shadow_texture* LUT's, in [0, 1]) +# Shader passes also need to know certain scales set in this .slangp, but their +# compilation model doesn't currently allow the .slangp file to tell them. Make +# sure to set the following constants in user-cgp-constants.h accordingly too: +# 1.) bloom_approx_scale_x = scale_x2 +# 2.) mask_resize_viewport_scale = float2(scale_x6, scale_y5) +# Finally, shader passes need to know the value of geom_max_aspect_ratio used to +# calculate scale_y6 (among other values): +# 1.) geom_max_aspect_ratio = (geom_max_aspect_ratio used to calculate scale_y5) + +shaders = "13" + +# Set an identifier, filename, and sampling traits for the phosphor mask texture. +# Load an aperture grille, slot mask, and an EDP shadow mask, and load a small +# non-mipmapped version and a large mipmapped version. +# TODO: Test masks in other directories. +textures = "mask_grille_texture_small;mask_grille_texture_large;mask_slot_texture_small;mask_slot_texture_large;mask_shadow_texture_small;mask_shadow_texture_large;SamplerLUT" +mask_grille_texture_small = "../crt/shaders/crt-royale/TileableLinearApertureGrille15Wide8And5d5SpacingResizeTo64.png" +mask_grille_texture_large = "../crt/shaders/crt-royale/TileableLinearApertureGrille15Wide8And5d5Spacing.png" +mask_slot_texture_small = "../crt/shaders/crt-royale/TileableLinearSlotMaskTall15Wide9And4d5Horizontal9d14VerticalSpacingResizeTo64.png" +mask_slot_texture_large = "../crt/shaders/crt-royale/TileableLinearSlotMaskTall15Wide9And4d5Horizontal9d14VerticalSpacing.png" +mask_shadow_texture_small = "../crt/shaders/crt-royale/TileableLinearShadowMaskEDPResizeTo64.png" +mask_shadow_texture_large = "../crt/shaders/crt-royale/TileableLinearShadowMaskEDP.png" +mask_grille_texture_small_wrap_mode = "repeat" +mask_grille_texture_large_wrap_mode = "repeat" +mask_slot_texture_small_wrap_mode = "repeat" +mask_slot_texture_large_wrap_mode = "repeat" +mask_shadow_texture_small_wrap_mode = "repeat" +mask_shadow_texture_large_wrap_mode = "repeat" +mask_grille_texture_small_linear = "true" +mask_grille_texture_large_linear = "true" +mask_slot_texture_small_linear = "true" +mask_slot_texture_large_linear = "true" +mask_shadow_texture_small_linear = "true" +mask_shadow_texture_large_linear = "true" +mask_grille_texture_small_mipmap = "false" # Mipmapping causes artifacts with manually resized masks without tex2Dlod +mask_grille_texture_large_mipmap = "true" # Essential for hardware-resized masks +mask_slot_texture_small_mipmap = "false" # Mipmapping causes artifacts with manually resized masks without tex2Dlod +mask_slot_texture_large_mipmap = "true" # Essential for hardware-resized masks +mask_shadow_texture_small_mipmap = "false" # Mipmapping causes artifacts with manually resized masks without tex2Dlod +mask_shadow_texture_large_mipmap = "true" # Essential for hardware-resized masks +SamplerLUT = "../reshade/shaders/LUT/Sony_Trinitron_Std_50_no_gamma.png" +SamplerLUT_linear = true + +shader0 = "../reshade/shaders/LUT/LUT.slang" + +# Pass0: Linearize the input based on CRT gamma and bob interlaced fields. +# (Bobbing ensures we can immediately blur without getting artifacts.) +shader1 = "../crt/shaders/crt-royale/src/crt-royale-first-pass-linearize-crt-gamma-bob-fields.slang" +alias1 = "ORIG_LINEARIZED" +filter_linear1 = "false" +scale_type1 = "source" +scale1 = "1.0" +srgb_framebuffer1 = "true" + +# Pass1: Resample interlaced (and misconverged) scanlines vertically. +# Separating vertical/horizontal scanline sampling is faster: It lets us +# consider more scanlines while calculating weights for fewer pixels, and +# it reduces our samples from vertical*horizontal to vertical+horizontal. +# This has to come right after ORIG_LINEARIZED, because there's no +# "original_source" scale_type we can use later. +shader2 = "../crt/shaders/crt-royale/src/crt-royale-scanlines-vertical-interlacing.slang" +alias2 = "VERTICAL_SCANLINES" +filter_linear2 = "true" +scale_type_x2 = "source" +scale_x2 = "1.0" +scale_type_y2 = "viewport" +scale_y2 = "1.0" +#float_framebuffer2 = "true" +srgb_framebuffer2 = "true" + +# Pass2: Do a small resize blur of ORIG_LINEARIZED at an absolute size, and +# account for convergence offsets. We want to blur a predictable portion of the +# screen to match the phosphor bloom, and absolute scale works best for +# reliable results with a fixed-size bloom. Picking a scale is tricky: +# a.) 400x300 is a good compromise for the "fake-bloom" version: It's low enough +# to blur high-res/interlaced sources but high enough that resampling +# doesn't smear low-res sources too much. +# b.) 320x240 works well for the "real bloom" version: It's 1-1.5% faster, and +# the only noticeable visual difference is a larger halation spread (which +# may be a good thing for people who like to crank it up). +# Note the 4:4 aspect ratio assumes the input has cropped geom_overscan (so it's +# *intended* for an ~4:4 aspect ratio). +shader3 = "../crt/shaders/crt-royale/src/crt-royale-bloom-approx.slang" +alias3 = "BLOOM_APPROX" +filter_linear3 = "true" +scale_type3 = "absolute" +scale_x3 = "320" +scale_y3 = "240" +srgb_framebuffer3 = "true" + +# Pass3: Vertically blur the input for halation and refractive diffusion. +# Base this on BLOOM_APPROX: This blur should be small and fast, and blurring +# a constant portion of the screen is probably physically correct if the +# viewport resolution is proportional to the simulated CRT size. +shader4 = "../blurs/blur5fast-vertical.slang" +filter_linear4 = "true" +scale_type4 = "source" +scale4 = "1.0" +srgb_framebuffer4 = "true" + +# Pass4: Horizontally blur the input for halation and refractive diffusion. +# Note: Using a one-pass 9x10 blur is about 1% slower. +shader5 = "../blurs/blur5fast-horizontal.slang" +alias5 = "HALATION_BLUR" +filter_linear5 = "true" +scale_type5 = "source" +scale5 = "1.0" +srgb_framebuffer5 = "true" + +# Pass5: Lanczos-resize the phosphor mask vertically. Set the absolute +# scale_x6 == mask_texture_small_size.x (see IMPORTANT above). Larger scales +# will blur, and smaller scales could get nasty. The vertical size must be +# based on the viewport size and calculated carefully to avoid artifacts later. +# First calculate the minimum number of mask tiles we need to draw. +# Since curvature is computed after the scanline masking pass: +# num_resized_mask_tiles = 2.0; +# If curvature were computed in the scanline masking pass (it's not): +# max_mask_texel_border = ~3.0 * (1/3.0 + 4.0*sqrt(2.0) + 0.6 + 1.0); +# max_mask_tile_border = max_mask_texel_border/ +# (min_resized_phosphor_triad_size * mask_triads_per_tile); +# num_resized_mask_tiles = max(2.0, 1.0 + max_mask_tile_border * 2.0); +# At typical values (triad_size >= 2.0, mask_triads_per_tile == 8): +# num_resized_mask_tiles = ~3.8 +# Triad sizes are given in horizontal terms, so we need geom_max_aspect_ratio +# to relate them to vertical resolution. The widest we expect is: +# geom_max_aspect_ratio = 4.0/3.0 # Note: Shader passes need to know this! +# The fewer triads we tile across the screen, the larger each triad will be as a +# fraction of the viewport size, and the larger scale_y6 must be to draw a full +# num_resized_mask_tiles. Therefore, we must decide the smallest number of +# triads we'll guarantee can be displayed on screen. We'll set this according +# to 3-pixel triads at 768p resolution (the lowest anyone's likely to use): +# min_allowed_viewport_triads = 768.0*geom_max_aspect_ratio / 3.0 = 341.333333 +# Now calculate the viewport scale that ensures we can draw resized_mask_tiles: +# min_scale_x = resized_mask_tiles * mask_triads_per_tile / +# min_allowed_viewport_triads +# scale_y6 = geom_max_aspect_ratio * min_scale_x +# # Some code might depend on equal scales: +# scale_x7 = scale_y5 +# Given our default geom_max_aspect_ratio and min_allowed_viewport_triads: +# scale_y6 = 4.0/3.0 * 2.0/(341.33334 / 8.0) = 0.0625 +# IMPORTANT: The scales MUST be calculated in this way. If you wish to change +# geom_max_aspect_ratio, update that constant in user-cgp-constants.h! +shader6 = "../crt/shaders/crt-royale/src/crt-royale-mask-resize-vertical.slang" +filter_linear6 = "true" +scale_type_x6 = "absolute" +scale_x6 = "64" +scale_type_y6 = "viewport" +scale_y6 = "0.0625" # Safe for >= 341.334 horizontal triads at viewport size +#srgb_framebuffer6 = "false" # mask_texture is already assumed linear + +# Pass6: Lanczos-resize the phosphor mask horizontally. scale_x7 = scale_y5. +# TODO: Check again if the shaders actually require equal scales. +shader7 = "../crt/shaders/crt-royale/src/crt-royale-mask-resize-horizontal.slang" +alias7 = "MASK_RESIZE" +filter_linear7 = "false" +scale_type_x7 = "viewport" +scale_x7 = "0.0625" +scale_type_y7 = "source" +scale_y7 = "1.0" +#srgb_framebuffer7 = "false" # mask_texture is already assumed linear + +# Pass7: Resample (misconverged) scanlines horizontally, apply halation, and +# apply the phosphor mask. +shader8 = "../crt/shaders/crt-royale/src/crt-royale-scanlines-horizontal-apply-mask.slang" +alias8 = "MASKED_SCANLINES" +filter_linear8 = "true" # This could just as easily be nearest neighbor. +scale_type8 = "viewport" +scale8 = "1.0" +#float_framebuffer8 = "true" +srgb_framebuffer8 = "true" + +# Pass 8: Compute a brightpass. This will require reading the final mask. +shader9 = "../crt/shaders/crt-royale/src/crt-royale-brightpass.slang" +alias9 = "BRIGHTPASS" +filter_linear9 = "true" # This could just as easily be nearest neighbor. +scale_type9 = "viewport" +scale9 = "1.0" +srgb_framebuffer9 = "true" + +# Pass 9: Blur the brightpass vertically +shader10 = "../crt/shaders/crt-royale/src/crt-royale-bloom-vertical.slang" +filter_linear10 = "true" # This could just as easily be nearest neighbor. +scale_type10 = "source" +scale10 = "1.0" +srgb_framebuffer10 = "true" + +# Pass 10: Blur the brightpass horizontally and combine it with the dimpass: +shader11 = "../crt/shaders/crt-royale/src/crt-royale-bloom-horizontal-reconstitute.slang" +filter_linear11 = "true" +scale_type11 = "source" +scale11 = "1.0" +srgb_framebuffer11 = "true" + +# Pass 11: Compute curvature/AA: +shader12 = "../crt/shaders/crt-royale/src/crt-royale-last-pass-no-geom.slang" +filter_linear12 = "true" +scale_type12 = "viewport" +mipmap_input12 = "true" +texture_wrap_mode12 = "clamp_to_edge" + +parameters = "crt_gamma;lcd_gamma;levels_contrast;halation_weight;diffusion_weight;bloom_underestimate_levels;bloom_excess;beam_min_sigma;beam_max_sigma;beam_spot_power;beam_min_shape;beam_max_shape;beam_shape_power;beam_horiz_filter;beam_horiz_sigma;beam_horiz_linear_rgb_weight;convergence_offset_x_r;convergence_offset_x_g;convergence_offset_x_b;convergence_offset_y_r;convergence_offset_y_g;convergence_offset_y_b;mask_type;mask_sample_mode_desired;mask_specify_num_triads;mask_triad_size_desired;mask_num_triads_desired;aa_subpixel_r_offset_x_runtime;aa_subpixel_r_offset_y_runtime;aa_cubic_c;aa_gauss_sigma;geom_mode_runtime;geom_radius;geom_view_dist;geom_tilt_angle_x;geom_tilt_angle_y;geom_aspect_ratio_x;geom_aspect_ratio_y;geom_overscan_x;geom_overscan_y;border_size;border_darkness;border_compress;interlace_bff;interlace_1080i;LUT_Size" +crt_gamma = "2.400000" +lcd_gamma = "2.400000" +levels_contrast = "0.740000" +halation_weight = "0.004600" +diffusion_weight = "0.001000" +bloom_underestimate_levels = "0.800000" +bloom_excess = "0.000000" +beam_min_sigma = "0.020000" +beam_max_sigma = "0.200000" +beam_spot_power = "0.370000" +beam_min_shape = "2.000000" +beam_max_shape = "4.000000" +beam_shape_power = "0.250000" +beam_horiz_filter = "0.000000" +beam_horiz_sigma = "0.545000" +beam_horiz_linear_rgb_weight = "1.000000" +convergence_offset_x_r = "-0.050000" +convergence_offset_x_g = "0.000000" +convergence_offset_x_b = "0.000000" +convergence_offset_y_r = "0.100000" +convergence_offset_y_g = "-0.050000" +convergence_offset_y_b = "0.100000" +mask_type = "0.000000" +mask_sample_mode_desired = "0.000000" +mask_specify_num_triads = "0.000000" +mask_triad_size_desired = "1.000000" +mask_num_triads_desired = "900.000000" +aa_subpixel_r_offset_x_runtime = "-0.333333" +aa_subpixel_r_offset_y_runtime = "0.000000" +aa_cubic_c = "0.500000" +aa_gauss_sigma = "0.500000" +geom_mode_runtime = "0.000000" +geom_radius = "3.000000" +geom_view_dist = "2.000000" +geom_tilt_angle_x = "0.000000" +geom_tilt_angle_y = "0.000000" +geom_aspect_ratio_x = "432.000000" +geom_aspect_ratio_y = "329.000000" +geom_overscan_x = "1.000000" +geom_overscan_y = "1.000000" +border_size = "0.005000" +border_darkness = "0.000000" +border_compress = "2.500000" +interlace_bff = "0.000000" +interlace_1080i = "0.000000" +LUT_Size = "32.0" diff --git a/presets/crt-royale-xm29plus.slangp b/presets/crt-royale-xm29plus.slangp index fdc98af..78e3264 100755 --- a/presets/crt-royale-xm29plus.slangp +++ b/presets/crt-royale-xm29plus.slangp @@ -13,16 +13,16 @@ # 1.) bloom_approx_scale_x = scale_x2 # 2.) mask_resize_viewport_scale = float2(scale_x6, scale_y5) # Finally, shader passes need to know the value of geom_max_aspect_ratio used to -# calculate scale_y5 (among other values): +# calculate scale_y6 (among other values): # 1.) geom_max_aspect_ratio = (geom_max_aspect_ratio used to calculate scale_y5) -shaders = "12" +shaders = "13" # Set an identifier, filename, and sampling traits for the phosphor mask texture. # Load an aperture grille, slot mask, and an EDP shadow mask, and load a small # non-mipmapped version and a large mipmapped version. # TODO: Test masks in other directories. -textures = "mask_grille_texture_small;mask_grille_texture_large;mask_slot_texture_small;mask_slot_texture_large;mask_shadow_texture_small;mask_shadow_texture_large" +textures = "mask_grille_texture_small;mask_grille_texture_large;mask_slot_texture_small;mask_slot_texture_large;mask_shadow_texture_small;mask_shadow_texture_large;SamplerLUT" mask_grille_texture_small = "../crt/shaders/crt-royale/TileableLinearApertureGrille15Wide8And5d5SpacingResizeTo64.png" mask_grille_texture_large = "../crt/shaders/crt-royale/TileableLinearApertureGrille15Wide8And5d5Spacing.png" mask_slot_texture_small = "../crt/shaders/crt-royale/TileableLinearSlotMaskTall15Wide9And4d5Horizontal9d14VerticalSpacingResizeTo64.png" @@ -47,16 +47,19 @@ mask_slot_texture_small_mipmap = "false" # Mipmapping causes artifacts with m mask_slot_texture_large_mipmap = "true" # Essential for hardware-resized masks mask_shadow_texture_small_mipmap = "false" # Mipmapping causes artifacts with manually resized masks without tex2Dlod mask_shadow_texture_large_mipmap = "true" # Essential for hardware-resized masks +SamplerLUT = "../reshade/shaders/LUT/NEC_XM29plus_capture.png" +SamplerLUT_linear = true +shader0 = "../reshade/shaders/LUT/LUT.slang" # Pass0: Linearize the input based on CRT gamma and bob interlaced fields. # (Bobbing ensures we can immediately blur without getting artifacts.) -shader0 = "../crt/shaders/crt-royale/src/crt-royale-first-pass-linearize-crt-gamma-bob-fields.slang" -alias0 = "ORIG_LINEARIZED" -filter_linear0 = "false" -scale_type0 = "source" -scale0 = "1.0" -srgb_framebuffer0 = "true" +shader1 = "../crt/shaders/crt-royale/src/crt-royale-first-pass-linearize-crt-gamma-bob-fields.slang" +alias1 = "ORIG_LINEARIZED" +filter_linear1 = "false" +scale_type1 = "source" +scale1 = "1.0" +srgb_framebuffer1 = "true" # Pass1: Resample interlaced (and misconverged) scanlines vertically. # Separating vertical/horizontal scanline sampling is faster: It lets us @@ -64,15 +67,15 @@ srgb_framebuffer0 = "true" # it reduces our samples from vertical*horizontal to vertical+horizontal. # This has to come right after ORIG_LINEARIZED, because there's no # "original_source" scale_type we can use later. -shader1 = "../crt/shaders/crt-royale/src/crt-royale-scanlines-vertical-interlacing.slang" -alias1 = "VERTICAL_SCANLINES" -filter_linear1 = "true" -scale_type_x1 = "source" -scale_x1 = "1.0" -scale_type_y1 = "viewport" -scale_y1 = "1.0" -#float_framebuffer1 = "true" -srgb_framebuffer1 = "true" +shader2 = "../crt/shaders/crt-royale/src/crt-royale-scanlines-vertical-interlacing.slang" +alias2 = "VERTICAL_SCANLINES" +filter_linear2 = "true" +scale_type_x2 = "source" +scale_x2 = "1.0" +scale_type_y2 = "viewport" +scale_y2 = "1.0" +#float_framebuffer2 = "true" +srgb_framebuffer2 = "true" # Pass2: Do a small resize blur of ORIG_LINEARIZED at an absolute size, and # account for convergence offsets. We want to blur a predictable portion of the @@ -84,44 +87,44 @@ srgb_framebuffer1 = "true" # b.) 320x240 works well for the "real bloom" version: It's 1-1.5% faster, and # the only noticeable visual difference is a larger halation spread (which # may be a good thing for people who like to crank it up). -# Note the 4:3 aspect ratio assumes the input has cropped geom_overscan (so it's -# *intended* for an ~4:3 aspect ratio). -shader2 = "../crt/shaders/crt-royale/src/crt-royale-bloom-approx.slang" -alias2 = "BLOOM_APPROX" -filter_linear2 = "true" -scale_type2 = "absolute" -scale_x2 = "320" -scale_y2 = "240" -srgb_framebuffer2 = "true" +# Note the 4:4 aspect ratio assumes the input has cropped geom_overscan (so it's +# *intended* for an ~4:4 aspect ratio). +shader3 = "../crt/shaders/crt-royale/src/crt-royale-bloom-approx.slang" +alias3 = "BLOOM_APPROX" +filter_linear3 = "true" +scale_type3 = "absolute" +scale_x3 = "320" +scale_y3 = "240" +srgb_framebuffer3 = "true" # Pass3: Vertically blur the input for halation and refractive diffusion. # Base this on BLOOM_APPROX: This blur should be small and fast, and blurring # a constant portion of the screen is probably physically correct if the # viewport resolution is proportional to the simulated CRT size. -shader3 = "../blurs/blur5fast-vertical.slang" -filter_linear3 = "true" -scale_type3 = "source" -scale3 = "1.0" -srgb_framebuffer3 = "true" - -# Pass4: Horizontally blur the input for halation and refractive diffusion. -# Note: Using a one-pass 9x9 blur is about 1% slower. -shader4 = "../blurs/blur5fast-horizontal.slang" -alias4 = "HALATION_BLUR" +shader4 = "../blurs/blur5fast-vertical.slang" filter_linear4 = "true" scale_type4 = "source" scale4 = "1.0" srgb_framebuffer4 = "true" +# Pass4: Horizontally blur the input for halation and refractive diffusion. +# Note: Using a one-pass 9x10 blur is about 1% slower. +shader5 = "../blurs/blur5fast-horizontal.slang" +alias5 = "HALATION_BLUR" +filter_linear5 = "true" +scale_type5 = "source" +scale5 = "1.0" +srgb_framebuffer5 = "true" + # Pass5: Lanczos-resize the phosphor mask vertically. Set the absolute -# scale_x5 == mask_texture_small_size.x (see IMPORTANT above). Larger scales +# scale_x6 == mask_texture_small_size.x (see IMPORTANT above). Larger scales # will blur, and smaller scales could get nasty. The vertical size must be # based on the viewport size and calculated carefully to avoid artifacts later. # First calculate the minimum number of mask tiles we need to draw. # Since curvature is computed after the scanline masking pass: # num_resized_mask_tiles = 2.0; # If curvature were computed in the scanline masking pass (it's not): -# max_mask_texel_border = ~3.0 * (1/3.0 + 4.0*sqrt(2.0) + 0.5 + 1.0); +# max_mask_texel_border = ~3.0 * (1/3.0 + 4.0*sqrt(2.0) + 0.6 + 1.0); # max_mask_tile_border = max_mask_texel_border/ # (min_resized_phosphor_triad_size * mask_triads_per_tile); # num_resized_mask_tiles = max(2.0, 1.0 + max_mask_tile_border * 2.0); @@ -131,7 +134,7 @@ srgb_framebuffer4 = "true" # to relate them to vertical resolution. The widest we expect is: # geom_max_aspect_ratio = 4.0/3.0 # Note: Shader passes need to know this! # The fewer triads we tile across the screen, the larger each triad will be as a -# fraction of the viewport size, and the larger scale_y5 must be to draw a full +# fraction of the viewport size, and the larger scale_y6 must be to draw a full # num_resized_mask_tiles. Therefore, we must decide the smallest number of # triads we'll guarantee can be displayed on screen. We'll set this according # to 3-pixel triads at 768p resolution (the lowest anyone's likely to use): @@ -139,72 +142,72 @@ srgb_framebuffer4 = "true" # Now calculate the viewport scale that ensures we can draw resized_mask_tiles: # min_scale_x = resized_mask_tiles * mask_triads_per_tile / # min_allowed_viewport_triads -# scale_y5 = geom_max_aspect_ratio * min_scale_x +# scale_y6 = geom_max_aspect_ratio * min_scale_x # # Some code might depend on equal scales: -# scale_x6 = scale_y5 +# scale_x7 = scale_y5 # Given our default geom_max_aspect_ratio and min_allowed_viewport_triads: -# scale_y5 = 4.0/3.0 * 2.0/(341.33333 / 8.0) = 0.0625 +# scale_y6 = 4.0/3.0 * 2.0/(341.33334 / 8.0) = 0.0625 # IMPORTANT: The scales MUST be calculated in this way. If you wish to change # geom_max_aspect_ratio, update that constant in user-cgp-constants.h! -shader5 = "../crt/shaders/crt-royale/src/crt-royale-mask-resize-vertical.slang" -filter_linear5 = "true" -scale_type_x5 = "absolute" -scale_x5 = "64" -scale_type_y5 = "viewport" -scale_y5 = "0.0625" # Safe for >= 341.333 horizontal triads at viewport size -#srgb_framebuffer5 = "false" # mask_texture is already assumed linear - -# Pass6: Lanczos-resize the phosphor mask horizontally. scale_x6 = scale_y5. -# TODO: Check again if the shaders actually require equal scales. -shader6 = "../crt/shaders/crt-royale/src/crt-royale-mask-resize-horizontal.slang" -alias6 = "MASK_RESIZE" -filter_linear6 = "false" -scale_type_x6 = "viewport" -scale_x6 = "0.0625" -scale_type_y6 = "source" -scale_y6 = "1.0" +shader6 = "../crt/shaders/crt-royale/src/crt-royale-mask-resize-vertical.slang" +filter_linear6 = "true" +scale_type_x6 = "absolute" +scale_x6 = "64" +scale_type_y6 = "viewport" +scale_y6 = "0.0625" # Safe for >= 341.334 horizontal triads at viewport size #srgb_framebuffer6 = "false" # mask_texture is already assumed linear +# Pass6: Lanczos-resize the phosphor mask horizontally. scale_x7 = scale_y5. +# TODO: Check again if the shaders actually require equal scales. +shader7 = "../crt/shaders/crt-royale/src/crt-royale-mask-resize-horizontal.slang" +alias7 = "MASK_RESIZE" +filter_linear7 = "false" +scale_type_x7 = "viewport" +scale_x7 = "0.0625" +scale_type_y7 = "source" +scale_y7 = "1.0" +#srgb_framebuffer7 = "false" # mask_texture is already assumed linear + # Pass7: Resample (misconverged) scanlines horizontally, apply halation, and # apply the phosphor mask. -shader7 = "../crt/shaders/crt-royale/src/crt-royale-scanlines-horizontal-apply-mask.slang" -alias7 = "MASKED_SCANLINES" -filter_linear7 = "true" # This could just as easily be nearest neighbor. -scale_type7 = "viewport" -scale7 = "1.0" -#float_framebuffer7 = "true" -srgb_framebuffer7 = "true" - -# Pass 8: Compute a brightpass. This will require reading the final mask. -shader8 = "../crt/shaders/crt-royale/src/crt-royale-brightpass.slang" -alias8 = "BRIGHTPASS" +shader8 = "../crt/shaders/crt-royale/src/crt-royale-scanlines-horizontal-apply-mask.slang" +alias8 = "MASKED_SCANLINES" filter_linear8 = "true" # This could just as easily be nearest neighbor. scale_type8 = "viewport" scale8 = "1.0" +#float_framebuffer8 = "true" srgb_framebuffer8 = "true" -# Pass 9: Blur the brightpass vertically -shader9 = "../crt/shaders/crt-royale/src/crt-royale-bloom-vertical.slang" +# Pass 8: Compute a brightpass. This will require reading the final mask. +shader9 = "../crt/shaders/crt-royale/src/crt-royale-brightpass.slang" +alias9 = "BRIGHTPASS" filter_linear9 = "true" # This could just as easily be nearest neighbor. -scale_type9 = "source" +scale_type9 = "viewport" scale9 = "1.0" srgb_framebuffer9 = "true" -# Pass 10: Blur the brightpass horizontally and combine it with the dimpass: -shader10 = "../crt/shaders/crt-royale/src/crt-royale-bloom-horizontal-reconstitute.slang" -filter_linear10 = "true" +# Pass 9: Blur the brightpass vertically +shader10 = "../crt/shaders/crt-royale/src/crt-royale-bloom-vertical.slang" +filter_linear10 = "true" # This could just as easily be nearest neighbor. scale_type10 = "source" scale10 = "1.0" srgb_framebuffer10 = "true" -# Pass 11: Compute curvature/AA: -shader11 = "../crt/shaders/crt-royale/src/crt-royale-last-pass-no-geom.slang" +# Pass 10: Blur the brightpass horizontally and combine it with the dimpass: +shader11 = "../crt/shaders/crt-royale/src/crt-royale-bloom-horizontal-reconstitute.slang" filter_linear11 = "true" -scale_type11 = "viewport" -mipmap_input11 = "true" -texture_wrap_mode11 = "clamp_to_edge" +scale_type11 = "source" +scale11 = "1.0" +srgb_framebuffer11 = "true" -parameters = "crt_gamma;lcd_gamma;levels_contrast;halation_weight;diffusion_weight;bloom_underestimate_levels;bloom_excess;beam_min_sigma;beam_max_sigma;beam_spot_power;beam_min_shape;beam_max_shape;beam_shape_power;beam_horiz_filter;beam_horiz_sigma;beam_horiz_linear_rgb_weight;convergence_offset_x_r;convergence_offset_x_g;convergence_offset_x_b;convergence_offset_y_r;convergence_offset_y_g;convergence_offset_y_b;mask_type;mask_sample_mode_desired;mask_specify_num_triads;mask_triad_size_desired;mask_num_triads_desired;aa_subpixel_r_offset_x_runtime;aa_subpixel_r_offset_y_runtime;aa_cubic_c;aa_gauss_sigma;geom_mode_runtime;geom_radius;geom_view_dist;geom_tilt_angle_x;geom_tilt_angle_y;geom_aspect_ratio_x;geom_aspect_ratio_y;geom_overscan_x;geom_overscan_y;border_size;border_darkness;border_compress;interlace_bff;interlace_1080i" +# Pass 11: Compute curvature/AA: +shader12 = "../crt/shaders/crt-royale/src/crt-royale-last-pass-no-geom.slang" +filter_linear12 = "true" +scale_type12 = "viewport" +mipmap_input12 = "true" +texture_wrap_mode12 = "clamp_to_edge" + +parameters = "crt_gamma;lcd_gamma;levels_contrast;halation_weight;diffusion_weight;bloom_underestimate_levels;bloom_excess;beam_min_sigma;beam_max_sigma;beam_spot_power;beam_min_shape;beam_max_shape;beam_shape_power;beam_horiz_filter;beam_horiz_sigma;beam_horiz_linear_rgb_weight;convergence_offset_x_r;convergence_offset_x_g;convergence_offset_x_b;convergence_offset_y_r;convergence_offset_y_g;convergence_offset_y_b;mask_type;mask_sample_mode_desired;mask_specify_num_triads;mask_triad_size_desired;mask_num_triads_desired;aa_subpixel_r_offset_x_runtime;aa_subpixel_r_offset_y_runtime;aa_cubic_c;aa_gauss_sigma;geom_mode_runtime;geom_radius;geom_view_dist;geom_tilt_angle_x;geom_tilt_angle_y;geom_aspect_ratio_x;geom_aspect_ratio_y;geom_overscan_x;geom_overscan_y;border_size;border_darkness;border_compress;interlace_bff;interlace_1080i;LUT_Size" beam_horiz_filter = "0.000000" beam_horiz_linear_rgb_weight = "1.000000" beam_horiz_sigma = "0.555000" @@ -249,3 +252,4 @@ aa_cubic_c = "0.500000" aa_gauss_sigma = "0.500000" aa_subpixel_r_offset_x_runtime = "-0.333333" aa_subpixel_r_offset_y_runtime = "0.000000" +LUT_Size = "32.0"