port fake-crt-geom & hyllian-fast (#380)

* Add files via upload

* Add files via upload

* port fake-crt-geom

* port fake-crt-geom

* port crt-hyllian-fast

* port crt-hyllian-fast
This commit is contained in:
metallic77 2023-04-07 17:10:33 +03:00 committed by GitHub
parent 4ab9e232f3
commit 5ed39804bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 324 additions and 0 deletions

View file

@ -0,0 +1,5 @@
shaders = 1
shader0 = shaders/hyllian/crt-hyllian-fast.slang
filter_linear0 = false
scale_type0 = viewport

5
crt/fake-crt-geom.slangp Normal file
View file

@ -0,0 +1,5 @@
shaders = 1
shader0 = shaders/fake-crt-geom.slang
filter_linear0 = true
scale_type0 = viewport

View file

@ -0,0 +1,167 @@
#version 450
// Simple scanlines with curvature and mask effects lifted from crt-geom
// original by hunterk, edited by DariusG
layout(push_constant) uniform Push
{
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
float SCANLINE_BASE_BRIGHTNESS;
float SCANLINE_SINE_COMP_A;
float SCANLINE_SINE_COMP_B;
float warpX;
float warpY;
float corner_round;
float cgwg;
float crt_gamma;
float monitor_gamma;
float boost;
} params;
// Parameter lines go here:
#pragma parameter SCANLINE_SINE_COMP_B "Scanline Intensity" 0.60 0.0 1.0 0.05
#define SCANLINE_SINE_COMP_B params.SCANLINE_SINE_COMP_B
#pragma parameter warpX "warpX" 0.03 0.0 0.125 0.01
#define warpX params.warpX
#pragma parameter warpY "warpY" 0.05 0.0 0.125 0.01
#define warpY params.warpY
#pragma parameter corner_round "Corner Roundness" 0.030 0.005 0.100 0.005
#define corner_round params.corner_round
#pragma parameter cgwg "CGWG mask str. " 0.5 0.0 1.0 0.1
#define cgwg params.cgwg
#pragma parameter crt_gamma "CRT Gamma" 2.5 1.0 4.0 0.05
#define crt_gamma params.crt_gamma
#pragma parameter monitor_gamma "Monitor Gamma" 2.2 1.0 4.0 0.05
#define monitor_gamma params.monitor_gamma
#pragma parameter boost "Bright boost " 1.00 1.00 2.00 0.02
#define boost params.boost
#pragma parameter SCANLINE_SINE_COMP_A "Scanline Sine Comp A" 0.0 0.0 0.10 0.01
#define SCANLINE_SINE_COMP_A params.SCANLINE_SINE_COMP_A
#pragma parameter SCANLINE_BASE_BRIGHTNESS "Scanline Base Brightness" 0.95 0.0 1.0 0.01
#define SCANLINE_BASE_BRIGHTNESS params.SCANLINE_BASE_BRIGHTNESS
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 = 1) uniform sampler2D Source;
///////////////////////////////////////////////////////////////////////////////////////////////
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;
}
vec4 scanline(vec2 coord, vec4 frame)
{
vec2 omega = vec2(3.1415 * params.OutputSize.x, 2.0 * 3.1415 * params.SourceSize.y);
vec2 sine_comp = vec2(SCANLINE_SINE_COMP_A, SCANLINE_SINE_COMP_B);
vec3 res = frame.xyz;
vec3 scanline = res * (SCANLINE_BASE_BRIGHTNESS + dot(sine_comp * sin(coord * omega), vec2(1.0, 1.0)));
return vec4(scanline.x, scanline.y, scanline.z, 1.0);
}
float corner(vec2 coord)
{
coord = (coord - vec2(0.5)) * 1.0 + vec2(0.5);
coord = min(coord, vec2(1.0)-coord) * vec2(1.0, params.SourceSize.z/params.SourceSize.zw);
vec2 cdist = vec2(corner_round);
coord = (cdist - min(coord,cdist));
float dist = sqrt(dot(coord,coord));
return clamp((cdist.x-dist)*300.0,0.0, 1.0);
}
// mask calculation
// cgwg mask.
vec4 Mask(vec2 pos)
{
vec3 mask = vec3(1.0);
{
float mf = floor(mod(pos.x,2.0));
float mc = 1.0 - cgwg;
if (mf == 0.0) { mask.g = mc; }
else { mask.r = mc; mask.b = mc; };
}
return vec4(mask, 1.0);
}
///////////////////////////////////////////////////////////////////
void main()
{
vec2 pos = Warp(vTexCoord.xy);
//borrowed from CRT-Pi
vec2 OGL2Pos = pos * params.SourceSize.xy;
vec2 pC4 = floor(OGL2Pos) + 0.5;
vec2 coord = pC4 / params.SourceSize.xy;
vec2 deltas = OGL2Pos - pC4;
vec2 signs = sign(deltas);
deltas.x *= 2.0;
deltas = deltas * deltas;
deltas.y = deltas.y * deltas.y;
deltas.x *= 0.5;
deltas.y *= 8.0;
deltas /= params.SourceSize.xy;
deltas *= signs;
vec2 tc = coord + deltas;
// mask effects look bad unless applied in linear gamma space
vec4 in_gamma = vec4(crt_gamma, crt_gamma, crt_gamma, 1.0);
vec4 out_gamma = vec4(1.0 / monitor_gamma, 1.0 / monitor_gamma, 1.0 / monitor_gamma, 1.0);
vec4 res = texture(Source, tc);
res=pow(res,in_gamma);
// apply the mask; looks bad with vert scanlines so make them mutually exclusive
res *= Mask(vTexCoord * params.OutputSize.xy * 1.0001);
// re-apply the gamma curve for the mask path
vec4 color = pow(scanline(pos, res), out_gamma);
float lum = color.r*0.3+color.g*0.6+color.b*0.1;
color*= mix(1.0,boost,lum);
FragColor = color*corner(tc);
}

