delete old, unused and redundant files, update lottes-multipass

This commit is contained in:
hunterk 2018-08-27 13:58:32 -05:00
parent e6ae09b6b1
commit 1035b1b04d
26 changed files with 848 additions and 1936 deletions

View file

@ -0,0 +1,43 @@
shaders = "6"
shader0 = "shaders/crt-easymode-halation/linearize.slang"
filter_linear0 = "true"
srgb_framebuffer0 = "true"
scale_type_x0 = "source"
scale_x0 = "1.000000"
scale_type_y0 = "source"
scale_y0 = "1.000000"
alias0 = ORIG_LINEARIZED
shader1 = "shaders/crt-easymode-halation/blur_horiz.slang"
filter_linear1 = "false"
srgb_framebuffer1 = "true"
scale_type_x1 = "source"
scale_x1 = "1.000000"
scale_type_y1 = "source"
scale_y1 = "1.000000"
shader2 = "shaders/crt-easymode-halation/blur_vert.slang"
filter_linear2 = "false"
srgb_framebuffer2 = "true"
scale_type_x2 = "source"
scale_x2 = "1.000000"
scale_type_y2 = "source"
scale_y2 = "1.000000"
shader3 = "shaders/crt-easymode-halation/threshold.slang"
filter_linear3 = "false"
srgb_framebuffer3 = "true"
scale_type_x3 = "source"
scale_x3 = "1.000000"
scale_type_y3 = "source"
scale_y3 = "1.000000"
alias3 = GlowPass
shader4 = "shaders/crt-lottes-multipass/bloompass.slang"
filter_linear4 = "true"
alias4 = BloomPass
srgb_framebuffer4 = true
shader5 = "shaders/crt-lottes-multipass/scanpass-glow.slang"
filter_linear5 = "true"

View file

@ -1,4 +1,4 @@
shaders = 17 shaders = 10
shader0 = shaders/glow-trails/glow-trails0.slang shader0 = shaders/glow-trails/glow-trails0.slang
filter_linear0 = false filter_linear0 = false
@ -22,77 +22,37 @@ shader3 = shaders/glow-trails/glow-trails1.slang
shader4 = shaders/crt-royale/src/crt-royale-first-pass-linearize-crt-gamma-bob-fields.slang shader4 = shaders/crt-royale/src/crt-royale-first-pass-linearize-crt-gamma-bob-fields.slang
srgb_framebuffer4 = true srgb_framebuffer4 = true
alias4 = "REFERENCE" alias4 = "ORIG_LINEARIZED"
shader5 = "shaders/crt-lottes-multipass/old/threshold.slang" shader5 = "shaders/crt-easymode-halation/blur_horiz.slang"
filter_linear5 = "true"
scale_type5 = "source"
scale5 = "1.0"
srgb_framebuffer5 = "true" srgb_framebuffer5 = "true"
shader6 = "../blurs/blur9fast-vertical.slang" shader6 = "shaders/crt-easymode-halation/blur_vert.slang"
alias6 = "GlowPass"
filter_linear6 = "true" filter_linear6 = "true"
scale_type6 = "source" scale_type6 = "source"
scale6 = "1.0" scale6 = "1.0"
srgb_framebuffer6 = "true" srgb_framebuffer6 = "true"
shader7 = "../blurs/blur9fast-horizontal.slang" shader7 = "shaders/crt-easymode-halation/threshold.slang"
alias7 = "HALATION_BLUR"
filter_linear7 = "true"
scale_type7 = "source"
scale7 = "1.0"
srgb_framebuffer7 = "true" srgb_framebuffer7 = "true"
shader8 = shaders/crt-lottes-multipass/old/horz3minus1.slang shader8 = "shaders/crt-lottes-multipass/bloompass-glow.slang"
srgb_framebuffer8 = true filter_linear8 = "true"
scale_type8 = source alias8 = BloomPass
filter_linear8 = true
alias8 = horz3minus1
shader9 = shaders/crt-lottes-multipass/old/horz3plus1.slang shader9 = "shaders/crt-lottes-multipass/scanpass-glow.slang"
srgb_framebuffer9 = true filter_linear9 = "true"
scale_type9 = source
filter_linear9 = true
alias9 = horz3plus1
shader10 = shaders/crt-lottes-multipass/old/horz5minus2.slang parameters = "mixfactor;threshold;trail_bright;glowFactor;DIFFUSION;maskLight;maskDark;warpX"
srgb_framebuffer10 = true
scale_type10 = source
filter_linear10 = true
alias10 = horz5minus2
shader11 = shaders/crt-lottes-multipass/old/horz5.slang
srgb_framebuffer11 = true
scale_type11 = source
filter_linear11 = true
alias11 = horz5
shader12 = shaders/crt-lottes-multipass/old/horz5plus2.slang
srgb_framebuffer12 = true
scale_type12 = source
filter_linear12 = true
alias12 = horz5plus2
shader13 = shaders/crt-lottes-multipass/old/horz7minus1.slang
srgb_framebuffer13 = true
scale_type13 = source
filter_linear13 = true
alias13 = horz7minus1
shader14 = shaders/crt-lottes-multipass/old/horz7.slang
srgb_framebuffer14 = true
scale_type14 = source
filter_linear14 = true
alias14 = horz7
shader15 = shaders/crt-lottes-multipass/old/horz7plus1.slang
srgb_framebuffer15 = true
scale_type15 = source
filter_linear15 = true
alias15 = horz7plus1
shader16 = shaders/crt-lottes-multipass/old/crt-lottes-multipass-glow.slang
texture_wrap_mode16 = "clamp_to_edge"
parameters = "mixfactor;threshold;trail_bright;glowFactor"
mixfactor = "0.75" mixfactor = "0.75"
threshold = "0.90" threshold = "0.90"
trail_bright = "0.07" trail_bright = "0.07"
glowFactor = "0.10" glowFactor = "0.10"
DIFFUSION = "0.10"
maskLight = 0.9
maskDark = 1.1
warpX = 0.0

View file

@ -1,7 +1,11 @@
shaders = 2 shaders = 3
shader0 = shaders/crt-lottes-multipass/bloompass.slang shader0 = ../stock.slang
alias0 = BloomPass alias0 = Reference
srgb_framebuffer0 = true
shader1 = shaders/crt-lottes-multipass/scanpass.slang shader1 = shaders/crt-lottes-multipass/bloompass.slang
alias1 = BloomPass
filter_linear1 = true
shader2 = shaders/crt-lottes-multipass/scanpass.slang
filter_linear2 = true

View file

