From f3bf578d4e4901ef326b8c8211118665f160b474 Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Sat, 11 Sep 2021 14:08:34 -0400 Subject: [PATCH] screen wipe shader stuff testing --- source/MainMenuState.hx | 15 ++++++ source/shaderslmfao/ScreenWipeShader.hx | 72 +++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 source/shaderslmfao/ScreenWipeShader.hx diff --git a/source/MainMenuState.hx b/source/MainMenuState.hx index 3ae385080..f52018913 100644 --- a/source/MainMenuState.hx +++ b/source/MainMenuState.hx @@ -16,6 +16,8 @@ import flixel.ui.FlxButton; import flixel.util.FlxColor; import flixel.util.FlxTimer; import lime.app.Application; +import openfl.filters.ShaderFilter; +import shaderslmfao.ScreenWipeShader; import ui.AtlasMenuList; import ui.MenuList; import ui.OptionsState; @@ -250,6 +252,19 @@ class MainMenuState extends MusicBeatState override function update(elapsed:Float) { + if (FlxG.keys.justPressed.N) + { + var screenShit:FlxSprite = new FlxSprite().loadGraphic(Paths.image("shaderTransitionStuff/coolDots")); + + var screenWipeShit:ScreenWipeShader = new ScreenWipeShader(); + + screenWipeShit.funnyShit.input = screenShit.pixels; + + FlxTween.tween(screenWipeShit, {daAlphaShit: 1}, 2, {ease: FlxEase.quadInOut}); + + FlxG.camera.setFilters([new ShaderFilter(screenWipeShit)]); + } + if (FlxG.onMobile) { var touch:FlxTouch = FlxG.touches.getFirst(); diff --git a/source/shaderslmfao/ScreenWipeShader.hx b/source/shaderslmfao/ScreenWipeShader.hx new file mode 100644 index 000000000..5264f7c33 --- /dev/null +++ b/source/shaderslmfao/ScreenWipeShader.hx @@ -0,0 +1,72 @@ +package shaderslmfao; + +import flixel.system.FlxAssets.FlxShader; + +class ScreenWipeShader extends FlxShader +{ + public var daAlphaShit(default, set):Float = 0; + + function set_daAlphaShit(alpha:Float):Float + { + alphaShit.value[0] = alpha; + + return alpha; + } + + @:glFragmentSource(' + #pragma header + + uniform float alphaShit; + uniform float yPos; + uniform float xPos; + + uniform sampler2D funnyShit; + + + vec3 rgb2hsv(vec3 c) + { + vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); + vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g)); + vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r)); + + float d = q.x - min(q.w, q.y); + float e = 1.0e-10; + return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x); + } + + vec3 hsv2rgb(vec3 c) + { + vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); + vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); + return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); + } + + void main() + { + vec2 funnyUv = openfl_TextureCoordv; + vec4 color = flixel_texture2D(bitmap, funnyUv); + + vec2 reallyFunnyUv = vec2(vec2(0.0, 0.0) - gl_FragCoord.xy / openfl_TextureSize.xy); + + vec4 gf = flixel_texture2D(funnyShit, openfl_TextureCoordv); + + + vec3 hsvTypeBeat = rgb2hsv(vec3(gf.r, gf.g, gf.b)); + + vec4 output = color; + + // .b here actually means value? + if (hsvTypeBeat.b <= alphaShit) + color = vec4(0.0, 0.0, 0.0, 0.0); + + + gl_FragColor = color; + } + ') + public function new() + { + super(); + + alphaShit.value = [0]; + } +}