View file

@ -0,0 +1,147 @@
#version 450
/*
Hyllian's CRT Shader
with cgwg's magenta/green dotmask
ported to GLSL/SLANG by DariusG & hunterk
Copyright (C) 2011-2015 Hyllian - sergiogdb@gmail.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
layout(push_constant) uniform Push
{
float MASK_INTENSITY;
float InputGamma;
float OutputGamma;
float BRIGHTBOOST;
float SCANLINES;
} params;
// Parameter lines go here:
#pragma parameter MASK_INTENSITY "MASK INTENSITY" 0.5 0.0 1.0 0.1
#define MASK_INTENSITY params.MASK_INTENSITY
#pragma parameter InputGamma "INPUT GAMMA" 2.4 0.0 5.0 0.1
#define InputGamma params.InputGamma
#pragma parameter OutputGamma "OUTPUT GAMMA" 2.2 0.0 5.0 0.1
#define OutputGamma params.OutputGamma
#pragma parameter BRIGHTBOOST "BRIGHT BOOST" 1.5 0.0 2.0 0.1
#define BRIGHTBOOST params.BRIGHTBOOST
#pragma parameter SCANLINES "SCANLINES STRENGTH" 0.72 0.0 1.0 0.02
#define SCANLINES params.SCANLINES
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
} global;
#define SourceSize global.SourceSize
#define TextureSize SourceSize.xy
#define InputSize global.OriginalSize.xy
#define COMPAT_TEXTURE texture
#define GAMMA_IN(color) pow(color, vec3(InputGamma, InputGamma, InputGamma))
#define GAMMA_OUT(color) pow(color, vec3(1.0 / OutputGamma, 1.0 / OutputGamma, 1.0 / OutputGamma))
#pragma stage vertex
layout(location = 0) in vec4 Position;
layout(location = 1) in vec2 TexCoord;
layout(location = 0) out vec2 vTexCoord;
layout(location = 1) out vec2 ps;
void main()
{
gl_Position = global.MVP * Position;
vec2 tex_size = vec2(TextureSize.x, TextureSize.y);
ps = 1.0/tex_size;
vTexCoord.xy = TexCoord.xy + ps * vec2(-0.49999, 0.0);
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 1) in vec2 ps;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 1) uniform sampler2D Source;
///////////////////////////////////////////////////////////////////////////////////////////////
void main()
{
vec2 dx = vec2(ps.x, 0.0);
vec2 dy = vec2(0.0, ps.y);
vec2 tc = (floor(vTexCoord.xy * SourceSize.xy) + vec2(0.49999, 0.49999)) / SourceSize.xy;
vec2 fp = fract(vTexCoord.xy * SourceSize.xy);
vec3 c10 = COMPAT_TEXTURE(Source, tc - dx).xyz;
vec3 c11 = COMPAT_TEXTURE(Source, tc ).xyz;
vec3 c12 = COMPAT_TEXTURE(Source, tc + dx).xyz;
vec3 c13 = COMPAT_TEXTURE(Source, tc + 2.0 * dx).xyz;
vec4 lobes = vec4(fp.x*fp.x*fp.x, fp.x*fp.x, fp.x, 1.0);
vec4 InvX = vec4(0.0);
// Horizontal cubic filter
InvX.x = dot(vec4( -0.5, 1.0, -0.5, 0.0), lobes);
InvX.y = dot(vec4( 1.5,-2.5, 0.0, 1.0), lobes);
InvX.z = dot(vec4( -1.5, 2.0, 0.5, 0.0), lobes);
InvX.w = dot(vec4( 0.5,-0.5, 0.0, 0.0), lobes);
vec3 color = InvX.x*c10.xyz;
color+= InvX.y*c11.xyz;
color+= InvX.z*c12.xyz;
color+= InvX.w*c13.xyz;
color = GAMMA_IN(color);
float pos1 = 1.5-SCANLINES - abs(fp.y - 0.5);
float d1 = max(0.0, min(1.0, pos1));
float d = d1*d1*(3.0+BRIGHTBOOST - (2.0*d1));
color = color*d;
// dotmask
float mod_factor = vTexCoord.x * global.OutputSize.x;
vec4 dotMaskWeights = mix(
vec4(1.0, 1.0-MASK_INTENSITY, 1.0, 1.),
vec4(1.0-MASK_INTENSITY, 1.0, 1.0-MASK_INTENSITY, 1.),
floor(mod(mod_factor, 2.0))
);
color *=vec3(dotMaskWeights.x,dotMaskWeights.y,dotMaskWeights.z);
color = GAMMA_OUT(color);
FragColor = vec4(color.r, color.g, color.b, 1.0);
}