@ -0,0 +1,343 @@
#version 450
layout(push_constant) uniform Push
{
float hardScan;
float hardPix;
float warpX;
float warpY;
float maskDark;
float maskLight;
float scaleInLinearGamma;
float shadowMask;
float brightBoost;
float hardBloomScan;
float hardBloomPix;
float bloomAmount;
float shape;
} param;
#pragma parameter hardScan "hardScan" -8.0 -20.0 0.0 1.0
#pragma parameter hardPix "hardPix" -3.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 scaleInLinearGamma "scaleInLinearGamma" 1.0 0.0 1.0 1.0
#pragma parameter shadowMask "shadowMask" 3.0 0.0 4.0 1.0
#pragma parameter brightBoost "brightness boost" 1.0 0.0 2.0 0.05
#pragma parameter hardBloomPix "bloom-x soft" -1.5 -2.0 -0.5 0.1
#pragma parameter hardBloomScan "bloom-y soft" -2.0 -4.0 -1.0 0.1
#pragma parameter bloomAmount "bloom amount" 0.4 0.0 1.0 0.05
#pragma parameter shape "filter kernel shape" 2.0 0.0 10.0 0.05
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;
}
// 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 Source;
layout(set = 0, binding = 3) uniform sampler2D ORIG_LINEARIZED;
//Uncomment to reduce instructions with simpler linearization
//(fixes HD3000 Sandy Bridge IGP)
#define SIMPLE_LINEAR_GAMMA
#define DO_BLOOM 1
// ------------- //
// sRGB to Linear.
// Assuming using sRGB typed textures this should not be needed.
#ifdef SIMPLE_LINEAR_GAMMA
float ToLinear1(float c)
{
return c;
}
vec3 ToLinear(vec3 c)
{
return c;
}
vec3 ToSrgb(vec3 c)
{
return pow(c, vec3(1.0 / 2.2));
}
#else
float ToLinear1(float c)
{
if (param.scaleInLinearGamma == 0)
return c;
return(c<=0.04045) ? c/12.92 : pow((c + 0.055)/1.055, 2.4);
}
vec3 ToLinear(vec3 c)
{
if (param.scaleInLinearGamma==0)
return c;
return vec3(ToLinear1(c.r), ToLinear1(c.g), ToLinear1(c.b));
}
// Linear to sRGB.
// Assuming using sRGB typed textures this should not be needed.
float ToSrgb1(float c)
{
if (param.scaleInLinearGamma == 0)
return c;
return(c<0.0031308 ? c*12.92 : 1.055*pow(c, 0.41666) - 0.055);
}
vec3 ToSrgb(vec3 c)
{
if (param.scaleInLinearGamma == 0)
return c;
return vec3(ToSrgb1(c.r), ToSrgb1(c.g), ToSrgb1(c.b));
}
#endif
// Nearest emulated sample given floating point position and texel offset.
// Also zero's off screen.
vec3 Fetch(vec2 pos,vec2 off){
pos=(floor(pos*global.SourceSize.xy+off)+vec2(0.5,0.5))/global.SourceSize.xy;
#ifdef SIMPLE_LINEAR_GAMMA
return ToLinear(param.brightBoost * (texture(ORIG_LINEARIZED,pos.xy).rgb));
#else
return ToLinear(param.brightBoost * texture(ORIG_LINEARIZED,pos.xy).rgb);
#endif
}
// Distance in emulated pixels to nearest texel.
vec2 Dist(vec2 pos)
{
pos = pos*global.SourceSize.xy;
return -((pos - floor(pos)) - vec2(0.5));
}
// 1D Gaussian.
float Gaus(float pos, float scale)
{
return exp2(scale*pow(abs(pos), param.shape));
}
// 3-tap Gaussian filter along horz line.
vec3 Horz3(vec2 pos, float off)
{
vec3 b = Fetch(pos, vec2(-1.0, off));
vec3 c = Fetch(pos, vec2( 0.0, off));
vec3 d = Fetch(pos, vec2( 1.0, off));
float dst = Dist(pos).x;
// Convert distance to weight.
float scale = param.hardPix;
float wb = Gaus(dst-1.0,scale);
float wc = Gaus(dst+0.0,scale);
float wd = Gaus(dst+1.0,scale);
// Return filtered sample.
return (b*wb+c*wc+d*wd)/(wb+wc+wd);
}
// 5-tap Gaussian filter along horz line.
vec3 Horz5(vec2 pos,float off){
vec3 a = Fetch(pos,vec2(-2.0, off));
vec3 b = Fetch(pos,vec2(-1.0, off));
vec3 c = Fetch(pos,vec2( 0.0, off));
vec3 d = Fetch(pos,vec2( 1.0, off));
vec3 e = Fetch(pos,vec2( 2.0, off));
float dst = Dist(pos).x;
// Convert distance to weight.
float scale = param.hardPix;
float wa = Gaus(dst - 2.0, scale);
float wb = Gaus(dst - 1.0, scale);
float wc = Gaus(dst + 0.0, scale);
float wd = Gaus(dst + 1.0, scale);
float we = Gaus(dst + 2.0, scale);
// Return filtered sample.
return (a*wa+b*wb+c*wc+d*wd+e*we)/(wa+wb+wc+wd+we);
}
// 7-tap Gaussian filter along horz line.
vec3 Horz7(vec2 pos,float off)
{
vec3 a = Fetch(pos, vec2(-3.0, off));
vec3 b = Fetch(pos, vec2(-2.0, off));
vec3 c = Fetch(pos, vec2(-1.0, off));
vec3 d = Fetch(pos, vec2( 0.0, off));
vec3 e = Fetch(pos, vec2( 1.0, off));
vec3 f = Fetch(pos, vec2( 2.0, off));
vec3 g = Fetch(pos, vec2( 3.0, off));
float dst = Dist(pos).x;
// Convert distance to weight.
float scale = param.hardBloomPix;
float wa = Gaus(dst - 3.0, scale);
float wb = Gaus(dst - 2.0, scale);
float wc = Gaus(dst - 1.0, scale);
float wd = Gaus(dst + 0.0, scale);
float we = Gaus(dst + 1.0, scale);
float wf = Gaus(dst + 2.0, scale);
float wg = Gaus(dst + 3.0, scale);
// Return filtered sample.
return (a*wa+b*wb+c*wc+d*wd+e*we+f*wf+g*wg)/(wa+wb+wc+wd+we+wf+wg);
}
// Return scanline weight.
float Scan(vec2 pos, float off)
{
float dst = Dist(pos).y;
return Gaus(dst + off, param.hardScan);
}
// Return scanline weight for bloom.
float BloomScan(vec2 pos, float off)
{
float dst = Dist(pos).y;
return Gaus(dst + off, param.hardBloomScan);
}
// Allow nearest three lines to effect pixel.
vec3 Tri(vec2 pos)
{
vec3 a = Horz3(pos,-1.0);
vec3 b = Horz5(pos, 0.0);
vec3 c = 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 = Horz5(pos,-2.0);
vec3 b = Horz7(pos,-1.0);
vec3 c = Horz7(pos, 0.0);
vec3 d = Horz7(pos, 1.0);
vec3 e = 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)*param.warpX, 1.0 + (pos.x*pos.x)*param.warpY);
return pos*0.5 + 0.5;
}
// Shadow mask.
vec3 Mask(vec2 pos)
{
vec3 mask = vec3(param.maskDark, param.maskDark, param.maskDark);
// Very compressed TV style shadow mask.
if (param.shadowMask == 1.0)
{
float line = param.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 = param.maskDark;
pos.x = fract(pos.x*0.333333333);
if (pos.x < 0.333) mask.r = param.maskLight;
else if (pos.x < 0.666) mask.g = param.maskLight;
else mask.b = param.maskLight;
mask*=line;
}
// Aperture-grille.
else if (param.shadowMask == 2.0)
{
pos.x = fract(pos.x*0.333333333);
if (pos.x < 0.333) mask.r = param.maskLight;
else if (pos.x < 0.666) mask.g = param.maskLight;
else mask.b = param.maskLight;
}
// Stretched VGA style shadow mask (same as prior shaders).
else if (param.shadowMask == 3.0)
{
pos.x += pos.y*3.0;
pos.x = fract(pos.x*0.166666666);
if (pos.x < 0.333) mask.r = param.maskLight;
else if (pos.x < 0.666) mask.g = param.maskLight;
else mask.b = param.maskLight;
}
// VGA style shadow mask.
else if (param.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 = param.maskLight;
else if (pos.x < 0.666) mask.g = param.maskLight;
else mask.b = param.maskLight;
}
return mask;
}
void main()
{
vec2 pos = vTexCoord;
FragColor = vec4(Bloom(pos)*param.bloomAmount, 1.0);
}

View file

