add parameters to lottes multipass and create a glow version

This commit is contained in:
hunterk 2016-08-23 16:09:44 -05:00
parent f82445a2a7
commit d33a8be758
4 changed files with 399 additions and 48 deletions

View file

@ -0,0 +1,72 @@
shaders = 13
shader0 = shaders/crt-royale/src/crt-royale-first-pass-linearize-crt-gamma-bob-fields.slang
float_framebuffer0 = true
alias0 = "REFERENCE"
shader1 = "shaders/crt-lottes-multipass/threshold.slang"
srgb_framebuffer1 = "true"
shader2 = "../blurs/blur9fast-vertical.slang"
filter_linear2 = "true"
scale_type2 = "source"
scale2 = "1.0"
srgb_framebuffer2 = "true"
shader3 = "../blurs/blur9fast-horizontal.slang"
alias3 = "HALATION_BLUR"
filter_linear3 = "true"
scale_type3 = "source"
scale3 = "1.0"
srgb_framebuffer3 = "true"
shader4 = shaders/crt-lottes-multipass/horz3minus1.slang
float_framebuffer4 = true
scale_type4 = source
filter_linear4 = true
alias4 = horz3minus1
shader5 = shaders/crt-lottes-multipass/horz3plus1.slang
float_framebuffer5 = true
scale_type5 = source
filter_linear5 = true
alias5 = horz3plus1
shader6 = shaders/crt-lottes-multipass/horz5minus2.slang
float_framebuffer6 = true
scale_type6 = source
filter_linear6 = true
alias6 = horz5minus2
shader7 = shaders/crt-lottes-multipass/horz5.slang
float_framebuffer7 = true
scale_type7 = source
filter_linear7 = true
alias7 = horz5
shader8 = shaders/crt-lottes-multipass/horz5plus2.slang
float_framebuffer8 = true
scale_type8 = source
filter_linear8 = true
alias8 = horz5plus2
shader9 = shaders/crt-lottes-multipass/horz7minus1.slang
float_framebuffer9 = true
scale_type9 = source
filter_linear9 = true
alias9 = horz7minus1
shader10 = shaders/crt-lottes-multipass/horz7.slang
float_framebuffer10 = true
scale_type10 = source
filter_linear10 = true
alias10 = horz7
shader11 = shaders/crt-lottes-multipass/horz7plus1.slang
float_framebuffer11 = true
scale_type11 = source
filter_linear11 = true
alias11 = horz7plus1
shader12 = shaders/crt-lottes-multipass/crt-lottes-multipass-glow.slang
texture_wrap_mode12 = "clamp_to_edge"

View file

