From e059ed300d09517ebc9adf1f880f1da7658fb697 Mon Sep 17 00:00:00 2001 From: kokoko3k Date: Sat, 6 Jan 2024 15:58:45 +0100 Subject: [PATCH] Add crt-resswitch-glitch-koko --- crt/crt-resswitch-glitch-koko.slangp | 6 ++ crt/shaders/crt-resswitch-glitch-koko.slang | 87 +++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 crt/crt-resswitch-glitch-koko.slangp create mode 100644 crt/shaders/crt-resswitch-glitch-koko.slang diff --git a/crt/crt-resswitch-glitch-koko.slangp b/crt/crt-resswitch-glitch-koko.slangp new file mode 100644 index 00000000..7f054724 --- /dev/null +++ b/crt/crt-resswitch-glitch-koko.slangp @@ -0,0 +1,6 @@ +shaders = 1 + + shader0 = shaders/crt-resswitch-glitch-koko.slang +scale_type0 = source + scale_0 = 1.0 + wrap_mode0 = "clamp_to_border" diff --git a/crt/shaders/crt-resswitch-glitch-koko.slang b/crt/shaders/crt-resswitch-glitch-koko.slang new file mode 100644 index 00000000..3927f6ef --- /dev/null +++ b/crt/shaders/crt-resswitch-glitch-koko.slang @@ -0,0 +1,87 @@ +#version 450 + +///////////////////////////// GPL LICENSE NOTICE ///////////////////////////// +// +// crt-resswitch-glitch-koko +// Copyright (C) 2024 Antonio Orefice +// +// This program is free software; you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by the Free +// Software Foundation; either version 3 of the License, or any later version. +// +//////////////////////////////////////////////////////////////////////////////// + + +layout(std140, set = 0, binding = 0) uniform UBO { + mat4 MVP; + vec4 SourceSize; + vec4 OriginalHistorySize1; + vec4 OriginalHistorySize2; + vec4 OriginalHistorySize3; + vec4 OriginalHistorySize4; + vec4 OriginalHistorySize5; + float RESSWITCH_ENABLE; + float RESSWITCH_GLITCH_TRESHOLD; + float RESSWITCH_GLITCH_BAR; + float RESSWITCH_GLITCH_SHAKE_MAX; +} global; + +#pragma parameter RESSWITCH_ENABLE "★ Resolution switch glitch enable? ==>" 1.0 0.0 1.0 1.0 +#pragma parameter RESSWITCH_GLITCH_TRESHOLD " Glitch if vertical resolution changes at least by" 50.0 1.0 1000.0 5.0 +#pragma parameter RESSWITCH_GLITCH_BAR " Bright glitch bars strength" 0.2 0.0 1.0 0.01 +#pragma parameter RESSWITCH_GLITCH_SHAKE_MAX " Screen shake amplitude" 0.2 0.0 1.0 0.01 + +#pragma stage vertex +layout(location = 0) in vec4 Position; +layout(location = 1) in vec2 TexCoord; +layout(location = 0) out vec2 vTexCoord; +layout(location = 1) out float vSwitchres_show_bar; + +void main() { + gl_Position = global.MVP * Position; + vTexCoord = TexCoord * 1.0001; + + vSwitchres_show_bar = 0.0; + if (global.RESSWITCH_ENABLE > 0.5 ) { + if (abs(global.SourceSize.y - global.OriginalHistorySize1.y) > global.RESSWITCH_GLITCH_TRESHOLD) { + //first frame + vSwitchres_show_bar = global.RESSWITCH_GLITCH_BAR; + vTexCoord.y += global.RESSWITCH_GLITCH_SHAKE_MAX * +1.0 ; + } + else if (abs(global.SourceSize.y - global.OriginalHistorySize2.y) > global.RESSWITCH_GLITCH_TRESHOLD) { + vSwitchres_show_bar = global.RESSWITCH_GLITCH_BAR; + vTexCoord.y += global.RESSWITCH_GLITCH_SHAKE_MAX * -1.0; + } + else if (abs(global.SourceSize.y - global.OriginalHistorySize3.y) > global.RESSWITCH_GLITCH_TRESHOLD) { + vSwitchres_show_bar = global.RESSWITCH_GLITCH_BAR; + vTexCoord.y += global.RESSWITCH_GLITCH_SHAKE_MAX * +0.5; + } + else if (abs(global.SourceSize.y - global.OriginalHistorySize4.y) > global.RESSWITCH_GLITCH_TRESHOLD) { + vSwitchres_show_bar = global.RESSWITCH_GLITCH_BAR; + vTexCoord.y += global.RESSWITCH_GLITCH_SHAKE_MAX * -0.5; + } + else if (abs(global.SourceSize.y - global.OriginalHistorySize5.y) > global.RESSWITCH_GLITCH_TRESHOLD) { + //last frame + vTexCoord.y += global.RESSWITCH_GLITCH_SHAKE_MAX * +0.25; + vSwitchres_show_bar = global.RESSWITCH_GLITCH_BAR; + } + } +} + +#pragma stage fragment +layout(location = 0) in vec2 vTexCoord; +layout(location = 1) in float vSwitchres_show_bar; +layout(location = 0) out vec4 FragColor; + +layout(set = 0, binding = 1) uniform sampler2D Source; + +#define _3kPI 3.141592653589793 + +void main() { + float switchresglitch = 0.0; + + if (vTexCoord.y < 0.0 ||vTexCoord.y > 1.0 ) + switchresglitch = sin( vTexCoord.y * _3kPI * (2/global.RESSWITCH_GLITCH_SHAKE_MAX) ) * vSwitchres_show_bar; + + FragColor = texture(Source, vTexCoord) + switchresglitch; +}