@ -15,7 +15,7 @@ layout(push_constant) uniform Push
float hardBloomPix; float hardBloomPix;
float bloomAmount; float bloomAmount;
float shape; float shape;
} params; } param;
#pragma parameter hardScan "hardScan" -8.0 -20.0 0.0 1.0 #pragma parameter hardScan "hardScan" -8.0 -20.0 0.0 1.0
#pragma parameter hardPix "hardPix" -3.0 -20.0 0.0 1.0 #pragma parameter hardPix "hardPix" -3.0 -20.0 0.0 1.0
@ -68,7 +68,6 @@ layout(location = 0) in vec2 vTexCoord;
layout(location = 1) in vec2 FragCoord; layout(location = 1) in vec2 FragCoord;
layout(location = 0) out vec4 FragColor; layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source; layout(set = 0, binding = 2) uniform sampler2D Source;
layout(set = 0, binding = 3) uniform sampler2D Original;
//Uncomment to reduce instructions with simpler linearization //Uncomment to reduce instructions with simpler linearization
//(fixes HD3000 Sandy Bridge IGP) //(fixes HD3000 Sandy Bridge IGP)
@ -95,7 +94,7 @@ vec3 ToSrgb(vec3 c)
#else #else
float ToLinear1(float c) float ToLinear1(float c)
{ {
if (params.scaleInLinearGamma == 0) if (param.scaleInLinearGamma == 0)
return c; return c;
return(c<=0.04045) ? c/12.92 : pow((c + 0.055)/1.055, 2.4); return(c<=0.04045) ? c/12.92 : pow((c + 0.055)/1.055, 2.4);
@ -103,7 +102,7 @@ float ToLinear1(float c)
vec3 ToLinear(vec3 c) vec3 ToLinear(vec3 c)
{ {
if (params.scaleInLinearGamma==0) if (param.scaleInLinearGamma==0)
return c; return c;
return vec3(ToLinear1(c.r), ToLinear1(c.g), ToLinear1(c.b)); return vec3(ToLinear1(c.r), ToLinear1(c.g), ToLinear1(c.b));
@ -113,7 +112,7 @@ vec3 ToLinear(vec3 c)
// Assuming using sRGB typed textures this should not be needed. // Assuming using sRGB typed textures this should not be needed.
float ToSrgb1(float c) float ToSrgb1(float c)
{ {
if (params.scaleInLinearGamma == 0) if (param.scaleInLinearGamma == 0)
return c; return c;
return(c<0.0031308 ? c*12.92 : 1.055*pow(c, 0.41666) - 0.055); return(c<0.0031308 ? c*12.92 : 1.055*pow(c, 0.41666) - 0.055);
@ -121,7 +120,7 @@ float ToSrgb1(float c)
vec3 ToSrgb(vec3 c) vec3 ToSrgb(vec3 c)
{ {
if (params.scaleInLinearGamma == 0) if (param.scaleInLinearGamma == 0)
return c; return c;
return vec3(ToSrgb1(c.r), ToSrgb1(c.g), ToSrgb1(c.b)); return vec3(ToSrgb1(c.r), ToSrgb1(c.g), ToSrgb1(c.b));
@ -135,9 +134,9 @@ vec3 ToSrgb(vec3 c)
vec3 Fetch(vec2 pos,vec2 off){ vec3 Fetch(vec2 pos,vec2 off){
pos=(floor(pos*global.SourceSize.xy+off)+vec2(0.5,0.5))/global.SourceSize.xy; pos=(floor(pos*global.SourceSize.xy+off)+vec2(0.5,0.5))/global.SourceSize.xy;
#ifdef SIMPLE_LINEAR_GAMMA #ifdef SIMPLE_LINEAR_GAMMA
return ToLinear(params.brightBoost * pow(texture(Original,pos.xy).rgb, vec3(2.2))); return ToLinear(pow(texture(Source,pos.xy).rgb, vec3(2.2)));
#else #else
return ToLinear(params.brightBoost * texture(Original,pos.xy).rgb); return ToLinear(texture(Source,pos.xy).rgb);
#endif #endif
} }
@ -152,7 +151,7 @@ vec2 Dist(vec2 pos)
// 1D Gaussian. // 1D Gaussian.
float Gaus(float pos, float scale) float Gaus(float pos, float scale)
{ {
return exp2(scale*pow(abs(pos), params.shape)); return exp2(scale*pow(abs(pos), param.shape));
} }
// 3-tap Gaussian filter along horz line. // 3-tap Gaussian filter along horz line.
@ -164,7 +163,7 @@ vec3 Horz3(vec2 pos, float off)
float dst = Dist(pos).x; float dst = Dist(pos).x;
// Convert distance to weight. // Convert distance to weight.
float scale = params.hardPix; float scale = param.hardPix;
float wb = Gaus(dst-1.0,scale); float wb = Gaus(dst-1.0,scale);
float wc = Gaus(dst+0.0,scale); float wc = Gaus(dst+0.0,scale);
float wd = Gaus(dst+1.0,scale); float wd = Gaus(dst+1.0,scale);
@ -183,7 +182,7 @@ vec3 Horz5(vec2 pos,float off){
float dst = Dist(pos).x; float dst = Dist(pos).x;
// Convert distance to weight. // Convert distance to weight.
float scale = params.hardPix; float scale = param.hardPix;
float wa = Gaus(dst - 2.0, scale); float wa = Gaus(dst - 2.0, scale);
float wb = Gaus(dst - 1.0, scale); float wb = Gaus(dst - 1.0, scale);
float wc = Gaus(dst + 0.0, scale); float wc = Gaus(dst + 0.0, scale);
@ -207,7 +206,7 @@ vec3 Horz7(vec2 pos,float off)
float dst = Dist(pos).x; float dst = Dist(pos).x;
// Convert distance to weight. // Convert distance to weight.
float scale = params.hardBloomPix; float scale = param.hardBloomPix;
float wa = Gaus(dst - 3.0, scale); float wa = Gaus(dst - 3.0, scale);
float wb = Gaus(dst - 2.0, scale); float wb = Gaus(dst - 2.0, scale);
float wc = Gaus(dst - 1.0, scale); float wc = Gaus(dst - 1.0, scale);
@ -225,7 +224,7 @@ float Scan(vec2 pos, float off)
{ {
float dst = Dist(pos).y; float dst = Dist(pos).y;
return Gaus(dst + off, params.hardScan); return Gaus(dst + off, param.hardScan);
} }
// Return scanline weight for bloom. // Return scanline weight for bloom.
@ -233,7 +232,7 @@ float BloomScan(vec2 pos, float off)
{ {
float dst = Dist(pos).y; float dst = Dist(pos).y;
return Gaus(dst + off, params.hardBloomScan); return Gaus(dst + off, param.hardBloomScan);
} }
// Allow nearest three lines to effect pixel. // Allow nearest three lines to effect pixel.
@ -272,7 +271,7 @@ vec3 Bloom(vec2 pos)
vec2 Warp(vec2 pos) vec2 Warp(vec2 pos)
{ {
pos = pos*2.0-1.0; pos = pos*2.0-1.0;
pos *= vec2(1.0 + (pos.y*pos.y)*params.warpX, 1.0 + (pos.x*pos.x)*params.warpY); pos *= vec2(1.0 + (pos.y*pos.y)*param.warpX, 1.0 + (pos.x*pos.x)*param.warpY);
return pos*0.5 + 0.5; return pos*0.5 + 0.5;
} }
@ -280,56 +279,56 @@ vec2 Warp(vec2 pos)
// Shadow mask. // Shadow mask.
vec3 Mask(vec2 pos) vec3 Mask(vec2 pos)
{ {
vec3 mask = vec3(params.maskDark, params.maskDark, params.maskDark); vec3 mask = vec3(param.maskDark, param.maskDark, param.maskDark);
// Very compressed TV style shadow mask. // Very compressed TV style shadow mask.
if (params.shadowMask == 1.0) if (param.shadowMask == 1.0)
{ {
float line = params.maskLight; float line = param.maskLight;
float odd = 0.0; float odd = 0.0;
if (fract(pos.x*0.166666666) < 0.5) odd = 1.0; if (fract(pos.x*0.166666666) < 0.5) odd = 1.0;
if (fract((pos.y + odd) * 0.5) < 0.5) line = params.maskDark; if (fract((pos.y + odd) * 0.5) < 0.5) line = param.maskDark;
pos.x = fract(pos.x*0.333333333); pos.x = fract(pos.x*0.333333333);
if (pos.x < 0.333) mask.r = params.maskLight; if (pos.x < 0.333) mask.r = param.maskLight;
else if (pos.x < 0.666) mask.g = params.maskLight; else if (pos.x < 0.666) mask.g = param.maskLight;
else mask.b = params.maskLight; else mask.b = param.maskLight;
mask*=line; mask*=line;
} }
// Aperture-grille. // Aperture-grille.
else if (params.shadowMask == 2.0) else if (param.shadowMask == 2.0)
{ {
pos.x = fract(pos.x*0.333333333); pos.x = fract(pos.x*0.333333333);
if (pos.x < 0.333) mask.r = params.maskLight; if (pos.x < 0.333) mask.r = param.maskLight;
else if (pos.x < 0.666) mask.g = params.maskLight; else if (pos.x < 0.666) mask.g = param.maskLight;
else mask.b = params.maskLight; else mask.b = param.maskLight;
} }
// Stretched VGA style shadow mask (same as prior shaders). // Stretched VGA style shadow mask (same as prior shaders).
else if (params.shadowMask == 3.0) else if (param.shadowMask == 3.0)
{ {
pos.x += pos.y*3.0; pos.x += pos.y*3.0;
pos.x = fract(pos.x*0.166666666); pos.x = fract(pos.x*0.166666666);
if (pos.x < 0.333) mask.r = params.maskLight; if (pos.x < 0.333) mask.r = param.maskLight;
else if (pos.x < 0.666) mask.g = params.maskLight; else if (pos.x < 0.666) mask.g = param.maskLight;
else mask.b = params.maskLight; else mask.b = param.maskLight;
} }
// VGA style shadow mask. // VGA style shadow mask.
else if (params.shadowMask == 4.0) else if (param.shadowMask == 4.0)
{ {
pos.xy = floor(pos.xy*vec2(1.0, 0.5)); pos.xy = floor(pos.xy*vec2(1.0, 0.5));
pos.x += pos.y*3.0; pos.x += pos.y*3.0;
pos.x = fract(pos.x*0.166666666); pos.x = fract(pos.x*0.166666666);
if (pos.x < 0.333) mask.r = params.maskLight; if (pos.x < 0.333) mask.r = param.maskLight;
else if (pos.x < 0.666) mask.g = params.maskLight; else if (pos.x < 0.666) mask.g = param.maskLight;
else mask.b = params.maskLight; else mask.b = param.maskLight;
} }
return mask; return mask;
@ -339,5 +338,5 @@ void main()
{ {
vec2 pos = vTexCoord; vec2 pos = vTexCoord;
FragColor = vec4(Bloom(pos)*params.bloomAmount, 1.0); FragColor = vec4(Bloom(pos)*param.bloomAmount, 1.0);
} }

View file

@ -1,66 +0,0 @@
#version 450
layout(push_constant) uniform Push
{
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
float mixfactor;
float threshold;
} params;
#pragma parameter mixfactor "Motionblur Fadeout" 0.5 0.0 1.0 0.01
#pragma parameter threshold "Brightness Threshold" 0.9 0.0 1.0 0.01
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
} global;
float key(float avg)
{
float guess = 1.5 - (1.5 / (avg * 0.1 + 1.0));
return max(0.0, guess) + 0.1;
}
mat3 yiq2rgb_mat = mat3(
1.0, 1.0, 1.0,
0.956, -0.2720, -1.1060,
0.6210, -0.6474, 1.7046
);
mat3 yiq_mat = mat3(
0.2989, 0.5959, 0.2115,
0.5870, -0.2744, -0.5229,
0.1140, -0.3216, 0.3114
);
#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 PassFeedback0;
void main()
{
vec3 frame = texture(Source, vTexCoord).rgb;
float luma = (frame.rrr * yiq_mat).r;
float trails = clamp(luma - params.threshold, 0.0, 1.0);
vec4 fdback = pow(texture(PassFeedback0, vTexCoord), vec4(2.2));
vec4 mixed = clamp((1.0 - params.mixfactor) * vec4(trails) - params.mixfactor * fdback, 0.0, 1.0) + params.mixfactor * fdback;
// vec4 current = pow(texture(Source, vTexCoord), vec4(2.2));
FragColor = pow(mixed, vec4(1.0 / 2.2));
}

View file

@ -1,47 +0,0 @@
#version 450
layout(push_constant) uniform Push
{
vec4 SourceSize;
vec4 OriginalSize;
vec4 OutputSize;
uint FrameCount;
float trail_bright;
} params;
#pragma parameter trail_bright "Phos. Trail Brightness" 0.25 0.0 1.0 0.01
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
} global;
mat3 yiq_mat = mat3(
0.2989, 0.5959, 0.2115,
0.5870, -0.2744, -0.5229,
0.1140, -0.3216, 0.3114
);
#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 Original;
void main()
{
vec4 trails = texture(Source, vTexCoord).rgba;
vec4 current = pow(texture(Original, vTexCoord).rgba, vec4(2.2));
FragColor = vec4(pow(current + vec4(clamp(trails.r - current.r, 0.0, 1.0) * params.trail_bright), vec4(1.0 / 2.2)));
}

View file

@ -1,225 +0,0 @@
#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;
} 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" 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;
} 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 horz3;
layout(set = 0, binding = 3) uniform sampler2D horz5;
layout(set = 0, binding = 4) uniform sampler2D horz7;
// 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 = textureOffset(horz3, pos, ivec2(1, 0)).rgb;//Horz3(pos,-1.0);
vec3 b = texture(horz5, pos).rgb;//Horz5(pos, 0.0);
vec3 c = textureOffset(horz3, pos, ivec2(-1, 0)).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 = textureOffset(horz5, pos, ivec2(-2, 0)).rgb;//Horz5(pos,-2.0);
vec3 b = textureOffset(horz7, pos, ivec2(-1, 0)).rgb;//Horz7(pos,-1.0);
vec3 c = texture(horz7, pos).rgb;//Horz7(pos, 0.0);
vec3 d = textureOffset(horz7, pos, ivec2(1, 0)).rgb;//Horz7(pos, 1.0);
vec3 e = textureOffset(horz5, pos, ivec2(2, 0)).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);
if (params.shadowMask > 0.0)
outColor.rgb *= Mask(vTexCoord.xy / params.OutputSize.zw * 1.000001);
#ifdef DO_BLOOM
//Add Bloom
outColor.rgb += Bloom(pos)*params.bloomAmount;
#endif
FragColor = vec4(ToSrgb(outColor.rgb), 1.0);
}

View file

@ -1,25 +0,0 @@
shaders = 5
shader0 = linearize.slang
srgb_framebuffer0 = true
alias0 = "REFERENCE"
shader1 = horz3.slang
srgb_framebuffer1 = true
scale_type1 = source
filter_linear1 = true
alias1 = horz3
shader2 = horz5.slang
srgb_framebuffer2 = true
scale_type2 = source
filter_linear2 = true
alias2 = horz5
shader3 = horz7.slang
srgb_framebuffer3 = true
scale_type3 = source
filter_linear3 = true
alias3 = horz7
shader4 = crt-lottes-multipass.slang

View file

@ -1,241 +0,0 @@
#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;
float gamma;
float ntsc;
} 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.15 0.0 1.0 0.01
#pragma parameter gamma "Gamma Adjustment" 1.5 0.0 5.0 0.05
#pragma parameter ntsc "NTSC Colors" 0.0 0.0 1.0 1.0
#define DO_BLOOM
#include "../../../../misc/colorspace-tools.h"
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, texture(HALATION_BLUR, pos.xy).rgb, params.glowFactor);
if (params.ntsc > 0.0)
FragColor = vec4(NTSCtoSRGB(pow(ToSrgb(outColor.rgb), vec3(1.0 / params.gamma))), 1.0);
else
FragColor = vec4(pow(ToSrgb(outColor.rgb), vec3(1.0 / params.gamma)), 1.0);
}

View file

@ -1,55 +0,0 @@
shaders = 10
shader0 = linearize.slang
srgb_framebuffer0 = true
alias0 = "REFERENCE"
shader1 = horz3minus1.slang
srgb_framebuffer1 = true
scale_type1 = source
filter_linear1 = true
alias1 = horz3minus1
shader2 = horz3plus1.slang
srgb_framebuffer2 = true
scale_type2 = source
filter_linear2 = true
alias2 = horz3plus1
shader3 = horz5minus2.slang
srgb_framebuffer3 = true
scale_type3 = source
filter_linear3 = true
alias3 = horz5minus2
shader4 = horz5.slang
srgb_framebuffer4 = true
scale_type4 = source
filter_linear4 = true
alias4 = horz5
shader5 = horz5plus2.slang
srgb_framebuffer5 = true
scale_type5 = source
filter_linear5 = true
alias5 = horz5plus2
shader6 = horz7minus1.slang
srgb_framebuffer6 = true
scale_type6 = source
filter_linear6 = true
alias6 = horz7minus1
shader7 = horz7.slang
srgb_framebuffer7 = true
scale_type7 = source
filter_linear7 = true
alias7 = horz7
shader8 = horz7plus1.slang
srgb_framebuffer8 = true
scale_type8 = source
filter_linear8 = true
alias8 = horz7plus1
shader9 = crt-lottes-multipass.slang

View file

@ -1,228 +0,0 @@
#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;
} 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" 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;
} 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;
// 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);
FragColor = vec4(ToSrgb(outColor.rgb), 1.0);
}