@ -0,0 +1,234 @@
#version 450
layout(push_constant) uniform Push
{
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
float hardScan;
float warpX;
float warpY;
float maskDark;
float maskLight;
float shadowMask;
float bloomAmount;
float hardBloomScan;
float shape;
float glowFactor;
} params;
#pragma parameter hardScan "hardScan" -8.0 -20.0 0.0 1.0
#pragma parameter warpX "warpX" 0.031 0.0 0.125 0.01
#pragma parameter warpY "warpY" 0.041 0.0 0.125 0.01
#pragma parameter maskDark "maskDark" 0.5 0.0 2.0 0.1
#pragma parameter maskLight "maskLight" 1.5 0.0 2.0 0.1
#pragma parameter shadowMask "shadowMask" 1.0 0.0 4.0 1.0
#pragma parameter hardBloomScan "bloom-y soft" -2.0 -4.0 -1.0 0.1
#pragma parameter bloomAmount "bloom amount" 0.15 0.0 1.0 0.05
#pragma parameter shape "filter kernel shape" 2.0 0.0 10.0 0.05
#pragma parameter glowFactor "Glow Strength" 0.2 0.0 1.0 0.01
#define DO_BLOOM
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;
}
// PUBLIC DOMAIN CRT STYLED SCAN-LINE SHADER
//
// by Timothy Lottes
//
// This is more along the style of a really good CGA arcade monitor.
// With RGB inputs instead of NTSC.
// The shadow mask example has the mask rotated 90 degrees for less chromatic aberration.
//
// Left it unoptimized to show the theory behind the algorithm.
//
// It is an example what I personally would want as a display option for pixel art games.
// Please take and use, change, or whatever.
#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 horz3minus1;
layout(set = 0, binding = 3) uniform sampler2D horz3plus1;
layout(set = 0, binding = 4) uniform sampler2D horz5minus2;
layout(set = 0, binding = 5) uniform sampler2D horz5;
layout(set = 0, binding = 6) uniform sampler2D horz5plus2;
layout(set = 0, binding = 7) uniform sampler2D horz7minus1;
layout(set = 0, binding = 8) uniform sampler2D horz7;
layout(set = 0, binding = 9) uniform sampler2D horz7plus1;
layout(set = 0, binding = 10) uniform sampler2D HALATION_BLUR;
// Linear to sRGB.
// Assuming using sRGB typed textures this should not be needed.
float ToSrgb1(float c)
{
return(c < 0.0031308 ? c*12.92 : 1.055*pow(c, 0.41666) - 0.055);
}
vec3 ToSrgb(vec3 c)
{
return vec3(ToSrgb1(c.r), ToSrgb1(c.g), ToSrgb1(c.b));
}
// Distance in emulated pixels to nearest texel.
vec2 Dist(vec2 pos)
{
pos = pos*params.SourceSize.xy;
return -((pos - floor(pos)) - vec2(0.5));
}
// 1D Gaussian.
float Gaus(float pos, float scale)
{
return exp2(scale*pow(abs(pos), params.shape));
}
// Return scanline weight.
float Scan(vec2 pos, float off)
{
float dst = Dist(pos).y;
return Gaus(dst + off, params.hardScan);
}
// Return scanline weight for bloom.
float BloomScan(vec2 pos, float off)
{
float dst = Dist(pos).y;
return Gaus(dst + off, params.hardBloomScan);
}
// Allow nearest three lines to effect pixel.
vec3 Tri(vec2 pos)
{
vec3 a = texture(horz3minus1, pos).rgb;//Horz3(pos,-1.0);
vec3 b = texture(horz5, pos).rgb;//Horz5(pos, 0.0);
vec3 c = texture(horz3plus1, pos).rgb;//Horz3(pos, 1.0);
float wa = Scan(pos, -1.0);
float wb = Scan(pos, 0.0);
float wc = Scan(pos, 1.0);
return a*wa+b*wb+c*wc;
}
// Small bloom.
vec3 Bloom(vec2 pos)
{
vec3 a = texture(horz5minus2, pos).rgb;//Horz5(pos,-2.0);
vec3 b = texture(horz7minus1, pos).rgb;//Horz7(pos,-1.0);
vec3 c = texture(horz7, pos).rgb;//Horz7(pos, 0.0);
vec3 d = texture(horz7plus1, pos).rgb;//Horz7(pos, 1.0);
vec3 e = texture(horz5plus2, pos).rgb;//Horz5(pos, 2.0);
float wa = BloomScan(pos, -2.0);
float wb = BloomScan(pos, -1.0);
float wc = BloomScan(pos, 0.0);
float wd = BloomScan(pos, 1.0);
float we = BloomScan(pos, 2.0);
return a*wa+b*wb+c*wc+d*wd+e*we;
}
// Distortion of scanlines, and end of screen alpha.
vec2 Warp(vec2 pos)
{
pos = pos*2.0-1.0;
pos *= vec2(1.0 + (pos.y*pos.y)*params.warpX, 1.0 + (pos.x*pos.x)*params.warpY);
return pos*0.5 + 0.5;
}
// Shadow mask.
vec3 Mask(vec2 pos)
{
vec3 mask = vec3(params.maskDark, params.maskDark, params.maskDark);
// Very compressed TV style shadow mask.
if (params.shadowMask == 1.0)
{
float line = params.maskLight;
float odd = 0.0;
if (fract(pos.x*0.166666666) < 0.5) odd = 1.0;
if (fract((pos.y + odd) * 0.5) < 0.5) line = params.maskDark;
pos.x = fract(pos.x*0.333333333);
if (pos.x < 0.333) mask.r = params.maskLight;
else if (pos.x < 0.666) mask.g = params.maskLight;
else mask.b = params.maskLight;
mask*=line;
}
// Aperture-grille.
else if (params.shadowMask == 2.0)
{
pos.x = fract(pos.x*0.333333333);
if (pos.x < 0.333) mask.r = params.maskLight;
else if (pos.x < 0.666) mask.g = params.maskLight;
else mask.b = params.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*0.166666666);
if (pos.x < 0.333) mask.r = params.maskLight;
else if (pos.x < 0.666) mask.g = params.maskLight;
else mask.b = params.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*0.166666666);
if (pos.x < 0.333) mask.r = params.maskLight;
else if (pos.x < 0.666) mask.g = params.maskLight;
else mask.b = params.maskLight;
}
return mask;
}
void main()
{
vec2 pos = Warp(vTexCoord);
vec3 outColor = Tri(pos);
#ifdef DO_BLOOM
//Add Bloom
outColor.rgb += Bloom(pos)*params.bloomAmount;
#endif
if (params.shadowMask > 0.0)
outColor.rgb *= Mask(vTexCoord.xy / params.OutputSize.zw * 1.000001);
if (params.glowFactor > 0.0)
outColor = mix(outColor, pow(texture(HALATION_BLUR, pos).rgb, mix(vec3(0.75), vec3(0.1), params.glowFactor)), params.glowFactor);
FragColor = vec4(ToSrgb(outColor.rgb), 1.0);
}

