mirror of
https://github.com/italicsjenga/slang-shaders.git
synced 2024-11-23 00:01:31 +11:00
add crt-hyllian-glow shaders and preset
This commit is contained in:
parent
1a73032cfd
commit
444f4772d3
30
crt/crt-hyllian-glow.slangp
Normal file
30
crt/crt-hyllian-glow.slangp
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
shaders = 6
|
||||||
|
|
||||||
|
shader0 = shaders/glow/linearize.slang
|
||||||
|
filter_linear0 = false
|
||||||
|
srgb_framebuffer0 = true
|
||||||
|
|
||||||
|
shader1 = shaders/crt-hyllian-glow/crt-hyllian.slang
|
||||||
|
filter_linear1 = false
|
||||||
|
scale_type1 = viewport
|
||||||
|
scale1 = 1.0
|
||||||
|
srgb_framebuffer1 = true
|
||||||
|
alias1 = CRT_PASS
|
||||||
|
|
||||||
|
shader2 = shaders/glow/threshold.slang
|
||||||
|
filter_linear2 = false
|
||||||
|
srgb_framebuffer2 = true
|
||||||
|
|
||||||
|
shader3 = shaders/glow/blur_horiz.slang
|
||||||
|
mipmap_input3 = true
|
||||||
|
filter_linear3 = true
|
||||||
|
scale_type3 = source
|
||||||
|
scale3 = 0.25
|
||||||
|
srgb_framebuffer3 = true
|
||||||
|
|
||||||
|
shader4 = shaders/glow/blur_vert.slang
|
||||||
|
filter_linear4 = true
|
||||||
|
srgb_framebuffer4 = true
|
||||||
|
|
||||||
|
shader5 = shaders/crt-hyllian-glow/resolve2.slang
|
||||||
|
filter_linear5 = true
|
185
crt/shaders/crt-hyllian-glow/crt-hyllian.slang
Normal file
185
crt/shaders/crt-hyllian-glow/crt-hyllian.slang
Normal file
|
@ -0,0 +1,185 @@
|
||||||
|
#version 450
|
||||||
|
|
||||||
|
layout(push_constant) uniform Push
|
||||||
|
{
|
||||||
|
float PHOSPHOR;
|
||||||
|
float VSCANLINES;
|
||||||
|
float InputGamma;
|
||||||
|
float OutputGamma;
|
||||||
|
float SHARPNESS;
|
||||||
|
float COLOR_BOOST;
|
||||||
|
float RED_BOOST;
|
||||||
|
float GREEN_BOOST;
|
||||||
|
float BLUE_BOOST;
|
||||||
|
float SCANLINES_STRENGTH;
|
||||||
|
float BEAM_MIN_WIDTH;
|
||||||
|
float BEAM_MAX_WIDTH;
|
||||||
|
float CRT_ANTI_RINGING;
|
||||||
|
} param;
|
||||||
|
|
||||||
|
#pragma parameter PHOSPHOR "CRT - Phosphor ON/OFF" 0.0 0.0 1.0 1.0
|
||||||
|
#pragma parameter VSCANLINES "CRT - Scanlines Direction" 0.0 0.0 1.0 1.0
|
||||||
|
#pragma parameter InputGamma "CRT - Input gamma" 2.2 0.0 5.0 0.1
|
||||||
|
#pragma parameter OutputGamma "CRT - Output Gamma" 2.2 0.0 5.0 0.1
|
||||||
|
#pragma parameter SHARPNESS "CRT - Sharpness Hack" 2.0 1.0 5.0 1.0
|
||||||
|
#pragma parameter COLOR_BOOST "CRT - Color Boost" 1.3 1.0 2.0 0.05
|
||||||
|
#pragma parameter RED_BOOST "CRT - Red Boost" 1.0 1.0 2.0 0.01
|
||||||
|
#pragma parameter GREEN_BOOST "CRT - Green Boost" 1.0 1.0 2.0 0.01
|
||||||
|
#pragma parameter BLUE_BOOST "CRT - Blue Boost" 1.0 1.0 2.0 0.01
|
||||||
|
#pragma parameter SCANLINES_STRENGTH "CRT - Scanline Strength" 1.0 0.0 1.0 0.02
|
||||||
|
#pragma parameter BEAM_MIN_WIDTH "CRT - Min Beam Width" 0.60 0.0 1.0 0.02
|
||||||
|
#pragma parameter BEAM_MAX_WIDTH "CRT - Max Beam Width" 0.80 0.0 1.0 0.02
|
||||||
|
#pragma parameter CRT_ANTI_RINGING "CRT - Anti-Ringing" 0.8 0.0 1.0 0.1
|
||||||
|
|
||||||
|
layout(std140, set = 0, binding = 0) uniform UBO
|
||||||
|
{
|
||||||
|
mat4 MVP;
|
||||||
|
vec4 OutputSize;
|
||||||
|
vec4 OriginalSize;
|
||||||
|
vec4 SourceSize;
|
||||||
|
} 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 = 1) in vec2 FragCoord;
|
||||||
|
layout(location = 0) out vec4 FragColor;
|
||||||
|
layout(set = 0, binding = 2) uniform sampler2D Source;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Hyllian's CRT Shader
|
||||||
|
|
||||||
|
Copyright (C) 2011-2016 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define GAMMA_IN(color) pow(color, vec3(param.InputGamma, param.InputGamma, param.InputGamma))
|
||||||
|
#define GAMMA_OUT(color) pow(color, vec3(1.0 / param.OutputGamma, 1.0 / param.OutputGamma, 1.0 / param.OutputGamma))
|
||||||
|
|
||||||
|
// Horizontal cubic filter.
|
||||||
|
|
||||||
|
// Some known filters use these values:
|
||||||
|
|
||||||
|
// B = 0.0, C = 0.0 => Hermite cubic filter.
|
||||||
|
// B = 1.0, C = 0.0 => Cubic B-Spline filter.
|
||||||
|
// B = 0.0, C = 0.5 => Catmull-Rom Spline filter. This is the default used in this shader.
|
||||||
|
// B = C = 1.0/3.0 => Mitchell-Netravali cubic filter.
|
||||||
|
// B = 0.3782, C = 0.3109 => Robidoux filter.
|
||||||
|
// B = 0.2620, C = 0.3690 => Robidoux Sharp filter.
|
||||||
|
// B = 0.36, C = 0.28 => My best config for ringing elimination in pixel art (Hyllian).
|
||||||
|
|
||||||
|
// For more info, see: http://www.imagemagick.org/Usage/img_diagrams/cubic_survey.gif
|
||||||
|
|
||||||
|
// Change these params to configure the horizontal filter.
|
||||||
|
float B = 0.0;
|
||||||
|
float C = 0.5;
|
||||||
|
|
||||||
|
mat4x4 invX = mat4x4(
|
||||||
|
(-B - 6.0*C)/6.0, (3.0*B + 12.0*C)/6.0, (-3.0*B - 6.0*C)/6.0, B/6.0,
|
||||||
|
(12.0 - 9.0*B - 6.0*C)/6.0, (-18.0 + 12.0*B + 6.0*C)/6.0, 0.0, (6.0 - 2.0*B)/6.0,
|
||||||
|
-(12.0 - 9.0*B - 6.0*C)/6.0, (18.0 - 15.0*B - 12.0*C)/6.0, (3.0*B + 6.0*C)/6.0, B/6.0,
|
||||||
|
(B + 6.0*C)/6.0, -C, 0.0, 0.0
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec3 color;
|
||||||
|
|
||||||
|
vec2 TextureSize = vec2(param.SHARPNESS*global.SourceSize.x, global.SourceSize.y);
|
||||||
|
|
||||||
|
vec2 dx = mix(vec2(1.0/TextureSize.x, 0.0), vec2(0.0, 1.0/TextureSize.y), param.VSCANLINES);
|
||||||
|
vec2 dy = mix(vec2(0.0, 1.0/TextureSize.y), vec2(1.0/TextureSize.x, 0.0), param.VSCANLINES);
|
||||||
|
|
||||||
|
vec2 pix_coord = vTexCoord*TextureSize + vec2(-0.5, 0.5);
|
||||||
|
|
||||||
|
vec2 tc = mix((floor(pix_coord) + vec2(0.5, 0.5))/TextureSize, (floor(pix_coord) + vec2(1.0, -0.5))/TextureSize, param.VSCANLINES);
|
||||||
|
|
||||||
|
vec2 fp = mix(fract(pix_coord), fract(pix_coord.yx), param.VSCANLINES);
|
||||||
|
|
||||||
|
vec3 c00 = GAMMA_IN(texture(Source, tc - dx - dy).xyz);
|
||||||
|
vec3 c01 = GAMMA_IN(texture(Source, tc - dy).xyz);
|
||||||
|
vec3 c02 = GAMMA_IN(texture(Source, tc + dx - dy).xyz);
|
||||||
|
vec3 c03 = GAMMA_IN(texture(Source, tc + 2.0*dx - dy).xyz);
|
||||||
|
vec3 c10 = GAMMA_IN(texture(Source, tc - dx ).xyz);
|
||||||
|
vec3 c11 = GAMMA_IN(texture(Source, tc ).xyz);
|
||||||
|
vec3 c12 = GAMMA_IN(texture(Source, tc + dx ).xyz);
|
||||||
|
vec3 c13 = GAMMA_IN(texture(Source, tc + 2.0*dx ).xyz);
|
||||||
|
|
||||||
|
// Get min/max samples
|
||||||
|
vec3 min_sample = min(min(c01, c11), min(c02, c12));
|
||||||
|
vec3 max_sample = max(max(c01, c11), max(c02, c12));
|
||||||
|
|
||||||
|
mat4x3 color_matrix0 = mat4x3(c00, c01, c02, c03);
|
||||||
|
mat4x3 color_matrix1 = mat4x3(c10, c11, c12, c13);
|
||||||
|
|
||||||
|
vec4 invX_Px = vec4(fp.x*fp.x*fp.x, fp.x*fp.x, fp.x, 1.0) * invX;
|
||||||
|
vec3 color0 = color_matrix0 * invX_Px;
|
||||||
|
vec3 color1 = color_matrix1 * invX_Px;
|
||||||
|
|
||||||
|
// Anti-ringing
|
||||||
|
vec3 aux = color0;
|
||||||
|
color0 = clamp(color0, min_sample, max_sample);
|
||||||
|
color0 = mix(aux, color0, param.CRT_ANTI_RINGING);
|
||||||
|
aux = color1;
|
||||||
|
color1 = clamp(color1, min_sample, max_sample);
|
||||||
|
color1 = mix(aux, color1, param.CRT_ANTI_RINGING);
|
||||||
|
|
||||||
|
float pos0 = fp.y;
|
||||||
|
float pos1 = 1 - fp.y;
|
||||||
|
|
||||||
|
vec3 lum0 = mix(vec3(param.BEAM_MIN_WIDTH), vec3(param.BEAM_MAX_WIDTH), color0);
|
||||||
|
vec3 lum1 = mix(vec3(param.BEAM_MIN_WIDTH), vec3(param.BEAM_MAX_WIDTH), color1);
|
||||||
|
|
||||||
|
vec3 d0 = clamp(pos0/(lum0 + 0.0000001), 0.0, 1.0);
|
||||||
|
vec3 d1 = clamp(pos1/(lum1 + 0.0000001), 0.0, 1.0);
|
||||||
|
|
||||||
|
d0 = exp(-10.0*param.SCANLINES_STRENGTH*d0*d0);
|
||||||
|
d1 = exp(-10.0*param.SCANLINES_STRENGTH*d1*d1);
|
||||||
|
|
||||||
|
color = clamp(color0*d0 + color1*d1, 0.0, 1.0);
|
||||||
|
|
||||||
|
color *= param.COLOR_BOOST*vec3(param.RED_BOOST, param.GREEN_BOOST, param.BLUE_BOOST);
|
||||||
|
|
||||||
|
float mod_factor = mix(vTexCoord.x * global.OutputSize.x, vTexCoord.y * global.OutputSize.y, param.VSCANLINES);
|
||||||
|
|
||||||
|
vec3 dotMaskWeights = mix(
|
||||||
|
vec3(1.0, 0.7, 1.0),
|
||||||
|
vec3(0.7, 1.0, 0.7),
|
||||||
|
floor(mod(mod_factor, 2.0))
|
||||||
|
);
|
||||||
|
|
||||||
|
color.rgb *= mix(vec3(1.0), dotMaskWeights, param.PHOSPHOR);
|
||||||
|
|
||||||
|
color = GAMMA_OUT(color);
|
||||||
|
|
||||||
|
FragColor = vec4(color, 1.0);
|
||||||
|
}
|
50
crt/shaders/crt-hyllian-glow/resolve2.slang
Normal file
50
crt/shaders/crt-hyllian-glow/resolve2.slang
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
#version 450
|
||||||
|
|
||||||
|
layout(push_constant) uniform Push
|
||||||
|
{
|
||||||
|
vec4 SourceSize;
|
||||||
|
vec4 OriginalSize;
|
||||||
|
vec4 OutputSize;
|
||||||
|
uint FrameCount;
|
||||||
|
float BLOOM_STRENGTH;
|
||||||
|
float SOURCE_BOOST;
|
||||||
|
} params;
|
||||||
|
|
||||||
|
#pragma parameter BLOOM_STRENGTH "Bloom Strength" 0.45 0.0 1.0 0.01
|
||||||
|
#pragma parameter SOURCE_BOOST "Bloom Color Boost" 1.15 1.0 1.3 0.01
|
||||||
|
|
||||||
|
#define BLOOM_STRENGTH params.BLOOM_STRENGTH
|
||||||
|
#define SOURCE_BOOST params.SOURCE_BOOST
|
||||||
|
|
||||||
|
#define INV_OUTPUT_GAMMA (1.0 / 2.2)
|
||||||
|
#define saturate(c) clamp(c, 0.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 CRT_PASS;
|
||||||
|
|
||||||
|
void main()
|
||||||
|
{
|
||||||
|
vec3 source = SOURCE_BOOST * texture(CRT_PASS, vTexCoord).rgb;
|
||||||
|
vec3 bloom = texture(Source, vTexCoord).rgb;
|
||||||
|
source += BLOOM_STRENGTH * bloom;
|
||||||
|
FragColor = vec4(pow(saturate(source), vec3(INV_OUTPUT_GAMMA,INV_OUTPUT_GAMMA,INV_OUTPUT_GAMMA)), 1.0);
|
||||||
|
}
|
Loading…
Reference in a new issue