View file

@ -1,77 +0,0 @@
#version 450
#define hardPix -3.0
#define brightboost 1
#define shape 2.0
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 REFERENCESize;
} 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;
// vTexCoord = floor(global.REFERENCESize.xy * TexCoord);
// vTexCoord = (vTexCoord + 0.5) * global.REFERENCESize.zw;
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D REFERENCE;
// Nearest emulated sample given floating point position and texel offset.
// Also zero's off screen.
vec3 Fetch(vec2 pos, vec2 off)
{
pos = vTexCoord;//(floor(pos*global.REFERENCESize.xy+off)+vec2(0.5,0.5)) * global.REFERENCESize.zw;
return brightboost * texture(REFERENCE, pos.xy).rgb;
}
// Distance in emulated pixels to nearest texel.
vec2 Dist(vec2 pos)
{
pos = pos*global.REFERENCESize.xy;
return -((pos - floor(pos)) - vec2(0.5));
}
// 1D Gaussian.
float Gaus(float pos, float scale)
{
return exp2(scale*pow(abs(pos), shape));
}
// 3-tap Gaussian filter along horz line.
vec3 Horz3(vec2 pos, float off)
{
vec3 b = Fetch(pos,vec2(-1.0, off));
vec3 c = Fetch(pos,vec2( 0.0, off));
vec3 d = Fetch(pos,vec2( 1.0, off));
float dst = Dist(pos).x;
// Convert distance to weight.
float scale = hardPix;
float wb = Gaus(dst - 1.0, scale);
float wc = Gaus(dst + 0.0, scale);
float wd = Gaus(dst + 1.0, scale);
// Return filtered sample.
return (b*wb+c*wc+d*wd) / (wb+wc+wd);
}
void main()
{
FragColor = vec4(Horz3(vTexCoord, 0.0).rgb, 1.0);
}

View file

@ -1,77 +0,0 @@
#version 450
#define hardPix -3.0
#define brightboost 1
#define shape 2.0
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 REFERENCESize;
} 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;
// vTexCoord = floor(global.REFERENCESize.xy * TexCoord);
// vTexCoord = (vTexCoord + 0.5) * global.REFERENCESize.zw;
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D REFERENCE;
// Nearest emulated sample given floating point position and texel offset.
// Also zero's off screen.
vec3 Fetch(vec2 pos, vec2 off)
{
pos = vTexCoord;//(floor(pos*global.REFERENCESize.xy+off)+vec2(0.5,0.5)) * global.REFERENCESize.zw;
return brightboost * texture(REFERENCE, pos.xy).rgb;
}
// Distance in emulated pixels to nearest texel.
vec2 Dist(vec2 pos)
{
pos = pos*global.REFERENCESize.xy;
return -((pos - floor(pos)) - vec2(0.5));
}
// 1D Gaussian.
float Gaus(float pos, float scale)
{
return exp2(scale*pow(abs(pos), shape));
}
// 3-tap Gaussian filter along horz line.
vec3 Horz3(vec2 pos, float off)
{
vec3 b = Fetch(pos,vec2(-1.0, off));
vec3 c = Fetch(pos,vec2( 0.0, off));
vec3 d = Fetch(pos,vec2( 1.0, off));
float dst = Dist(pos).x;
// Convert distance to weight.
float scale = hardPix;
float wb = Gaus(dst - 1.0, scale);
float wc = Gaus(dst + 0.0, scale);
float wd = Gaus(dst + 1.0, scale);
// Return filtered sample.
return (b*wb+c*wc+d*wd) / (wb+wc+wd);
}
void main()
{
FragColor = vec4(Horz3(vTexCoord, -1.0).rgb, 1.0);
}

View file

@ -1,77 +0,0 @@
#version 450
#define hardPix -3.0
#define brightboost 1
#define shape 2.0
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 REFERENCESize;
} 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;
// vTexCoord = floor(global.REFERENCESize.xy * TexCoord);
// vTexCoord = (vTexCoord + 0.5) * global.REFERENCESize.zw;
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D REFERENCE;
// Nearest emulated sample given floating point position and texel offset.
// Also zero's off screen.
vec3 Fetch(vec2 pos, vec2 off)
{
pos = vTexCoord;//(floor(pos*global.REFERENCESize.xy+off)+vec2(0.5,0.5)) * global.REFERENCESize.zw;
return brightboost * texture(REFERENCE, pos.xy).rgb;
}
// Distance in emulated pixels to nearest texel.
vec2 Dist(vec2 pos)
{
pos = pos*global.REFERENCESize.xy;
return -((pos - floor(pos)) - vec2(0.5));
}
// 1D Gaussian.
float Gaus(float pos, float scale)
{
return exp2(scale*pow(abs(pos), shape));
}
// 3-tap Gaussian filter along horz line.
vec3 Horz3(vec2 pos, float off)
{
vec3 b = Fetch(pos,vec2(-1.0, off));
vec3 c = Fetch(pos,vec2( 0.0, off));
vec3 d = Fetch(pos,vec2( 1.0, off));
float dst = Dist(pos).x;
// Convert distance to weight.
float scale = hardPix;
float wb = Gaus(dst - 1.0, scale);
float wc = Gaus(dst + 0.0, scale);
float wd = Gaus(dst + 1.0, scale);
// Return filtered sample.
return (b*wb+c*wc+d*wd) / (wb+wc+wd);
}
void main()
{
FragColor = vec4(Horz3(vTexCoord, 1.0).rgb, 1.0);
}

View file