View file

@ -1,26 +1,36 @@
#version 450
// -- config -- //
layout(push_constant) uniform Push
{
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
float hardScan;
float warpX;
float warpY;
float maskDark;
float maskLight;
float shadowMask;
float bloomAmount;
float hardBloomScan;
float shape;
} params;
#define hardScan -8.0
#define warpX 0.031
#define warpY 0.041
#define maskDark 0.5
#define maskLight 1.5
#define shadowMask 1
#define brightboost 1
#define bloomAmount 1.0/16.0
#define hardBloomScan -2.0
#define shape 2.0
#pragma parameter hardScan "hardScan" -8.0 -20.0 0.0 1.0
#pragma parameter warpX "warpX" 0.031 0.0 0.125 0.01
#pragma parameter warpY "warpY" 0.041 0.0 0.125 0.01
#pragma parameter maskDark "maskDark" 0.5 0.0 2.0 0.1
#pragma parameter maskLight "maskLight" 1.5 0.0 2.0 0.1
#pragma parameter shadowMask "shadowMask" 3.0 0.0 4.0 1.0
#pragma parameter hardBloomScan "bloom-y soft" -2.0 -4.0 -1.0 0.1
#pragma parameter bloomAmount "bloom amount" 0.15 0.0 1.0 0.05
#pragma parameter shape "filter kernel shape" 2.0 0.0 10.0 0.05
#define DO_BLOOM
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 SourceSize;
} global;
#pragma stage vertex
@ -75,7 +85,7 @@ vec3 ToSrgb(vec3 c)
// Distance in emulated pixels to nearest texel.
vec2 Dist(vec2 pos)
{
pos = pos*global.SourceSize.xy;
pos = pos*params.SourceSize.xy;
return -((pos - floor(pos)) - vec2(0.5));
}
@ -83,7 +93,7 @@ vec2 Dist(vec2 pos)
// 1D Gaussian.
float Gaus(float pos, float scale)
{
return exp2(scale*pow(abs(pos), shape));
return exp2(scale*pow(abs(pos), params.shape));
}
// Return scanline weight.
@ -91,7 +101,7 @@ float Scan(vec2 pos, float off)
{
float dst = Dist(pos).y;
return Gaus(dst + off, hardScan);
return Gaus(dst + off, params.hardScan);
}
// Return scanline weight for bloom.
@ -99,7 +109,7 @@ float BloomScan(vec2 pos, float off)
{
float dst = Dist(pos).y;
return Gaus(dst + off, hardBloomScan);
return Gaus(dst + off, params.hardBloomScan);
}
// Allow nearest three lines to effect pixel.
@ -138,7 +148,7 @@ vec3 Bloom(vec2 pos)
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);
pos *= vec2(1.0 + (pos.y*pos.y)*params.warpX, 1.0 + (pos.x*pos.x)*params.warpY);
return pos*0.5 + 0.5;
}
@ -146,56 +156,56 @@ vec2 Warp(vec2 pos)
// Shadow mask.
vec3 Mask(vec2 pos)
{
vec3 mask = vec3(maskDark, maskDark, maskDark);
vec3 mask = vec3(params.maskDark, params.maskDark, params.maskDark);
// Very compressed TV style shadow mask.
if (shadowMask == 1.0)
if (params.shadowMask == 1.0)
{
float line = maskLight;
float line = params.maskLight;
float odd = 0.0;
if (fract(pos.x*0.166666666) < 0.5) odd = 1.0;
if (fract((pos.y + odd) * 0.5) < 0.5) line = maskDark;
if (fract((pos.y + odd) * 0.5) < 0.5) line = params.maskDark;
pos.x = fract(pos.x*0.333333333);
if (pos.x < 0.333) mask.r = maskLight;
else if (pos.x < 0.666) mask.g = maskLight;
else mask.b = maskLight;
if (pos.x < 0.333) mask.r = params.maskLight;
else if (pos.x < 0.666) mask.g = params.maskLight;
else mask.b = params.maskLight;
mask*=line;
}
// Aperture-grille.
else if (shadowMask == 2.0)
else if (params.shadowMask == 2.0)
{
pos.x = fract(pos.x*0.333333333);
if (pos.x < 0.333) mask.r = maskLight;
else if (pos.x < 0.666) mask.g = maskLight;
else mask.b = maskLight;
if (pos.x < 0.333) mask.r = params.maskLight;
else if (pos.x < 0.666) mask.g = params.maskLight;
else mask.b = params.maskLight;
}
// Stretched VGA style shadow mask (same as prior shaders).
else if (shadowMask == 3.0)
else if (params.shadowMask == 3.0)
{
pos.x += pos.y*3.0;
pos.x = fract(pos.x*0.166666666);
if (pos.x < 0.333) mask.r = maskLight;
else if (pos.x < 0.666) mask.g = maskLight;
else mask.b = maskLight;
if (pos.x < 0.333) mask.r = params.maskLight;
else if (pos.x < 0.666) mask.g = params.maskLight;
else mask.b = params.maskLight;
}
// VGA style shadow mask.
else if (shadowMask == 4.0)
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*0.166666666);
if (pos.x < 0.333) mask.r = maskLight;
else if (pos.x < 0.666) mask.g = maskLight;
else mask.b = maskLight;
if (pos.x < 0.333) mask.r = params.maskLight;
else if (pos.x < 0.666) mask.g = params.maskLight;
else mask.b = params.maskLight;
}
return mask;
@ -208,18 +218,11 @@ void main()
#ifdef DO_BLOOM
//Add Bloom
outColor.rgb += Bloom(pos)*bloomAmount;
outColor.rgb += Bloom(pos)*params.bloomAmount;
#endif
if (shadowMask > 0.0)
outColor.rgb *= Mask(vTexCoord.xy / global.OutputSize.zw * 1.000001);
/* TODO/FIXME - hacky clamp fix */
vec2 bordertest = (pos);
if ( bordertest.x > 0.0001 && bordertest.x < 0.9999 && bordertest.y > 0.0001 && bordertest.y < 0.9999)
outColor.rgb = outColor.rgb;
else
outColor.rgb = vec3(0.0);
if (params.shadowMask > 0.0)
outColor.rgb *= Mask(vTexCoord.xy / params.OutputSize.zw * 1.000001);
FragColor = vec4(ToSrgb(outColor.rgb), 1.0);
}

View file

@ -0,0 +1,42 @@
#version 450
layout(push_constant) uniform Push
{
float GLOW_WHITEPOINT;
float GLOW_ROLLOFF;
} param;
#pragma parameter GLOW_WHITEPOINT "Glow Whitepoint" 1.0 0.5 1.1 0.02
#pragma parameter GLOW_ROLLOFF "Glow Rolloff" 0.3 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 = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source;
void main()
{
vec3 color = 1.15 * texture(Source, vTexCoord).rgb;
vec3 factor = clamp(color / param.GLOW_WHITEPOINT, 0.0, 1.0);
FragColor = vec4(factor - vec3(param.GLOW_ROLLOFF), 1.0);
}