From 7e8d978fcd2faa2769a7dfb7de09305f3f9e48bb Mon Sep 17 00:00:00 2001 From: hunterk Date: Thu, 16 May 2019 14:49:39 -0500 Subject: [PATCH] add cgwg's geom-deluxe shaders and preset --- crt/crt-geom-deluxe.slangp | 29 ++ crt/shaders/geom-deluxe/crt-geom-deluxe.slang | 323 ++++++++++++++++++ crt/shaders/geom-deluxe/gaussx.slang | 47 +++ crt/shaders/geom-deluxe/gaussy.slang | 47 +++ .../geom-deluxe/geom-deluxe-params.inc | 55 +++ .../geom-deluxe/masks/aperture_1_2_bgr.png | Bin 0 -> 153 bytes .../geom-deluxe/masks/aperture_1_4_rgb.png | Bin 0 -> 152 bytes .../geom-deluxe/masks/aperture_2_4_rgb.png | Bin 0 -> 159 bytes .../geom-deluxe/masks/aperture_2_5_bgr.png | Bin 0 -> 156 bytes .../geom-deluxe/masks/aperture_3_6_rgb.png | Bin 0 -> 159 bytes .../geom-deluxe/masks/delta_1_2x1_bgr.png | Bin 0 -> 159 bytes .../geom-deluxe/masks/delta_1_4x1_rgb.png | Bin 0 -> 156 bytes .../geom-deluxe/masks/delta_2_4x1_rgb.png | Bin 0 -> 164 bytes .../geom-deluxe/masks/delta_2_4x2_rgb.png | Bin 0 -> 168 bytes .../geom-deluxe/masks/slot_2_4x4_rgb.png | Bin 0 -> 171 bytes .../geom-deluxe/masks/slot_2_5x4_bgr.png | Bin 0 -> 176 bytes .../geom-deluxe/masks/slot_3_7x6_rgb.png | Bin 0 -> 180 bytes crt/shaders/geom-deluxe/phosphor_apply.slang | 38 +++ crt/shaders/geom-deluxe/phosphor_update.slang | 41 +++ 19 files changed, 580 insertions(+) create mode 100644 crt/crt-geom-deluxe.slangp create mode 100644 crt/shaders/geom-deluxe/crt-geom-deluxe.slang create mode 100644 crt/shaders/geom-deluxe/gaussx.slang create mode 100644 crt/shaders/geom-deluxe/gaussy.slang create mode 100644 crt/shaders/geom-deluxe/geom-deluxe-params.inc create mode 100644 crt/shaders/geom-deluxe/masks/aperture_1_2_bgr.png create mode 100644 crt/shaders/geom-deluxe/masks/aperture_1_4_rgb.png create mode 100644 crt/shaders/geom-deluxe/masks/aperture_2_4_rgb.png create mode 100644 crt/shaders/geom-deluxe/masks/aperture_2_5_bgr.png create mode 100644 crt/shaders/geom-deluxe/masks/aperture_3_6_rgb.png create mode 100644 crt/shaders/geom-deluxe/masks/delta_1_2x1_bgr.png create mode 100644 crt/shaders/geom-deluxe/masks/delta_1_4x1_rgb.png create mode 100644 crt/shaders/geom-deluxe/masks/delta_2_4x1_rgb.png create mode 100644 crt/shaders/geom-deluxe/masks/delta_2_4x2_rgb.png create mode 100644 crt/shaders/geom-deluxe/masks/slot_2_4x4_rgb.png create mode 100644 crt/shaders/geom-deluxe/masks/slot_2_5x4_bgr.png create mode 100644 crt/shaders/geom-deluxe/masks/slot_3_7x6_rgb.png create mode 100644 crt/shaders/geom-deluxe/phosphor_apply.slang create mode 100644 crt/shaders/geom-deluxe/phosphor_update.slang diff --git a/crt/crt-geom-deluxe.slangp b/crt/crt-geom-deluxe.slangp new file mode 100644 index 0000000..9a145ee --- /dev/null +++ b/crt/crt-geom-deluxe.slangp @@ -0,0 +1,29 @@ +shaders = 5 + +shader0 = shaders/geom-deluxe/phosphor_apply.slang +alias0 = internal1 + +shader1 = shaders/geom-deluxe/phosphor_update.slang +alias1 = phosphor + +shader2 = shaders/geom-deluxe/gaussx.slang +filter_linear2 = true +alias2 = internal2 + +shader3 = shaders/geom-deluxe/gaussy.slang +filter_linear3 = true +alias3 = blur + +shader4 = shaders/geom-deluxe/crt-geom-deluxe.slang +filter_linear4 = true + +textures = "aperture;slot;delta" +delta = shaders/geom-deluxe/masks/delta_2_4x1_rgb.png +delta_filter_linear = true +delta_repeat_mode = repeat +slot = shaders/geom-deluxe/masks/slot_2_5x4_bgr.png +slot_filter_linear = true +slot_repeat_mode = repeat +aperture = shaders/geom-deluxe/masks/aperture_2_4_rgb.png +aperture_filter_linear = true +aperture_repeat_mode = repeat \ No newline at end of file diff --git a/crt/shaders/geom-deluxe/crt-geom-deluxe.slang b/crt/shaders/geom-deluxe/crt-geom-deluxe.slang new file mode 100644 index 0000000..7d8d6c7 --- /dev/null +++ b/crt/shaders/geom-deluxe/crt-geom-deluxe.slang @@ -0,0 +1,323 @@ +#version 450 + +/* CRT shader + * + * Copyright (C) 2010-2016 cgwg, Themaister and DOLLS + * + * 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. + */ + +#include "geom-deluxe-params.inc" + +#define u_tex_size0 global.SourceSize +#define u_tex_size1 global.internal1Size +#define u_quad_dims global.OutputSize + +// Comment the next line to disable interpolation in linear gamma (and gain speed). +//#define LINEAR_PROCESSING + +// Enable 3x oversampling of the beam profile +#define OVERSAMPLE + +// Use the older, purely gaussian beam profile +#define USEGAUSSIAN + +// Macros. +#define FIX(c) max(abs(c), 1e-5) +#define PI 3.141592653589 + +#pragma stage vertex +layout(location = 0) in vec4 Position; +layout(location = 1) in vec2 TexCoord; +layout(location = 0) out vec2 v_texCoord; +layout(location = 1) out vec2 v_sinangle; +layout(location = 2) out vec2 v_cosangle; +layout(location = 3) out vec3 v_stretch; +layout(location = 4) out vec2 v_one; + +float intersect(vec2 xy , vec2 sinangle, vec2 cosangle) +{ + float A = dot(xy,xy)+d.x*d.x; + float B = 2.0*(params.R.x*(dot(xy,sinangle)-d.x*cosangle.x*cosangle.y)-d.x*d.x); + float C = d.x*d.x + 2.0*params.R.x*d.x*cosangle.x*cosangle.y; + return (-B-sqrt(B*B-4.0*A*C))/(2.0*A); +} + +vec2 bkwtrans(vec2 xy, vec2 sinangle, vec2 cosangle) +{ + float c = intersect(xy, sinangle, cosangle); + vec2 pt = vec2(c)*xy; + pt -= vec2(-params.R.x)*sinangle; + pt /= vec2(params.R.x); + vec2 tang = sinangle/cosangle; + vec2 poc = pt/cosangle; + float A = dot(tang,tang)+1.0; + float B = -2.0*dot(poc,tang); + float C = dot(poc,poc)-1.0; + float a = (-B+sqrt(B*B-4.0*A*C))/(2.0*A); + vec2 uv = (pt-a*sinangle)/cosangle; + float r = FIX(params.R.x*acos(a)); + return uv*r/sin(r/params.R.x); +} + +vec2 fwtrans(vec2 uv, vec2 sinangle, vec2 cosangle) +{ + float r = FIX(sqrt(dot(uv,uv))); + uv *= sin(r/params.R.x)/r; + float x = 1.0-cos(r/params.R.x); + float D = d.x/params.R.x + x*cosangle.x*cosangle.y+dot(uv,sinangle); + return d.x*(uv*cosangle-x*sinangle)/D; +} + +vec3 maxscale(vec2 sinangle, vec2 cosangle) +{ + vec2 c = bkwtrans(-params.R.x * sinangle / (1.0 + params.R.x/d.x*cosangle.x*cosangle.y), sinangle, cosangle); + vec2 a = vec2(0.5,0.5)*aspect.xy; + vec2 lo = vec2(fwtrans(vec2(-a.x,c.y), sinangle, cosangle).x, + fwtrans(vec2(c.x,-a.y), sinangle, cosangle).y)/aspect.xy; + vec2 hi = vec2(fwtrans(vec2(+a.x,c.y), sinangle, cosangle).x, + fwtrans(vec2(c.x,+a.y), sinangle, cosangle).y)/aspect.xy; + return vec3((hi+lo)*aspect.xy*0.5,max(hi.x-lo.x,hi.y-lo.y)); +} + +void main() +{ + gl_Position = global.MVP * Position; + v_texCoord = TexCoord; + + // Precalculate a bunch of useful values we'll need in the fragment + // shader. + vec2 ang; + // if (u_rotation_type.x < 0.5) + // ang = vec2(0.0,angle.x); + // else if (u_rotation_type.x < 1.5) + // ang = vec2(angle.x,0.0); + // else if (u_rotation_type.x < 2.5) + // ang = vec2(0.0,-angle.x); + // else + // ang = vec2(-angle.x,0.0); + ang = angle.xy; + v_sinangle = sin(ang); + v_cosangle = cos(ang); + v_stretch = maxscale(v_sinangle, v_cosangle); + + // The size of one texel, in texture-coordinates. + v_one = 1.0 / u_tex_size0.xy; +} + +#pragma stage fragment +layout(location = 0) in vec2 v_texCoord; +layout(location = 1) in vec2 v_sinangle; +layout(location = 2) in vec2 v_cosangle; +layout(location = 3) in vec3 v_stretch; +layout(location = 4) in vec2 v_one; +layout(location = 0) out vec4 FragColor; +layout(set = 0, binding = 2) uniform sampler2D blur; +layout(set = 0, binding = 3) uniform sampler2D internal1; +layout(set = 0, binding = 4) uniform sampler2D aperture; +layout(set = 0, binding = 5) uniform sampler2D slot; +layout(set = 0, binding = 6) uniform sampler2D delta; + +#define blur_texture blur + +#ifdef LINEAR_PROCESSING +# define TEX2D(c) pow(texture(internal1, (c)), vec4(CRTgamma)) +#else +# define TEX2D(c) texture(internal1, (c)) +#endif + +float intersect(vec2 xy , vec2 sinangle, vec2 cosangle) +{ + float A = dot(xy,xy)+d.x*d.x; + float B = 2.0*(params.R.x*(dot(xy,sinangle)-d.x*cosangle.x*cosangle.y)-d.x*d.x); + float C = d.x*d.x + 2.0*params.R.x*d.x*cosangle.x*cosangle.y; + return (-B-sqrt(B*B-4.0*A*C))/(2.0*A); +} + +vec2 bkwtrans(vec2 xy, vec2 sinangle, vec2 cosangle) +{ + float c = intersect(xy, sinangle, cosangle); + vec2 pt = vec2(c)*xy; + pt -= vec2(-params.R.x)*sinangle; + pt /= vec2(params.R.x); + vec2 tang = sinangle/cosangle; + vec2 poc = pt/cosangle; + float A = dot(tang,tang)+1.0; + float B = -2.0*dot(poc,tang); + float C = dot(poc,poc)-1.0; + float a = (-B+sqrt(B*B-4.0*A*C))/(2.0*A); + vec2 uv = (pt-a*sinangle)/cosangle; + float r = FIX(params.R.x*acos(a)); + return uv*r/sin(r/params.R.x); +} + +vec2 transform(vec2 coord, vec3 stretch, vec2 sinangle, vec2 cosangle) +{ + coord = (coord-vec2(0.5))*aspect.xy*stretch.z+stretch.xy; + return (bkwtrans(coord, sinangle, cosangle)/overscan.xy/aspect.xy+vec2(0.5)); +} + +float corner(vec2 coord) +{ + coord = (coord - vec2(0.5)) * overscan.xy + vec2(0.5); + coord = min(coord, vec2(1.0)-coord) * aspect.xy; + vec2 cdist = vec2(cornersize.x); + coord = (cdist - min(coord,cdist)); + float dist = sqrt(dot(coord,coord)); + return clamp((max(cdist.x,1e-3)-dist)*cornersmooth.x,0.0, 1.0); +} + +// Calculate the influence of a scanline on the current pixel. +// +// 'distance' is the distance in texture coordinates from the current +// pixel to the scanline in question. +// 'color' is the colour of the scanline at the horizontal location of +// the current pixel. +vec4 scanlineWeights(float distance, vec4 color) +{ + // "wid" controls the width of the scanline beam, for each RGB channel + // The "weights" lines basically specify the formula that gives + // you the profile of the beam, i.e. the intensity as + // a function of distance from the vertical center of the + // scanline. In this case, it is gaussian if width=2, and + // becomes nongaussian for larger widths. Ideally this should + // be normalized so that the integral across the beam is + // independent of its width. That is, for a narrower beam + // "weights" should have a higher peak at the center of the + // scanline than for a wider beam. +#ifdef USEGAUSSIAN + vec4 wid = 0.3 + 0.1 * pow(color, vec4(3.0)); + vec4 weights = vec4(distance / wid); + return 0.4 * exp(-weights * weights) / wid; +#else + vec4 wid = 2.0 + 2.0 * pow(color, vec4(4.0)); + vec4 weights = vec4(distance / 0.3); + return 1.4 * exp(-pow(weights * inversesqrt(0.5 * wid), wid)) / (0.6 + 0.2 * wid); +#endif +} + +void main() +{ + // Here's a helpful diagram to keep in mind while trying to + // understand the code: + // + // | | | | | + // ------------------------------- + // | | | | | + // | 01 | 11 | 21 | 31 | <-- current scanline + // | | @ | | | + // ------------------------------- + // | | | | | + // | 02 | 12 | 22 | 32 | <-- next scanline + // | | | | | + // ------------------------------- + // | | | | | + // + // Each character-cell represents a pixel on the output + // surface, "@" represents the current pixel (always somewhere + // in the bottom half of the current scan-line, or the top-half + // of the next scanline). The grid of lines represents the + // edges of the texels of the underlying texture. + + // Texture coordinates of the texel containing the active pixel. + vec2 xy; + if (curvature.x > 0.5) + xy = transform(v_texCoord, v_stretch, v_sinangle, v_cosangle); + else + xy = (v_texCoord-vec2(0.5))/overscan.xy+vec2(0.5); + vec2 xy0 = xy; + float cval = corner(xy); + + // Of all the pixels that are mapped onto the texel we are + // currently rendering, which pixel are we currently rendering? + vec2 ratio_scale = xy * u_tex_size0.xy - vec2(0.5); + +#ifdef OVERSAMPLE + float oversample_filter = fwidth(ratio_scale.y); +#endif + vec2 uv_ratio = fract(ratio_scale); + + // Snap to the center of the underlying texel. + xy = (floor(ratio_scale) + vec2(0.5)) / u_tex_size0.xy; + + // Calculate Lanczos scaling coefficients describing the effect + // of various neighbour texels in a scanline on the current + // pixel. + vec4 coeffs = PI * vec4(1.0 + uv_ratio.x, uv_ratio.x, 1.0 - uv_ratio.x, 2.0 - uv_ratio.x); + + // Prevent division by zero. + coeffs = FIX(coeffs); + + // Lanczos2 kernel. + coeffs = 2.0 * sin(coeffs) * sin(coeffs / 2.0) / (coeffs * coeffs); + + // Normalize. + coeffs /= dot(coeffs, vec4(1.0)); + + // Calculate the effective colour of the current and next + // scanlines at the horizontal location of the current pixel, + // using the Lanczos coefficients above. + vec4 col = clamp(TEX2D(xy + vec2(-v_one.x, 0.0))*coeffs.x + + TEX2D(xy)*coeffs.y + + TEX2D(xy +vec2(v_one.x, 0.0))*coeffs.z + + TEX2D(xy + vec2(2.0 * v_one.x, 0.0))*coeffs.w , 0.0, 1.0); + + vec4 col2 = clamp(TEX2D(xy + vec2(-v_one.x, v_one.y))*coeffs.x + + TEX2D(xy + vec2(0.0, v_one.y))*coeffs.y + + TEX2D(xy + v_one)*coeffs.z + + TEX2D(xy + vec2(2.0 * v_one.x, v_one.y))*coeffs.w , 0.0, 1.0); + + +#ifndef LINEAR_PROCESSING + col = pow(col , vec4(CRTgamma.x)); + col2 = pow(col2, vec4(CRTgamma.x)); +#endif + + // Calculate the influence of the current and next scanlines on + // the current pixel. + vec4 weights = scanlineWeights(uv_ratio.y, col); + vec4 weights2 = scanlineWeights(1.0 - uv_ratio.y, col2); +#ifdef OVERSAMPLE + uv_ratio.y =uv_ratio.y+1.0/3.0*oversample_filter; + weights = (weights+scanlineWeights(uv_ratio.y, col))/3.0; + weights2=(weights2+scanlineWeights(abs(1.0-uv_ratio.y), col2))/3.0; + uv_ratio.y =uv_ratio.y-2.0/3.0*oversample_filter; + weights=weights+scanlineWeights(abs(uv_ratio.y), col)/3.0; + weights2=weights2+scanlineWeights(abs(1.0-uv_ratio.y), col2)/3.0; +#endif + vec3 mul_res = (col * weights + col2 * weights2).rgb; + + // halation and corners + vec3 blur = pow(texture(blur_texture,xy0).rgb, vec3(CRTgamma.x)); + mul_res = mix(mul_res, blur, halation.x) * vec3(cval); + + // Convert the image gamma for display on our output device. + mul_res = pow(mul_res, vec3(1.0 / monitorgamma.x)); + + // Shadow mask + // original code; just makes a giant phosphor here + // xy = v_texCoord.xy * u_quad_dims.xy / u_tex_size1.xy; + + // tiling; looks nasty at non-integer x and/or y + // xy = fract(v_texCoord * global.SourceSize.xy * 1.9999); + + // gl_FragCoord; tied to physical pixel size + xy = v_texCoord.xy * global.OutputSize.xy; + + //vec3 mask = texture(mask_texture, xy).rgb; + vec3 mask = vec3(1.0); + if(mask_picker == 0) // no mask + { + FragColor = vec4(mul_res, col.a); + return; + } + else if(mask_picker == 1) mask = texture(aperture, xy * 0.3333).rgb; + else if(mask_picker == 2) mask = texture(slot, xy * 0.25).rgb; + else mask = texture(delta, xy * 0.49999).rgb; + mask = mix(vec3(1.0), mask, aperture_strength.x); + + FragColor = vec4(mul_res*mask, col.a); +} \ No newline at end of file diff --git a/crt/shaders/geom-deluxe/gaussx.slang b/crt/shaders/geom-deluxe/gaussx.slang new file mode 100644 index 0000000..1b6650f --- /dev/null +++ b/crt/shaders/geom-deluxe/gaussx.slang @@ -0,0 +1,47 @@ +#version 450 + +#include "geom-deluxe-params.inc" + +#define tex_size0 global.SourceSize + +#pragma stage vertex +layout(location = 0) in vec4 Position; +layout(location = 1) in vec2 TexCoord; +layout(location = 0) out vec2 v_texCoord; +layout(location = 1) out vec4 v_coeffs; + +void main() +{ + gl_Position = global.MVP * Position; + v_texCoord = TexCoord; + float wid = width.x*tex_size0.x/(320.*aspect.x); + v_coeffs = exp(vec4(1.,4.,9.,16.)*vec4(-1.0/wid/wid)); +} + +#pragma stage fragment +layout(location = 0) in vec2 v_texCoord; +layout(location = 1) in vec4 v_coeffs; +layout(location = 0) out vec4 FragColor; +layout(set = 0, binding = 2) uniform sampler2D internal1; + +#define TEX2D(v) pow(texture(internal1, v).rgb, vec3(gamma)) + +void main() +{ + vec3 sum = vec3(0.0); + float onex = 1.0/tex_size0.x; + + sum += TEX2D(v_texCoord + vec2(-4.0 * onex, 0.0)) * vec3(v_coeffs.w); + sum += TEX2D(v_texCoord + vec2(-3.0 * onex, 0.0)) * vec3(v_coeffs.z); + sum += TEX2D(v_texCoord + vec2(-2.0 * onex, 0.0)) * vec3(v_coeffs.y); + sum += TEX2D(v_texCoord + vec2(-1.0 * onex, 0.0)) * vec3(v_coeffs.x); + sum += TEX2D(v_texCoord); + sum += TEX2D(v_texCoord + vec2(+1.0 * onex, 0.0)) * vec3(v_coeffs.x); + sum += TEX2D(v_texCoord + vec2(+2.0 * onex, 0.0)) * vec3(v_coeffs.y); + sum += TEX2D(v_texCoord + vec2(+3.0 * onex, 0.0)) * vec3(v_coeffs.z); + sum += TEX2D(v_texCoord + vec2(+4.0 * onex, 0.0)) * vec3(v_coeffs.w); + + float norm = 1.0 / (1.0 + 2.0*(v_coeffs.x+v_coeffs.y+v_coeffs.z+v_coeffs.w)); + + FragColor = vec4( pow(sum*vec3(norm), vec3(1.0/gamma.x)), 1.0 ); +} \ No newline at end of file diff --git a/crt/shaders/geom-deluxe/gaussy.slang b/crt/shaders/geom-deluxe/gaussy.slang new file mode 100644 index 0000000..6299453 --- /dev/null +++ b/crt/shaders/geom-deluxe/gaussy.slang @@ -0,0 +1,47 @@ +#version 450 + +#include "geom-deluxe-params.inc" + +#define tex_size0 global.SourceSize + +#pragma stage vertex +layout(location = 0) in vec4 Position; +layout(location = 1) in vec2 TexCoord; +layout(location = 0) out vec2 v_texCoord; +layout(location = 1) out vec4 v_coeffs; + +void main() +{ + gl_Position = global.MVP * Position; + v_texCoord = TexCoord; + float wid = width.x*tex_size0.y/(320.*aspect.y); + v_coeffs = exp(vec4(1.,4.,9.,16.)*vec4(-1.0/wid/wid)); +} + +#pragma stage fragment +layout(location = 0) in vec2 v_texCoord; +layout(location = 1) in vec4 v_coeffs; +layout(location = 0) out vec4 FragColor; +layout(set = 0, binding = 2) uniform sampler2D Source; + +#define TEX2D(v) pow(texture(Source, v).rgb, vec3(gamma)) + +void main() +{ + vec3 sum = vec3(0.0); + float oney = 1.0/tex_size0.y; + + sum += TEX2D(v_texCoord + vec2(0.0, -4.0 * oney)) * vec3(v_coeffs.w); + sum += TEX2D(v_texCoord + vec2(0.0, -3.0 * oney)) * vec3(v_coeffs.z); + sum += TEX2D(v_texCoord + vec2(0.0, -2.0 * oney)) * vec3(v_coeffs.y); + sum += TEX2D(v_texCoord + vec2(0.0, -1.0 * oney)) * vec3(v_coeffs.x); + sum += TEX2D(v_texCoord); + sum += TEX2D(v_texCoord + vec2(0.0, +1.0 * oney)) * vec3(v_coeffs.x); + sum += TEX2D(v_texCoord + vec2(0.0, +2.0 * oney)) * vec3(v_coeffs.y); + sum += TEX2D(v_texCoord + vec2(0.0, +3.0 * oney)) * vec3(v_coeffs.z); + sum += TEX2D(v_texCoord + vec2(0.0, +4.0 * oney)) * vec3(v_coeffs.w); + + float norm = 1.0 / (1.0 + 2.0*(v_coeffs.x+v_coeffs.y+v_coeffs.z+v_coeffs.w)); + + FragColor = vec4( pow(sum*vec3(norm), vec3(1.0/gamma.x)), 1.0 ); +} \ No newline at end of file diff --git a/crt/shaders/geom-deluxe/geom-deluxe-params.inc b/crt/shaders/geom-deluxe/geom-deluxe-params.inc new file mode 100644 index 0000000..ceb0ffa --- /dev/null +++ b/crt/shaders/geom-deluxe/geom-deluxe-params.inc @@ -0,0 +1,55 @@ +layout(push_constant) uniform Push +{ + float phosphor_power, phosphor_amplitude, CRTgamma, width, aspect_x, aspect_y, d, R, angle_x, angle_y, + aperture_strength, halation, curvature, cornersize, cornersmooth, overscan_x, overscan_y, + monitorgamma, mask_type; +} params; + +layout(std140, set = 0, binding = 0) uniform UBO +{ + vec4 SourceSize; + vec4 OriginalSize; + vec4 OutputSize; + uint FrameCount; + vec4 FinalViewportSize; + vec4 internal1Size; + mat4 MVP; +} global; + +#pragma parameter mask_type "Mask (none, aperture, slot, delta)" 1.0 0.0 3.0 1.0 +#pragma parameter aperture_strength "Shadow mask strength" 0.4 0.0 1.0 0.05 +#pragma parameter phosphor_power "Phosphor decay power" 1.2 0.5 3.0 0.05 +#pragma parameter phosphor_amplitude "Phosphor persistence amplitude" 0.04 0.0 0.2 0.01 +#pragma parameter CRTgamma "Gamma of simulated CRT" 2.4 0.7 4.0 0.05 +#pragma parameter halation "Halation amplitude" 0.1 0.0 0.3 0.01 +#pragma parameter width "Halation blur width" 2.0 0.1 4.0 0.1 +#pragma parameter curvature "Enable Curvature" 1.0 0.0 1.0 1.0 +#pragma parameter R "Radius of curvature" 3.5 0.5 10.0 0.1 +#pragma parameter d "Distance to screen" 2.0 0.1 10.0 0.1 +#pragma parameter angle_x "Tilt X" 0.0 -1.0 1.0 0.01 +#pragma parameter angle_y "Tilt Y" 0.0 -1.0 1.0 0.01 +#pragma parameter cornersize "Rounded corner size" 0.01 0.00 0.10 0.01 +#pragma parameter cornersmooth "Border smoothness" 1000.0 100.0 2000.0 100.0 +#pragma parameter overscan_x "Overscan X" 1.0 0.8 1.2 0.02 +#pragma parameter overscan_y "Overscan Y" 1.0 0.8 1.2 0.02 +#pragma parameter monitorgamma "Gamma of output display" 2.2 0.7 4.0 0.05 +#pragma parameter aspect_x "Aspect ratio X" 1.0 0.3 1.0 0.01 +#pragma parameter aspect_y "Aspect ratio Y" 0.75 0.3 1.0 0.01 + +#define phosphor_power params.phosphor_power +#define phosphor_amplitude params.phosphor_amplitude +#define CRTgamma params.CRTgamma +#define width params.width +#define curvature params.curvature +#define d params.d +#define cornersize params.cornersize +#define cornersmooth params.cornersmooth +#define monitorgamma params.monitorgamma +#define halation params.halation +#define aperture_strength params.aperture_strength +vec2 aspect = vec2(params.aspect_x, params.aspect_y); +vec2 angle = vec2(params.angle_x, params.angle_y); +vec2 overscan = vec2(params.overscan_x, params.overscan_y); +int mask_picker = int(params.mask_type); + +const float gamma = 2.2; \ No newline at end of file diff --git a/crt/shaders/geom-deluxe/masks/aperture_1_2_bgr.png b/crt/shaders/geom-deluxe/masks/aperture_1_2_bgr.png new file mode 100644 index 0000000000000000000000000000000000000000..26c49ba1c813a9eadcadefb12a258250186056e0 GIT binary patch literal 153 zcmeAS@N?(olHy`uVBq!ia0vp^OhC-Y0V1m%UfcyzoCO|{#S9GG!XV7ZFl&wkP>{XE z)7O>#0UHkwr?7LvkCQ+l+02lL66gHf+|;}hAeVu`xhOTUBsE2$JhLQ2!QIn0AVn{g q9VpK4>Eal|aXtCR`496S+A}k7|7QA^Zo4ECq{q|M&t;ucLK6UY7bZ&p literal 0 HcmV?d00001 diff --git a/crt/shaders/geom-deluxe/masks/aperture_1_4_rgb.png b/crt/shaders/geom-deluxe/masks/aperture_1_4_rgb.png new file mode 100644 index 0000000000000000000000000000000000000000..1667e2abfac38dadc35e478869ba60a614d907de GIT binary patch literal 152 zcmeAS@N?(olHy`uVBq!ia0vp^EI`c2!2~4B;%3YOQk(@Ik;M!Q+`=Ht$S`Y;1W=H@ z#M9T6{Q(;fkCxT`YVjjLA=%83h!W@g+}zZ>5+Ij>!MP|ku_QG`p**uBL&4qCHy}kX ql^rO~=jq}Y!f`$M$N2*X7!EUte`Wf2u2lajNQlFz;kcgs=lp>KALchsd}zCo*%Q~loCIH}TCZYfU literal 0 HcmV?d00001 diff --git a/crt/shaders/geom-deluxe/masks/aperture_2_5_bgr.png b/crt/shaders/geom-deluxe/masks/aperture_2_5_bgr.png new file mode 100644 index 0000000000000000000000000000000000000000..0efddb5bcee308651035bb1bb0035ab511830480 GIT binary patch literal 156 zcmeAS@N?(olHy`uVBq!ia0vp^tU%1j!2~2{&iT9qNO2Z;L>4nJa0`PlBg3pY5H=O_6KY{Jp3%vUf${e3dv@MM3gw^=jNv7l>oU649-QVi6yBi3gww484B*6z5ywE vsq8>;Ax{^_5RU7~f6gB`aNxsyK{o~lIeunFsUPwWK-xTA{an^LB{Ts5E>tHJ literal 0 HcmV?d00001 diff --git a/crt/shaders/geom-deluxe/masks/aperture_3_6_rgb.png b/crt/shaders/geom-deluxe/masks/aperture_3_6_rgb.png new file mode 100644 index 0000000000000000000000000000000000000000..8ebbb448786b9317119e3c83083f923808d1dbbe GIT binary patch literal 159 zcmeAS@N?(olHy`uVBq!ia0vp^>_E)O!2~4dW-8AFQk(@Ik;M!Q+`=Ht$S`Y;1V~kh zr>`sf12!HW0lwX7wj4kq+02lL66gHf+|;}hAeVu`xhOTUBsE2$JhLQ2!QIn0AVn_~ tWV)!Qi(?4K_2fV24}idj`Hg~|OblAW%#4f+@4o=)^mO%eS?83{1OU+{CrtnV literal 0 HcmV?d00001 diff --git a/crt/shaders/geom-deluxe/masks/delta_1_2x1_bgr.png b/crt/shaders/geom-deluxe/masks/delta_1_2x1_bgr.png new file mode 100644 index 0000000000000000000000000000000000000000..497ca42647477b1c7fc8ff9c9ef584875a63773c GIT binary patch literal 159 zcmeAS@N?(olHy`uVBq!ia0vp^Od!kwBL7~QRScv!3p^r$G`BDaGcwGYBLNg-FY)ws zWq-iN!=s@#(?^pNC?uO15>euupPQSSR|4cRFgO>bCYGe8D3oWGWGJ|M`Ua%vrLqIX sMLk^{LpZLp9%N($@)`vG`-@MSV50ei_4m719v}q_p00i_>zopr0O0T?NdN!< literal 0 HcmV?d00001 diff --git a/crt/shaders/geom-deluxe/masks/delta_1_4x1_rgb.png b/crt/shaders/geom-deluxe/masks/delta_1_4x1_rgb.png new file mode 100644 index 0000000000000000000000000000000000000000..21144c3b1833042a99cebdc69e7fc64162249562 GIT binary patch literal 156 zcmeAS@N?(olHy`uVBq!ia0vp^EI`b}!2~2foO)#fq&N#aB8wRqxP?KOkzv*x37{Z* ziKnkC`vW!}9vxAq553YrA=%83h!W@g+}zZ>5+Ij>!MP|ku_QG`p**uBL&4qCHy}kX ul^rN9LV0FMhJw4NZ$OG( zDmzeI%G1R$gyXvH;f=fu3_OPwKK;M=E=)ztNb;3@>IaVBJr_2og0y?O`njxgN@xNA DY0fJ^ literal 0 HcmV?d00001 diff --git a/crt/shaders/geom-deluxe/masks/delta_2_4x2_rgb.png b/crt/shaders/geom-deluxe/masks/delta_2_4x2_rgb.png new file mode 100644 index 0000000000000000000000000000000000000000..9cba74f077da0a5d3bdcf6d6ff24bf7397462b42 GIT binary patch literal 168 zcmeAS@N?(olHy`uVBq!ia0vp^EFjFm1SHiab7}%9&H|6fVg?3oVGw3ym^DWND9B#o z>Fdh=fQ^SojdykN-{U|b+02lL66gHf+|;}hAeVu`xhOTUBsE2$JhLQ2!QIn0AVn{g z9Vjm6>Eal|aXtCZ`2z<&%x|3d(4JYDS(usY$A9_0z!U~1V~+ou5+Ij>!MP|ku_QG`p**uBL&4qCHy}kX zl^rOq=;`7Z!f`$M&-nufKFn_vWZrC`!04vZqtv)&HfyA)5d%ZbBu*h&EslR6Q#@V$ KT-G@yGywqL%qe&P literal 0 HcmV?d00001 diff --git a/crt/shaders/geom-deluxe/masks/slot_2_5x4_bgr.png b/crt/shaders/geom-deluxe/masks/slot_2_5x4_bgr.png new file mode 100644 index 0000000000000000000000000000000000000000..58d1651bc38ebbd1d087b2943a01f7f8e0cf22aa GIT binary patch literal 176 zcmeAS@N?(olHy`uVBq!ia0vp^AT|pJ6OgosvYZ8^I14-?iy0WWg+Z8+Vb&Z8pdfpR zr>`sf12!HWG36DHkNpM;$!3N`lsM<-=BDPA0J#hd&PAz-C8;S2<(VZJ3hti10V#T^ z>_BlfPZ!4!j_b*P&L22%;KO`D_JfB`G;m5hWI0{m!XTsIlj0cMmnOlW+Q2DvT zWe19DdAc};NL)_-bN&Dbe3;)jQQ+ti2a|+@TBkaC53Lhfz1pLYA#C>sCWgyfIK|w% R*3SeP=jrO_vd$@?2>@|TGr#}< literal 0 HcmV?d00001 diff --git a/crt/shaders/geom-deluxe/phosphor_apply.slang b/crt/shaders/geom-deluxe/phosphor_apply.slang new file mode 100644 index 0000000..e72ec5a --- /dev/null +++ b/crt/shaders/geom-deluxe/phosphor_apply.slang @@ -0,0 +1,38 @@ +#version 450 + +#include "geom-deluxe-params.inc" + +#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 PassFeedback1; + +void main() +{ + vec4 screen = texture(Source, vTexCoord); + vec4 phosphor = texture(PassFeedback1, vTexCoord); + + vec3 cscrn = pow(screen.rgb, vec3(gamma)); + vec3 cphos = pow(phosphor.rgb, vec3(gamma)); + + // encode the upper 2 bits of the time elapsed in the lower 2 bits of b + float t = 255.0*phosphor.a + fract(phosphor.b*255.0/4.0)*1024.0; + + cphos *= vec3( phosphor_amplitude * pow(t,-phosphor_power) ); + + vec3 col = pow(cscrn + cphos, vec3(1.0/gamma)); + + FragColor = vec4(col, 1.0); +} \ No newline at end of file diff --git a/crt/shaders/geom-deluxe/phosphor_update.slang b/crt/shaders/geom-deluxe/phosphor_update.slang new file mode 100644 index 0000000..0394611 --- /dev/null +++ b/crt/shaders/geom-deluxe/phosphor_update.slang @@ -0,0 +1,41 @@ +#version 450 +#pragma name phosphor + +#include "geom-deluxe-params.inc" + +#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 phosphor; + +void main() +{ + vec4 screen = texture(Source, vTexCoord); + vec4 phosphor = texture(phosphor, vTexCoord); + + vec3 lum = vec3(0.299,0.587,0.114); + float bscrn = dot(pow(screen.rgb,vec3(gamma)),lum); + float bphos = dot(pow(phosphor.rgb,vec3(gamma)),lum); + // encode the upper 2 bits of the time elapsed in the lower 2 bits of b + float t = 1.0 + 255.0*phosphor.a + fract(phosphor.b*255.0/4.0)*1024.0; + + bphos = ( t > 1023.0 ? 0.0 : bphos*pow(t,-phosphor_power) ); + + FragColor = ( bscrn >= bphos ? + vec4(screen.rg,floor(screen.b*255.0/4.0)*4.0/255.0,1.0/255.0) + : vec4(phosphor.rg, + (floor(phosphor.b*255.0/4.0)*4.0 + floor(t/256.0))/255.0, + fract(t/256.0)*256.0/255.0 ) ); +} \ No newline at end of file