@ -1,81 +0,0 @@
#version 450
#define hardPix -3.0
#define brightboost 1
#define shape 2.0
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 REFERENCESize;
} 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;
// vTexCoord = floor(global.REFERENCESize.xy * TexCoord);
// vTexCoord = (vTexCoord + 0.5) * global.REFERENCESize.zw;
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D REFERENCE;
// Nearest emulated sample given floating point position and texel offset.
// Also zero's off screen.
vec3 Fetch(vec2 pos, vec2 off)
{
pos = vTexCoord;//(floor(pos*global.REFERENCESize.xy+off)+vec2(0.5,0.5)) * global.REFERENCESize.zw;
return brightboost * texture(REFERENCE, pos.xy).rgb;
}
// Distance in emulated pixels to nearest texel.
vec2 Dist(vec2 pos)
{
pos = pos*global.REFERENCESize.xy;
return -((pos - floor(pos)) - vec2(0.5));
}
// 1D Gaussian.
float Gaus(float pos, float scale)
{
return exp2(scale*pow(abs(pos), shape));
}
// 5-tap Gaussian filter along horz line.
vec3 Horz5(vec2 pos,float off)
{
vec3 a = Fetch(pos,vec2(-2.0, off));
vec3 b = Fetch(pos,vec2(-1.0, off));
vec3 c = Fetch(pos,vec2( 0.0, off));
vec3 d = Fetch(pos,vec2( 1.0, off));
vec3 e = Fetch(pos,vec2( 2.0, off));
float dst = Dist(pos).x;
// Convert distance to weight.
float scale = hardPix;
float wa = Gaus(dst - 2.0, scale);
float wb = Gaus(dst - 1.0, scale);
float wc = Gaus(dst + 0.0, scale);
float wd = Gaus(dst + 1.0, scale);
float we = Gaus(dst + 2.0, scale);
// Return filtered sample.
return (a*wa+b*wb+c*wc+d*wd+e*we)/(wa+wb+wc+wd+we);
}
void main()
{
FragColor = vec4(Horz5(vTexCoord, 0.0).rgb, 1.0);
}

View file

@ -1,81 +0,0 @@
#version 450
#define hardPix -3.0
#define brightboost 1
#define shape 2.0
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 REFERENCESize;
} 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;
// vTexCoord = floor(global.REFERENCESize.xy * TexCoord);
// vTexCoord = (vTexCoord + 0.5) * global.REFERENCESize.zw;
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D REFERENCE;
// Nearest emulated sample given floating point position and texel offset.
// Also zero's off screen.
vec3 Fetch(vec2 pos, vec2 off)
{
pos = vTexCoord;//(floor(pos*global.REFERENCESize.xy+off)+vec2(0.5,0.5)) * global.REFERENCESize.zw;
return brightboost * texture(REFERENCE, pos.xy).rgb;
}
// Distance in emulated pixels to nearest texel.
vec2 Dist(vec2 pos)
{
pos = pos*global.REFERENCESize.xy;
return -((pos - floor(pos)) - vec2(0.5));
}
// 1D Gaussian.
float Gaus(float pos, float scale)
{
return exp2(scale*pow(abs(pos), shape));
}
// 5-tap Gaussian filter along horz line.
vec3 Horz5(vec2 pos,float off)
{
vec3 a = Fetch(pos,vec2(-2.0, off));
vec3 b = Fetch(pos,vec2(-1.0, off));
vec3 c = Fetch(pos,vec2( 0.0, off));
vec3 d = Fetch(pos,vec2( 1.0, off));
vec3 e = Fetch(pos,vec2( 2.0, off));
float dst = Dist(pos).x;
// Convert distance to weight.
float scale = hardPix;
float wa = Gaus(dst - 2.0, scale);
float wb = Gaus(dst - 1.0, scale);
float wc = Gaus(dst + 0.0, scale);
float wd = Gaus(dst + 1.0, scale);
float we = Gaus(dst + 2.0, scale);
// Return filtered sample.
return (a*wa+b*wb+c*wc+d*wd+e*we)/(wa+wb+wc+wd+we);
}
void main()
{
FragColor = vec4(Horz5(vTexCoord, -2.0).rgb, 1.0);
}

View file

@ -1,81 +0,0 @@
#version 450
#define hardPix -3.0
#define brightboost 1
#define shape 2.0
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 REFERENCESize;
} 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;
// vTexCoord = floor(global.REFERENCESize.xy * TexCoord);
// vTexCoord = (vTexCoord + 0.5) * global.REFERENCESize.zw;
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D REFERENCE;
// Nearest emulated sample given floating point position and texel offset.
// Also zero's off screen.
vec3 Fetch(vec2 pos, vec2 off)
{
pos = vTexCoord;//(floor(pos*global.REFERENCESize.xy+off)+vec2(0.5,0.5)) * global.REFERENCESize.zw;
return brightboost * texture(REFERENCE, pos.xy).rgb;
}
// Distance in emulated pixels to nearest texel.
vec2 Dist(vec2 pos)
{
pos = pos*global.REFERENCESize.xy;
return -((pos - floor(pos)) - vec2(0.5));
}
// 1D Gaussian.
float Gaus(float pos, float scale)
{
return exp2(scale*pow(abs(pos), shape));
}
// 5-tap Gaussian filter along horz line.
vec3 Horz5(vec2 pos,float off)
{
vec3 a = Fetch(pos,vec2(-2.0, off));
vec3 b = Fetch(pos,vec2(-1.0, off));
vec3 c = Fetch(pos,vec2( 0.0, off));
vec3 d = Fetch(pos,vec2( 1.0, off));
vec3 e = Fetch(pos,vec2( 2.0, off));
float dst = Dist(pos).x;
// Convert distance to weight.
float scale = hardPix;
float wa = Gaus(dst - 2.0, scale);
float wb = Gaus(dst - 1.0, scale);
float wc = Gaus(dst + 0.0, scale);
float wd = Gaus(dst + 1.0, scale);
float we = Gaus(dst + 2.0, scale);
// Return filtered sample.
return (a*wa+b*wb+c*wc+d*wd+e*we)/(wa+wb+wc+wd+we);
}
void main()
{
FragColor = vec4(Horz5(vTexCoord, 2.0).rgb, 1.0);
}

View file

@ -1,85 +0,0 @@
#version 450
#define brightboost 1
#define shape 2.0
#define hardBloomPix -1.5
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 REFERENCESize;
} 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;
// vTexCoord = floor(global.REFERENCESize.xy * TexCoord);
// vTexCoord = (vTexCoord + 0.5) * global.REFERENCESize.zw;
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D REFERENCE;
// Nearest emulated sample given floating point position and texel offset.
// Also zero's off screen.
vec3 Fetch(vec2 pos, vec2 off)
{
pos = vTexCoord;//(floor(pos*global.REFERENCESize.xy+off)+vec2(0.5,0.5)) * global.REFERENCESize.zw;
return brightboost * texture(REFERENCE, pos.xy).rgb;
}
// Distance in emulated pixels to nearest texel.
vec2 Dist(vec2 pos)
{
pos = pos*global.REFERENCESize.xy;
return -((pos - floor(pos)) - vec2(0.5));
}
// 1D Gaussian.
float Gaus(float pos, float scale)
{
return exp2(scale*pow(abs(pos), shape));
}
// 7-tap Gaussian filter along horz line.
vec3 Horz7(vec2 pos, float off)
{
vec3 a = Fetch(pos, vec2(-3.0, off));
vec3 b = Fetch(pos, vec2(-2.0, off));
vec3 c = Fetch(pos, vec2(-1.0, off));
vec3 d = Fetch(pos, vec2( 0.0, off));
vec3 e = Fetch(pos, vec2( 1.0, off));
vec3 f = Fetch(pos, vec2( 2.0, off));
vec3 g = Fetch(pos, vec2( 3.0, off));
float dst = Dist(pos).x;
// Convert distance to weight.
float scale = hardBloomPix;
float wa = Gaus(dst - 3.0, scale);
float wb = Gaus(dst - 2.0, scale);
float wc = Gaus(dst - 1.0, scale);
float wd = Gaus(dst + 0.0, scale);
float we = Gaus(dst + 1.0, scale);
float wf = Gaus(dst + 2.0, scale);
float wg = Gaus(dst + 3.0, scale);
// Return filtered sample.
return (a*wa+b*wb+c*wc+d*wd+e*we+f*wf+g*wg)/(wa+wb+wc+wd+we+wf+wg);
}
void main()
{
FragColor = vec4(Horz7(vTexCoord, 0.0).rgb, 1.0);
}

View file

@ -1,85 +0,0 @@
#version 450
#define brightboost 1
#define shape 2.0
#define hardBloomPix -1.5
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 REFERENCESize;
} 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;
// vTexCoord = floor(global.REFERENCESize.xy * TexCoord);
// vTexCoord = (vTexCoord + 0.5) * global.REFERENCESize.zw;
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D REFERENCE;
// Nearest emulated sample given floating point position and texel offset.
// Also zero's off screen.
vec3 Fetch(vec2 pos, vec2 off)
{
pos = vTexCoord;//(floor(pos*global.REFERENCESize.xy+off)+vec2(0.5,0.5)) * global.REFERENCESize.zw;
return brightboost * texture(REFERENCE, pos.xy).rgb;
}
// Distance in emulated pixels to nearest texel.
vec2 Dist(vec2 pos)
{
pos = pos*global.REFERENCESize.xy;
return -((pos - floor(pos)) - vec2(0.5));
}
// 1D Gaussian.
float Gaus(float pos, float scale)
{
return exp2(scale*pow(abs(pos), shape));
}
// 7-tap Gaussian filter along horz line.
vec3 Horz7(vec2 pos, float off)
{
vec3 a = Fetch(pos, vec2(-3.0, off));
vec3 b = Fetch(pos, vec2(-2.0, off));
vec3 c = Fetch(pos, vec2(-1.0, off));
vec3 d = Fetch(pos, vec2( 0.0, off));
vec3 e = Fetch(pos, vec2( 1.0, off));
vec3 f = Fetch(pos, vec2( 2.0, off));
vec3 g = Fetch(pos, vec2( 3.0, off));
float dst = Dist(pos).x;
// Convert distance to weight.
float scale = hardBloomPix;
float wa = Gaus(dst - 3.0, scale);
float wb = Gaus(dst - 2.0, scale);
float wc = Gaus(dst - 1.0, scale);
float wd = Gaus(dst + 0.0, scale);
float we = Gaus(dst + 1.0, scale);
float wf = Gaus(dst + 2.0, scale);
float wg = Gaus(dst + 3.0, scale);
// Return filtered sample.
return (a*wa+b*wb+c*wc+d*wd+e*we+f*wf+g*wg)/(wa+wb+wc+wd+we+wf+wg);
}
void main()
{
FragColor = vec4(Horz7(vTexCoord, -1.0).rgb, 1.0);
}

