From 8009dea4d724b288009d68bc5ccee9d5799e186e Mon Sep 17 00:00:00 2001 From: hunterk Date: Tue, 20 Dec 2016 15:36:43 -0600 Subject: [PATCH] break glow-trails to its own shader and add vector-glow presets --- ...rt-lottes-multipass-interlaced-glow.slangp | 4 +- crt/shaders/glow-trails/combine.slang | 45 +++++++++++++ crt/shaders/glow-trails/glow-trails0.slang | 66 +++++++++++++++++++ crt/shaders/glow-trails/glow-trails1.slang | 47 +++++++++++++ crt/vector-glow-alt-render.slangp | 29 ++++++++ crt/vector-glow.slangp | 49 ++++++++++++++ presets/crt-lottes-trinitron.slangp | 4 +- 7 files changed, 240 insertions(+), 4 deletions(-) create mode 100644 crt/shaders/glow-trails/combine.slang create mode 100644 crt/shaders/glow-trails/glow-trails0.slang create mode 100644 crt/shaders/glow-trails/glow-trails1.slang create mode 100644 crt/vector-glow-alt-render.slangp create mode 100644 crt/vector-glow.slangp diff --git a/crt/crt-lottes-multipass-interlaced-glow.slangp b/crt/crt-lottes-multipass-interlaced-glow.slangp index b59eeb2..b1c08fd 100644 --- a/crt/crt-lottes-multipass-interlaced-glow.slangp +++ b/crt/crt-lottes-multipass-interlaced-glow.slangp @@ -1,6 +1,6 @@ shaders = 17 -shader0 = shaders/crt-lottes-multipass/glow-trails0.slang +shader0 = shaders/glow-trails/glow-trails0.slang filter_linear0 = false scale_type0 = source scale0 = 1.0 @@ -18,7 +18,7 @@ scale_type2 = "source" scale2 = "1.0" srgb_framebuffer2 = "true" -shader3 = shaders/crt-lottes-multipass/glow-trails1.slang +shader3 = shaders/glow-trails/glow-trails1.slang shader4 = shaders/crt-royale/src/crt-royale-first-pass-linearize-crt-gamma-bob-fields.slang srgb_framebuffer4 = true diff --git a/crt/shaders/glow-trails/combine.slang b/crt/shaders/glow-trails/combine.slang new file mode 100644 index 0000000..bff6d3c --- /dev/null +++ b/crt/shaders/glow-trails/combine.slang @@ -0,0 +1,45 @@ +#version 450 + +layout(push_constant) uniform Push +{ + vec4 SourceSize; + vec4 OriginalSize; + vec4 OutputSize; + uint FrameCount; + float screen_combine; + float haze_strength; +} params; + +#pragma parameter screen_combine "Screen Combine" 0.0 0.0 1.0 1.0 +#pragma parameter haze_strength "Haze Strength" 0.5 0.0 1.0 0.05 + +layout(std140, set = 0, binding = 0) uniform UBO +{ + mat4 MVP; +} global; + +#pragma stage vertex +layout(location = 0) in vec4 Position; +layout(location = 1) in vec2 TexCoord; +layout(location = 0) out vec2 vTexCoord; + +void main() +{ + gl_Position = global.MVP * Position; + vTexCoord = TexCoord; +} + +#pragma stage fragment +layout(location = 0) in vec2 vTexCoord; +layout(location = 0) out vec4 FragColor; +layout(set = 0, binding = 2) uniform sampler2D Source; +layout(set = 0, binding = 3) uniform sampler2D PASS1; + +void main() +{ +vec4 blurred = pow(texture(Source, vTexCoord), vec4(2.2)); +vec4 unblurred = pow(texture(PASS1, vTexCoord), vec4(2.2)); +vec4 dark = vec4(pow(mix(unblurred, blurred, params.haze_strength), vec4(1.0 / 2.2)));//vec4(pow((unblurred + blurred) / 2.0, vec4(1.0 / 2.2))); +vec4 bright = vec4(pow(vec4(1.0) - (vec4(1.0) - unblurred) * (vec4(1.0) - blurred), vec4(1.0 / 2.2))); + FragColor = (params.screen_combine < 0.5) ? dark : bright; +} \ No newline at end of file diff --git a/crt/shaders/glow-trails/glow-trails0.slang b/crt/shaders/glow-trails/glow-trails0.slang new file mode 100644 index 0000000..3cc5c37 --- /dev/null +++ b/crt/shaders/glow-trails/glow-trails0.slang @@ -0,0 +1,66 @@ +#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)); +} \ No newline at end of file diff --git a/crt/shaders/glow-trails/glow-trails1.slang b/crt/shaders/glow-trails/glow-trails1.slang new file mode 100644 index 0000000..f9534f5 --- /dev/null +++ b/crt/shaders/glow-trails/glow-trails1.slang @@ -0,0 +1,47 @@ +#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))); +} \ No newline at end of file diff --git a/crt/vector-glow-alt-render.slangp b/crt/vector-glow-alt-render.slangp new file mode 100644 index 0000000..547e218 --- /dev/null +++ b/crt/vector-glow-alt-render.slangp @@ -0,0 +1,29 @@ +shaders = 4 + +shader0 = "../misc/image-adjustment.slang" +alias0 = PASS1 + +shader1 = "../blurs/blur11fast-vertical.slang" +filter_linear1 = "true" +scale_type1 = "source" +scale1 = "0.5" +mipmap1 = "true" + +shader2 = "../blurs/blur11fast-horizontal.slang" +filter_linear2 = "true" +scale_type2 = "source" +scale2 = "0.5" +mipmap_input2 = "true" + +shader3 = "shaders/glow-trails/combine.slang" +scale_type3 = "viewport" +scale3 = 1.0 + +parameters = "mixfactor;threshold;trail_bright;glowFactor;haze_strength;luminance;screen_combine" +mixfactor = "0.18" +threshold = "0.90" +trail_bright = "0.30" +glowFactor = "0.10" +haze_strength = "0.75" +luminance = "1.50" +screen_combine = "1.0" \ No newline at end of file diff --git a/crt/vector-glow.slangp b/crt/vector-glow.slangp new file mode 100644 index 0000000..69ad217 --- /dev/null +++ b/crt/vector-glow.slangp @@ -0,0 +1,49 @@ +shaders = 9 + +shader0 = 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 = shaders/glow-trails/glow-trails1.slang + +shader4 = "../anti-aliasing/shaders/advanced-aa.slang" +alias4 = PASS1 + +shader5 = "../blurs/blur9fast-vertical.slang" +filter_linear5 = "true" +scale_type5 = "source" +scale5 = "1.0" +srgb_framebuffer5 = "true" + +shader6 = "../blurs/blur9fast-horizontal.slang" +filter_linear6 = "true" +scale_type6 = "source" +scale6 = "1.0" +srgb_framebuffer6 = "true" + +shader7 = "shaders/glow-trails/combine.slang" + +shader8 = "../misc/image-adjustment.slang" + +parameters = "mixfactor;threshold;trail_bright;glowFactor;haze_strength;luminance;bright" +mixfactor = "0.18" +threshold = "0.90" +trail_bright = "0.30" +glowFactor = "0.10" +haze_strength = "0.25" +luminance = "1.50" +bright = "1.0" \ No newline at end of file diff --git a/presets/crt-lottes-trinitron.slangp b/presets/crt-lottes-trinitron.slangp index 6a7cde7..a7f3cc4 100755 --- a/presets/crt-lottes-trinitron.slangp +++ b/presets/crt-lottes-trinitron.slangp @@ -1,6 +1,6 @@ shaders = 18 -shader0 = ../crt/shaders/crt-lottes-multipass/glow-trails0.slang +shader0 = ../crt/shaders/glow-trails/glow-trails0.slang filter_linear0 = false scale_type0 = source scale0 = 1.0 @@ -18,7 +18,7 @@ scale_type2 = "source" scale2 = "1.0" srgb_framebuffer2 = "true" -shader3 = ../crt/shaders/crt-lottes-multipass/glow-trails1.slang +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