some formatting cleanups and add torridgristle's mask to dotmask

This commit is contained in:
hunterk 2019-01-16 16:12:04 -06:00
parent d81d82ef48
commit 6ffa629671

View file

@ -2,10 +2,10 @@
/* /*
Dot Mask Dot Mask
Authors: cgwg, Timothy Lottes Authors: cgwg, Timothy Lottes, torridgristle
License: GPL License: GPL
Note: This shader is just the dotmask functions from cgwg's CRT shader and crt-lottes. Note: This shader is just the dotmask functions from cgwg's CRT shader and crt-lottes plus torridgristle's mask.
*/ */
layout(std140, set = 0, binding = 0) uniform UBO layout(std140, set = 0, binding = 0) uniform UBO
@ -23,7 +23,7 @@ layout(std140, set = 0, binding = 0) uniform UBO
#pragma parameter DOTMASK_STRENGTH "CGWG Dot Mask Strength" 0.3 0.0 1.0 0.01 #pragma parameter DOTMASK_STRENGTH "CGWG Dot Mask Strength" 0.3 0.0 1.0 0.01
#pragma parameter maskDark "Lottes maskDark" 0.5 0.0 2.0 0.1 #pragma parameter maskDark "Lottes maskDark" 0.5 0.0 2.0 0.1
#pragma parameter maskLight "Lottes maskLight" 1.5 0.0 2.0 0.1 #pragma parameter maskLight "Lottes maskLight" 1.5 0.0 2.0 0.1
#pragma parameter shadowMask "Mask Style" 3.0 0.0 4.0 1.0 #pragma parameter shadowMask "Mask Style" 3.0 0.0 5.0 1.0
#define mod_factor vTexCoord.x * global.SourceSize.x * global.OutputSize.x / global.SourceSize.x #define mod_factor vTexCoord.x * global.SourceSize.x * global.OutputSize.x / global.SourceSize.x
@ -43,6 +43,7 @@ layout(location = 0) in vec2 vTexCoord;
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;
// Lottes' public domain mask code
// Shadow mask. // Shadow mask.
vec3 Mask(vec2 pos){ vec3 Mask(vec2 pos){
vec3 mask=vec3(global.maskDark,global.maskDark,global.maskDark); vec3 mask=vec3(global.maskDark,global.maskDark,global.maskDark);
@ -91,24 +92,55 @@ vec3 Mask(vec2 pos){
else mask.b=global.maskLight; else mask.b=global.maskLight;
} }
return mask;} return mask;
}
// torridgristle's shadowmask code
const float Pi = 3.1415926536;
vec3 SinPhosphor(vec3 image)
{
float MaskR = sin(global.OutputSize.x*vTexCoord.x*Pi*1.0+Pi*0.00000+vTexCoord.y*global.OutputSize.y*Pi*0.5)*0.5+0.5;
float MaskG = sin(global.OutputSize.x*vTexCoord.x*Pi*1.0+Pi*1.33333+vTexCoord.y*global.OutputSize.y*Pi*0.5)*0.5+0.5;
float MaskB = sin(global.OutputSize.x*vTexCoord.x*Pi*1.0+Pi*0.66667+vTexCoord.y*global.OutputSize.y*Pi*0.5)*0.5+0.5;
vec3 Mask = vec3(MaskR,MaskG,MaskB);
Mask = min(Mask*2.0,1.0);
return vec3(Mask * image);
}
// cgwg's aperture grille
vec3 cgwg_mask(vec3 image)
{
float mask = 1.0 - global.DOTMASK_STRENGTH;
//Output pixels are alternately tinted green and magenta
vec3 dotMaskWeights = mix(vec3(1.0, mask, 1.0),
vec3(mask, 1.0, mask),
floor(mod(mod_factor, 2.0)));
return image * dotMaskWeights;
}
void main() void main()
{ {
vec3 res = pow(texture(Source, vTexCoord).rgb, vec3(2.2)); vec3 res = texture(Source, vTexCoord).rgb;
float mask = 1.0 - global.DOTMASK_STRENGTH; if (global.shadowMask == 0.0)
{
//cgwg's dotmask emulation: res = cgwg_mask(res);
//Output pixels are alternately tinted green and magenta FragColor = vec4(res, 1.0);
vec3 dotMaskWeights = mix(vec3(1.0, mask, 1.0), return;
vec3(mask, 1.0, mask),
floor(mod(mod_factor, 2.0)));
if (global.shadowMask == 0) {
res *= dotMaskWeights;
}
else {
res *= Mask(floor(1.000001 * vTexCoord.xy * global.OutputSize.xy + vec2(0.5)));
} }
else if (global.shadowMask == 5.0)
{
res *= SinPhosphor(res);
}
else
{
// Lottes mask needs linear gamma
res = pow(res, vec3(2.2));
res *= Mask(floor(1.000001 * vTexCoord.xy * global.OutputSize.xy + vec2(0.5)));
}
FragColor = vec4(pow(res, vec3(1.0/2.2)), 1.0); FragColor = vec4(pow(res, vec3(1.0/2.2)), 1.0);
} }