View file

@ -1,85 +0,0 @@
#version 450
#define brightboost 1
#define shape 2.0
#define hardBloomPix -1.5
layout(std140, set = 0, binding = 0) uniform UBO
{
mat4 MVP;
vec4 OutputSize;
vec4 OriginalSize;
vec4 REFERENCESize;
} 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;
// vTexCoord = floor(global.REFERENCESize.xy * TexCoord);
// vTexCoord = (vTexCoord + 0.5) * global.REFERENCESize.zw;
}
#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D REFERENCE;
// Nearest emulated sample given floating point position and texel offset.
// Also zero's off screen.
vec3 Fetch(vec2 pos, vec2 off)
{
pos = vTexCoord;//(floor(pos*global.REFERENCESize.xy+off)+vec2(0.5,0.5)) * global.REFERENCESize.zw;
return brightboost * texture(REFERENCE, pos.xy).rgb;
}
// Distance in emulated pixels to nearest texel.
vec2 Dist(vec2 pos)
{
pos = pos*global.REFERENCESize.xy;
return -((pos - floor(pos)) - vec2(0.5));
}
// 1D Gaussian.
float Gaus(float pos, float scale)
{
return exp2(scale*pow(abs(pos), shape));
}
// 7-tap Gaussian filter along horz line.
vec3 Horz7(vec2 pos, float off)
{
vec3 a = Fetch(pos, vec2(-3.0, off));
vec3 b = Fetch(pos, vec2(-2.0, off));
vec3 c = Fetch(pos, vec2(-1.0, off));
vec3 d = Fetch(pos, vec2( 0.0, off));
vec3 e = Fetch(pos, vec2( 1.0, off));
vec3 f = Fetch(pos, vec2( 2.0, off));
vec3 g = Fetch(pos, vec2( 3.0, off));
float dst = Dist(pos).x;
// Convert distance to weight.
float scale = hardBloomPix;
float wa = Gaus(dst - 3.0, scale);
float wb = Gaus(dst - 2.0, scale);
float wc = Gaus(dst - 1.0, scale);
float wd = Gaus(dst + 0.0, scale);
float we = Gaus(dst + 1.0, scale);
float wf = Gaus(dst + 2.0, scale);
float wg = Gaus(dst + 3.0, scale);
// Return filtered sample.
return (a*wa+b*wb+c*wc+d*wd+e*we+f*wf+g*wg)/(wa+wb+wc+wd+we+wf+wg);
}
void main()
{
FragColor = vec4(Horz7(vTexCoord, 1.0).rgb, 1.0);
}

View file

@ -1,32 +0,0 @@
#version 450
#define GAMMA 2.2
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()
{
FragColor = vec4(pow(texture(Source, vTexCoord).rgb, vec3(GAMMA)), 1.0);
}

View file

@ -1,42 +0,0 @@
#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);
}

View file

@ -0,0 +1,363 @@
#version 450
// 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.
layout(push_constant) uniform Push
{
float hardScan;
float hardPix;
float warpX;
float warpY;
float maskDark;
float maskLight;
float scaleInLinearGamma;
float shadowMask;
float brightBoost;
float hardBloomScan;
float hardBloomPix;
float bloomAmount;
float shape;
float DIFFUSION;
} param;
#pragma parameter hardScan "hardScan" -8.0 -20.0 0.0 1.0
#pragma parameter hardPix "hardPix" -3.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 scaleInLinearGamma "scaleInLinearGamma" 1.0 0.0 1.0 1.0
#pragma parameter shadowMask "shadowMask" 3.0 0.0 4.0 1.0
#pragma parameter brightBoost "brightness boost" 1.0 0.0 2.0 0.05
#pragma parameter hardBloomPix "bloom-x soft" -1.5 -2.0 -0.5 0.1
#pragma parameter hardBloomScan "bloom-y soft" -2.0 -4.0 -1.0 0.1
#pragma parameter bloomAmount "bloom amount" 0.40 0.0 1.0 0.05
#pragma parameter shape "filter kernel shape" 2.0 0.0 10.0 0.05
#pragma parameter DIFFUSION "Diffusion" 0.0 0.0 1.0 0.01
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 * 1.00001;
}
#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;
layout(set = 0, binding = 3) uniform sampler2D ORIG_LINEARIZED;
layout(set = 0, binding = 4) uniform sampler2D BloomPass;
layout(set = 0, binding = 5) uniform sampler2D GlowPass;
//Uncomment to reduce instructions with simpler linearization
//(fixes HD3000 Sandy Bridge IGP)
#define SIMPLE_LINEAR_GAMMA
#define DO_BLOOM 1
// ------------- //
// sRGB to Linear.
// Assuming using sRGB typed textures this should not be needed.
#ifdef SIMPLE_LINEAR_GAMMA
float ToLinear1(float c)
{
return c;
}
vec3 ToLinear(vec3 c)
{
return c;
}
vec3 ToSrgb(vec3 c)
{
return pow(c, vec3(1.0 / 2.2));
}
#else
float ToLinear1(float c)
{
if (param.scaleInLinearGamma == 0)
return c;
return(c<=0.04045) ? c/12.92 : pow((c + 0.055)/1.055, 2.4);
}
vec3 ToLinear(vec3 c)
{
if (param.scaleInLinearGamma==0)
return c;
return vec3(ToLinear1(c.r), ToLinear1(c.g), ToLinear1(c.b));
}
// Linear to sRGB.
// Assuming using sRGB typed textures this should not be needed.
float ToSrgb1(float c)
{
if (param.scaleInLinearGamma == 0)
return c;
return(c<0.0031308 ? c*12.92 : 1.055*pow(c, 0.41666) - 0.055);
}
vec3 ToSrgb(vec3 c)
{
if (param.scaleInLinearGamma == 0)
return c;
return vec3(ToSrgb1(c.r), ToSrgb1(c.g), ToSrgb1(c.b));
}
#endif
// Nearest emulated sample given floating point position and texel offset.
// Also zero's off screen.
vec3 Fetch(vec2 pos,vec2 off){
pos=(floor(pos*global.SourceSize.xy+off)+vec2(0.5,0.5))/global.SourceSize.xy;
#ifdef SIMPLE_LINEAR_GAMMA
return ToLinear(param.brightBoost * (texture(ORIG_LINEARIZED,pos.xy).rgb));
#else
return ToLinear(param.brightBoost * texture(ORIG_LINEARIZED,pos.xy).rgb);
#endif
}
// Distance in emulated pixels to nearest texel.
vec2 Dist(vec2 pos)
{
pos = pos*global.SourceSize.xy;
return -((pos - floor(pos)) - vec2(0.5));
}
// 1D Gaussian.
float Gaus(float pos, float scale)
{
return exp2(scale*pow(abs(pos), param.shape));
}
// 3-tap Gaussian filter along horz line.
vec3 Horz3(vec2 pos, float off)
{
vec3 b = Fetch(pos, vec2(-1.0, off));
vec3 c = Fetch(pos, vec2( 0.0, off));
vec3 d = Fetch(pos, vec2( 1.0, off));
float dst = Dist(pos).x;
// Convert distance to weight.
float scale = param.hardPix;
float wb = Gaus(dst-1.0,scale);
float wc = Gaus(dst+0.0,scale);
float wd = Gaus(dst+1.0,scale);
// Return filtered sample.
return (b*wb+c*wc+d*wd)/(wb+wc+wd);
}
// 5-tap Gaussian filter along horz line.
vec3 Horz5(vec2 pos,float off){
vec3 a = Fetch(pos,vec2(-2.0, off));
vec3 b = Fetch(pos,vec2(-1.0, off));
vec3 c = Fetch(pos,vec2( 0.0, off));
vec3 d = Fetch(pos,vec2( 1.0, off));
vec3 e = Fetch(pos,vec2( 2.0, off));
float dst = Dist(pos).x;
// Convert distance to weight.
float scale = param.hardPix;
float wa = Gaus(dst - 2.0, scale);
float wb = Gaus(dst - 1.0, scale);
float wc = Gaus(dst + 0.0, scale);
float wd = Gaus(dst + 1.0, scale);
float we = Gaus(dst + 2.0, scale);
// Return filtered sample.
return (a*wa+b*wb+c*wc+d*wd+e*we)/(wa+wb+wc+wd+we);
}
// 7-tap Gaussian filter along horz line.
vec3 Horz7(vec2 pos,float off)
{
vec3 a = Fetch(pos, vec2(-3.0, off));
vec3 b = Fetch(pos, vec2(-2.0, off));
vec3 c = Fetch(pos, vec2(-1.0, off));
vec3 d = Fetch(pos, vec2( 0.0, off));
vec3 e = Fetch(pos, vec2( 1.0, off));
vec3 f = Fetch(pos, vec2( 2.0, off));
vec3 g = Fetch(pos, vec2( 3.0, off));
float dst = Dist(pos).x;
// Convert distance to weight.
float scale = param.hardBloomPix;
float wa = Gaus(dst - 3.0, scale);
float wb = Gaus(dst - 2.0, scale);
float wc = Gaus(dst - 1.0, scale);
float wd = Gaus(dst + 0.0, scale);
float we = Gaus(dst + 1.0, scale);
float wf = Gaus(dst + 2.0, scale);
float wg = Gaus(dst + 3.0, scale);
// Return filtered sample.
return (a*wa+b*wb+c*wc+d*wd+e*we+f*wf+g*wg)/(wa+wb+wc+wd+we+wf+wg);
}
// Return scanline weight.
float Scan(vec2 pos, float off)
{
float dst = Dist(pos).y;
return Gaus(dst + off, param.hardScan);
}
// Return scanline weight for bloom.
float BloomScan(vec2 pos, float off)
{
float dst = Dist(pos).y;
return Gaus(dst + off, param.hardBloomScan);
}
// Allow nearest three lines to effect pixel.
vec3 Tri(vec2 pos)
{
vec3 a = Horz3(pos,-1.0);
vec3 b = Horz5(pos, 0.0);
vec3 c = 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 = Horz5(pos,-2.0);
vec3 b = Horz7(pos,-1.0);
vec3 c = Horz7(pos, 0.0);
vec3 d = Horz7(pos, 1.0);
vec3 e = 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)*param.warpX, 1.0 + (pos.x*pos.x)*param.warpY);
return pos*0.5 + 0.5;
}
// Shadow mask.
vec3 Mask(vec2 pos)
{
vec3 mask = vec3(param.maskDark, param.maskDark, param.maskDark);
// Very compressed TV style shadow mask.
if (param.shadowMask == 1.0)
{
float line = param.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 = param.maskDark;
pos.x = fract(pos.x*0.333333333);
if (pos.x < 0.333) mask.r = param.maskLight;
else if (pos.x < 0.666) mask.g = param.maskLight;
else mask.b = param.maskLight;
mask*=line;
}
// Aperture-grille.
else if (param.shadowMask == 2.0)
{
pos.x = fract(pos.x*0.333333333);
if (pos.x < 0.333) mask.r = param.maskLight;
else if (pos.x < 0.666) mask.g = param.maskLight;
else mask.b = param.maskLight;
}
// Stretched VGA style shadow mask (same as prior shaders).
else if (param.shadowMask == 3.0)
{
pos.x += pos.y*3.0;
pos.x = fract(pos.x*0.166666666);
if (pos.x < 0.333) mask.r = param.maskLight;
else if (pos.x < 0.666) mask.g = param.maskLight;
else mask.b = param.maskLight;
}
// VGA style shadow mask.
else if (param.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 = param.maskLight;
else if (pos.x < 0.666) mask.g = param.maskLight;
else mask.b = param.maskLight;
}
return mask;
}
void main()
{
vec2 pos = Warp(vTexCoord);
vec3 outColor = Tri(pos).rgb;
vec3 diff = texture(GlowPass, pos).rgb;
if (param.shadowMask > 0.0)
outColor.rgb *= Mask(vTexCoord.xy / global.OutputSize.zw * 1.000001);
#ifdef DO_BLOOM
//Add Bloom
outColor.rgb += mix( vec3(0.0), texture(BloomPass, pos).rgb, param.bloomAmount);
#endif
#ifdef GL_ES /* 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);
#endif
outColor += diff * param.DIFFUSION;
FragColor = vec4(ToSrgb(outColor.rgb), 1.0);
}

