From 2f63837430409d04030d259f079b1794761ccff7 Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Sun, 18 Apr 2021 01:43:28 -0400 Subject: [PATCH] pico stage shader --- source/PlayState.hx | 12 ++++++- source/TitleState.hx | 7 ++++ source/shaderslmfao/BuildingShaders.hx | 49 ++++++++++++++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 source/shaderslmfao/BuildingShaders.hx diff --git a/source/PlayState.hx b/source/PlayState.hx index 3c407fcf0..8924cdb92 100644 --- a/source/PlayState.hx +++ b/source/PlayState.hx @@ -43,6 +43,8 @@ import openfl.display.BitmapData; import openfl.display.BlendMode; import openfl.display.StageQuality; import openfl.filters.ShaderFilter; +import shaderslmfao.BuildingShaders.BuildingShader; +import shaderslmfao.BuildingShaders; import shaderslmfao.ColorSwap; import ui.PreferencesMenu; @@ -157,6 +159,7 @@ class PlayState extends MusicBeatState #end var camPos:FlxPoint; + var lightFadeShader:BuildingShaders; override public function create() { @@ -254,7 +257,9 @@ class PlayState extends MusicBeatState city.updateHitbox(); add(city); + lightFadeShader = new BuildingShaders(); phillyCityLights = new FlxTypedGroup(); + add(phillyCityLights); for (i in 0...5) @@ -265,6 +270,7 @@ class PlayState extends MusicBeatState light.setGraphicSize(Std.int(light.width * 0.85)); light.updateHitbox(); light.antialiasing = true; + light.shader = lightFadeShader.shader; phillyCityLights.add(light); } @@ -936,6 +942,7 @@ class PlayState extends MusicBeatState var vid:FlxVideo = new FlxVideo('music/ughCutscene.mp4'); vid.finishCallback = function() { + FlxTween.tween(FlxG.camera, {zoom: defaultCamZoom}, (Conductor.crochet / 1000) * 5, {ease: FlxEase.quadInOut}); startCountdown(); cameraMovement(); }; @@ -1942,7 +1949,8 @@ class PlayState extends MusicBeatState trainFrameTiming = 0; } } - // phillyCityLights.members[curLight].alpha -= (Conductor.crochet / 1000) * FlxG.elapsed; + + lightFadeShader.update((Conductor.crochet / 1000) * FlxG.elapsed * 1.5); // phillyCityLights.members[curLight].alpha -= (Conductor.crochet / 1000) * FlxG.elapsed; } super.update(elapsed); @@ -3002,6 +3010,8 @@ class PlayState extends MusicBeatState if (curBeat % 4 == 0) { + lightFadeShader.reset(); + phillyCityLights.forEach(function(light:FlxSprite) { light.visible = false; diff --git a/source/TitleState.hx b/source/TitleState.hx index 189639df3..66d9ba8f8 100644 --- a/source/TitleState.hx +++ b/source/TitleState.hx @@ -29,6 +29,8 @@ import openfl.events.NetStatusEvent; import openfl.media.Video; import openfl.net.NetConnection; import openfl.net.NetStream; +import shaderslmfao.BuildingShaders.BuildingShader; +import shaderslmfao.BuildingShaders; import shaderslmfao.ColorSwap; import ui.PreferencesMenu; @@ -57,6 +59,7 @@ class TitleState extends MusicBeatState var wackyImage:FlxSprite; var lastBeat:Int = 0; var swagShader:ColorSwap; + var alphaShader:BuildingShaders; var thingie:FlxSprite; var video:Video; @@ -73,6 +76,7 @@ class TitleState extends MusicBeatState FlxG.game.focusLostFramerate = 60; swagShader = new ColorSwap(); + alphaShader = new BuildingShaders(); FlxG.sound.muteKeys = [ZERO]; @@ -249,6 +253,7 @@ class TitleState extends MusicBeatState logoBl.updateHitbox(); logoBl.shader = swagShader.shader; + // logoBl.shader = alphaShader.shader; // trace(); // logoBl.screenCenter(); @@ -465,11 +470,13 @@ class TitleState extends MusicBeatState if (controls.UI_LEFT) { swagShader.update(-elapsed * 0.1); + // alphaShader.update(-elapsed * 0.1); } if (controls.UI_RIGHT) { swagShader.update(elapsed * 0.1); + // alphaShader.update(elapsed * 0.1); } super.update(elapsed); diff --git a/source/shaderslmfao/BuildingShaders.hx b/source/shaderslmfao/BuildingShaders.hx new file mode 100644 index 000000000..8106967d1 --- /dev/null +++ b/source/shaderslmfao/BuildingShaders.hx @@ -0,0 +1,49 @@ +package shaderslmfao; + +import flixel.system.FlxAssets.FlxShader; + +class BuildingShaders +{ + public var shader(default, null):BuildingShader; + public var daAlpha:Float = 1; + + public function new():Void + { + shader = new BuildingShader(); + shader.alphaShit.value = [0]; + } + + public function update(elapsed:Float):Void + { + shader.alphaShit.value[0] += elapsed; + } + + public function reset() + { + shader.alphaShit.value[0] = 0; + } +} + +class BuildingShader extends FlxShader +{ + @:glFragmentSource(' + #pragma header + + uniform float alphaShit; + + void main() + { + vec4 color = flixel_texture2D(bitmap, openfl_TextureCoordv); + + if (color.a > 0.0) + color -= alphaShit; + + gl_FragColor = color; + } + + ') + public function new() + { + super(); + } +}