View file

@ -28,7 +28,7 @@ layout(push_constant) uniform Push
float hardBloomPix; float hardBloomPix;
float bloomAmount; float bloomAmount;
float shape; float shape;
} params; } param;
#pragma parameter hardScan "hardScan" -8.0 -20.0 0.0 1.0 #pragma parameter hardScan "hardScan" -8.0 -20.0 0.0 1.0
#pragma parameter hardPix "hardPix" -3.0 -20.0 0.0 1.0 #pragma parameter hardPix "hardPix" -3.0 -20.0 0.0 1.0
@ -68,8 +68,8 @@ layout(location = 0) in vec2 vTexCoord;
layout(location = 1) in vec2 FragCoord; layout(location = 1) in vec2 FragCoord;
layout(location = 0) out vec4 FragColor; layout(location = 0) out vec4 FragColor;
layout(set = 0, binding = 2) uniform sampler2D Source; layout(set = 0, binding = 2) uniform sampler2D Source;
layout(set = 0, binding = 3) uniform sampler2D Original; layout(set = 0, binding = 3) uniform sampler2D BloomPass;
layout(set = 0, binding = 4) uniform sampler2D BloomPass; layout(set = 0, binding = 4) uniform sampler2D Reference;
//Uncomment to reduce instructions with simpler linearization //Uncomment to reduce instructions with simpler linearization
//(fixes HD3000 Sandy Bridge IGP) //(fixes HD3000 Sandy Bridge IGP)
@ -96,7 +96,7 @@ vec3 ToSrgb(vec3 c)
#else #else
float ToLinear1(float c) float ToLinear1(float c)
{ {
if (params.scaleInLinearGamma == 0) if (param.scaleInLinearGamma == 0)
return c; return c;
return(c<=0.04045) ? c/12.92 : pow((c + 0.055)/1.055, 2.4); return(c<=0.04045) ? c/12.92 : pow((c + 0.055)/1.055, 2.4);
@ -104,7 +104,7 @@ float ToLinear1(float c)
vec3 ToLinear(vec3 c) vec3 ToLinear(vec3 c)
{ {
if (params.scaleInLinearGamma==0) if (param.scaleInLinearGamma==0)
return c; return c;
return vec3(ToLinear1(c.r), ToLinear1(c.g), ToLinear1(c.b)); return vec3(ToLinear1(c.r), ToLinear1(c.g), ToLinear1(c.b));
@ -114,7 +114,7 @@ vec3 ToLinear(vec3 c)
// Assuming using sRGB typed textures this should not be needed. // Assuming using sRGB typed textures this should not be needed.
float ToSrgb1(float c) float ToSrgb1(float c)
{ {
if (params.scaleInLinearGamma == 0) if (param.scaleInLinearGamma == 0)
return c; return c;
return(c<0.0031308 ? c*12.92 : 1.055*pow(c, 0.41666) - 0.055); return(c<0.0031308 ? c*12.92 : 1.055*pow(c, 0.41666) - 0.055);
@ -122,7 +122,7 @@ float ToSrgb1(float c)
vec3 ToSrgb(vec3 c) vec3 ToSrgb(vec3 c)
{ {
if (params.scaleInLinearGamma == 0) if (param.scaleInLinearGamma == 0)
return c; return c;
return vec3(ToSrgb1(c.r), ToSrgb1(c.g), ToSrgb1(c.b)); return vec3(ToSrgb1(c.r), ToSrgb1(c.g), ToSrgb1(c.b));
@ -136,9 +136,9 @@ vec3 ToSrgb(vec3 c)
vec3 Fetch(vec2 pos,vec2 off){ vec3 Fetch(vec2 pos,vec2 off){
pos=(floor(pos*global.SourceSize.xy+off)+vec2(0.5,0.5))/global.SourceSize.xy; pos=(floor(pos*global.SourceSize.xy+off)+vec2(0.5,0.5))/global.SourceSize.xy;
#ifdef SIMPLE_LINEAR_GAMMA #ifdef SIMPLE_LINEAR_GAMMA
return ToLinear(params.brightBoost * pow(texture(Original,pos.xy).rgb, vec3(2.2))); return ToLinear(param.brightBoost * pow(texture(Reference,pos.xy).rgb, vec3(2.2)));
#else #else
return ToLinear(params.brightBoost * texture(Original,pos.xy).rgb); return ToLinear(param.brightBoost * texture(Reference,pos.xy).rgb);
#endif #endif
} }
@ -153,7 +153,7 @@ vec2 Dist(vec2 pos)
// 1D Gaussian. // 1D Gaussian.
float Gaus(float pos, float scale) float Gaus(float pos, float scale)
{ {
return exp2(scale*pow(abs(pos), params.shape)); return exp2(scale*pow(abs(pos), param.shape));
} }
// 3-tap Gaussian filter along horz line. // 3-tap Gaussian filter along horz line.
@ -165,7 +165,7 @@ vec3 Horz3(vec2 pos, float off)
float dst = Dist(pos).x; float dst = Dist(pos).x;
// Convert distance to weight. // Convert distance to weight.
float scale = params.hardPix; float scale = param.hardPix;
float wb = Gaus(dst-1.0,scale); float wb = Gaus(dst-1.0,scale);
float wc = Gaus(dst+0.0,scale); float wc = Gaus(dst+0.0,scale);
float wd = Gaus(dst+1.0,scale); float wd = Gaus(dst+1.0,scale);
@ -184,7 +184,7 @@ vec3 Horz5(vec2 pos,float off){
float dst = Dist(pos).x; float dst = Dist(pos).x;
// Convert distance to weight. // Convert distance to weight.
float scale = params.hardPix; float scale = param.hardPix;
float wa = Gaus(dst - 2.0, scale); float wa = Gaus(dst - 2.0, scale);
float wb = Gaus(dst - 1.0, scale); float wb = Gaus(dst - 1.0, scale);
float wc = Gaus(dst + 0.0, scale); float wc = Gaus(dst + 0.0, scale);
@ -208,7 +208,7 @@ vec3 Horz7(vec2 pos,float off)
float dst = Dist(pos).x; float dst = Dist(pos).x;
// Convert distance to weight. // Convert distance to weight.
float scale = params.hardBloomPix; float scale = param.hardBloomPix;
float wa = Gaus(dst - 3.0, scale); float wa = Gaus(dst - 3.0, scale);
float wb = Gaus(dst - 2.0, scale); float wb = Gaus(dst - 2.0, scale);
float wc = Gaus(dst - 1.0, scale); float wc = Gaus(dst - 1.0, scale);
@ -226,7 +226,7 @@ float Scan(vec2 pos, float off)
{ {
float dst = Dist(pos).y; float dst = Dist(pos).y;
return Gaus(dst + off, params.hardScan); return Gaus(dst + off, param.hardScan);
} }
// Return scanline weight for bloom. // Return scanline weight for bloom.
@ -234,7 +234,7 @@ float BloomScan(vec2 pos, float off)
{ {
float dst = Dist(pos).y; float dst = Dist(pos).y;
return Gaus(dst + off, params.hardBloomScan); return Gaus(dst + off, param.hardBloomScan);
} }
// Allow nearest three lines to effect pixel. // Allow nearest three lines to effect pixel.
@ -273,7 +273,7 @@ vec3 Bloom(vec2 pos)
vec2 Warp(vec2 pos) vec2 Warp(vec2 pos)
{ {
pos = pos*2.0-1.0; pos = pos*2.0-1.0;
pos *= vec2(1.0 + (pos.y*pos.y)*params.warpX, 1.0 + (pos.x*pos.x)*params.warpY); pos *= vec2(1.0 + (pos.y*pos.y)*param.warpX, 1.0 + (pos.x*pos.x)*param.warpY);
return pos*0.5 + 0.5; return pos*0.5 + 0.5;
} }
@ -281,56 +281,56 @@ vec2 Warp(vec2 pos)
// Shadow mask. // Shadow mask.
vec3 Mask(vec2 pos) vec3 Mask(vec2 pos)
{ {
vec3 mask = vec3(params.maskDark, params.maskDark, params.maskDark); vec3 mask = vec3(param.maskDark, param.maskDark, param.maskDark);
// Very compressed TV style shadow mask. // Very compressed TV style shadow mask.
if (params.shadowMask == 1.0) if (param.shadowMask == 1.0)
{ {
float line = params.maskLight; float line = param.maskLight;
float odd = 0.0; float odd = 0.0;
if (fract(pos.x*0.166666666) < 0.5) odd = 1.0; if (fract(pos.x*0.166666666) < 0.5) odd = 1.0;
if (fract((pos.y + odd) * 0.5) < 0.5) line = params.maskDark; if (fract((pos.y + odd) * 0.5) < 0.5) line = param.maskDark;
pos.x = fract(pos.x*0.333333333); pos.x = fract(pos.x*0.333333333);
if (pos.x < 0.333) mask.r = params.maskLight; if (pos.x < 0.333) mask.r = param.maskLight;
else if (pos.x < 0.666) mask.g = params.maskLight; else if (pos.x < 0.666) mask.g = param.maskLight;
else mask.b = params.maskLight; else mask.b = param.maskLight;
mask*=line; mask*=line;
} }
// Aperture-grille. // Aperture-grille.
else if (params.shadowMask == 2.0) else if (param.shadowMask == 2.0)
{ {
pos.x = fract(pos.x*0.333333333); pos.x = fract(pos.x*0.333333333);
if (pos.x < 0.333) mask.r = params.maskLight; if (pos.x < 0.333) mask.r = param.maskLight;
else if (pos.x < 0.666) mask.g = params.maskLight; else if (pos.x < 0.666) mask.g = param.maskLight;
else mask.b = params.maskLight; else mask.b = param.maskLight;
} }
// Stretched VGA style shadow mask (same as prior shaders). // Stretched VGA style shadow mask (same as prior shaders).
else if (params.shadowMask == 3.0) else if (param.shadowMask == 3.0)
{ {
pos.x += pos.y*3.0; pos.x += pos.y*3.0;
pos.x = fract(pos.x*0.166666666); pos.x = fract(pos.x*0.166666666);
if (pos.x < 0.333) mask.r = params.maskLight; if (pos.x < 0.333) mask.r = param.maskLight;
else if (pos.x < 0.666) mask.g = params.maskLight; else if (pos.x < 0.666) mask.g = param.maskLight;
else mask.b = params.maskLight; else mask.b = param.maskLight;
} }
// VGA style shadow mask. // VGA style shadow mask.
else if (params.shadowMask == 4.0) else if (param.shadowMask == 4.0)
{ {
pos.xy = floor(pos.xy*vec2(1.0, 0.5)); pos.xy = floor(pos.xy*vec2(1.0, 0.5));
pos.x += pos.y*3.0; pos.x += pos.y*3.0;
pos.x = fract(pos.x*0.166666666); pos.x = fract(pos.x*0.166666666);
if (pos.x < 0.333) mask.r = params.maskLight; if (pos.x < 0.333) mask.r = param.maskLight;
else if (pos.x < 0.666) mask.g = params.maskLight; else if (pos.x < 0.666) mask.g = param.maskLight;
else mask.b = params.maskLight; else mask.b = param.maskLight;
} }
return mask; return mask;
@ -341,11 +341,11 @@ void main()
vec2 pos = Warp(vTexCoord); vec2 pos = Warp(vTexCoord);
vec3 outColor = Tri(pos).rgb; vec3 outColor = Tri(pos).rgb;
if (params.shadowMask > 0.0) if (param.shadowMask > 0.0)
outColor.rgb *= Mask(vTexCoord.xy / global.OutputSize.zw * 1.000001); outColor.rgb *= Mask(vTexCoord.xy / global.OutputSize.zw * 1.000001);
#ifdef DO_BLOOM #ifdef DO_BLOOM
//Add Bloom //Add Bloom
outColor.rgb += mix( vec3(0.0), texture(BloomPass, pos).rgb, params.bloomAmount); outColor.rgb += mix( vec3(0.0), texture(BloomPass, pos).rgb, param.bloomAmount);
#endif #endif
#ifdef GL_ES /* TODO/FIXME - hacky clamp fix */ #ifdef GL_ES /* TODO/FIXME - hacky clamp fix */
vec2 bordertest = (pos); vec2 bordertest = (pos);

View file

@ -1,110 +0,0 @@
shaders = 18
shader0 = ../crt/shaders/glow-trails/glow-trails0.slang
filter_linear0 = false
scale_type0 = source
scale0 = 1.0
shader1 = "../blurs/blur9fast-vertical.slang"
filter_linear1 = "true"
scale_type1 = "source"
scale1 = "1.0"
srgb_framebuffer1 = "true"
shader2 = "../blurs/blur9fast-horizontal.slang"
alias2 = "TRAIL_BLUR"
filter_linear2 = "true"
scale_type2 = "source"
scale2 = "1.0"
srgb_framebuffer2 = "true"
shader3 = ../crt/shaders/glow-trails/glow-trails1.slang
shader4 = ../crt/shaders/crt-royale/src/crt-royale-first-pass-linearize-crt-gamma-bob-fields.slang
srgb_framebuffer4 = true
alias4 = "REFERENCE"
shader5 = "../crt/shaders/crt-lottes-multipass/old/threshold.slang"
srgb_framebuffer5 = "true"
shader6 = "../blurs/blur9fast-vertical.slang"
filter_linear6 = "true"
scale_type6 = "source"
scale6 = "1.0"
srgb_framebuffer6 = "true"
shader7 = "../blurs/blur9fast-horizontal.slang"
alias7 = "HALATION_BLUR"
filter_linear7 = "true"
scale_type7 = "source"
scale7 = "1.0"
srgb_framebuffer7 = "true"
shader8 = ../crt/shaders/crt-lottes-multipass/old/horz3minus1.slang
srgb_framebuffer8 = true
scale_type8 = source
filter_linear8 = true
alias8 = horz3minus1
shader9 = ../crt/shaders/crt-lottes-multipass/old/horz3plus1.slang
srgb_framebuffer9 = true
scale_type9 = source
filter_linear9 = true
alias9 = horz3plus1
shader10 = ../crt/shaders/crt-lottes-multipass/old/horz5minus2.slang
srgb_framebuffer10 = true
scale_type10 = source
filter_linear10 = true
alias10 = horz5minus2
shader11 = ../crt/shaders/crt-lottes-multipass/old/horz5.slang
srgb_framebuffer11 = true
scale_type11 = source
filter_linear11 = true
alias11 = horz5
shader12 = ../crt/shaders/crt-lottes-multipass/old/horz5plus2.slang
srgb_framebuffer12 = true
scale_type12 = source
filter_linear12 = true
alias12 = horz5plus2
shader13 = ../crt/shaders/crt-lottes-multipass/old/horz7minus1.slang
srgb_framebuffer13 = true
scale_type13 = source
filter_linear13 = true
alias13 = horz7minus1
shader14 = ../crt/shaders/crt-lottes-multipass/old/horz7.slang
srgb_framebuffer14 = true
scale_type14 = source
filter_linear14 = true
alias14 = horz7
shader15 = ../crt/shaders/crt-lottes-multipass/old/horz7plus1.slang
srgb_framebuffer15 = true
scale_type15 = source
filter_linear15 = true
alias15 = horz7plus1
shader16 = ../crt/shaders/crt-lottes-multipass/old/crt-lottes-multipass-glow.slang
texture_wrap_mode16 = "clamp_to_edge"
scale16 = 4.0
scale_type16 = source
shader17 = ../border/shaders/imgborder.slang
textures = BORDER
BORDER = ../border/textures/pvm.png
parameters = "border_on_top;mixfactor;threshold;trail_bright;glowFactor;hardScan;shadowMask;warpX"
mixfactor = "0.75"
threshold = "0.90"
trail_bright = "0.07"
glowFactor = "0.10"
hardScan = "-20.0"
shadowMask = "2.0"
warpX = "0.0"
warpY = "0.3"
border_on_top = 1.0