From 671046a6d5e75b3af9a68d72ff52ab9dc83def14 Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Sat, 20 Mar 2021 14:55:29 -0400 Subject: [PATCH 1/4] SHADERRRR --- source/TitleState.hx | 13 +++++--- source/shaderslmfao/ColorSwap.hx | 52 ++++++++++++++------------------ 2 files changed, 32 insertions(+), 33 deletions(-) diff --git a/source/TitleState.hx b/source/TitleState.hx index fef57d275..23b5eac82 100644 --- a/source/TitleState.hx +++ b/source/TitleState.hx @@ -1,9 +1,5 @@ package; -#if desktop -import Discord.DiscordClient; -import sys.thread.Thread; -#end import flixel.FlxG; import flixel.FlxSprite; import flixel.addons.transition.FlxTransitionSprite.GraphicTransTileDiamond; @@ -21,9 +17,15 @@ import flixel.util.FlxTimer; import io.newgrounds.NG; import lime.app.Application; import openfl.Assets; +import shaderslmfao.ColorSwap; using StringTools; +#if desktop +import Discord.DiscordClient; +import sys.thread.Thread; +#end + class TitleState extends MusicBeatState { static var initialized:Bool = false; @@ -158,6 +160,9 @@ class TitleState extends MusicBeatState gfDance.animation.addByIndices('danceRight', 'gfDance', [15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29], "", 24, false); gfDance.antialiasing = true; add(gfDance); + + gfDance.shader = new ColorSwap().shader; + add(logoBl); titleText = new FlxSprite(100, FlxG.height * 0.8); diff --git a/source/shaderslmfao/ColorSwap.hx b/source/shaderslmfao/ColorSwap.hx index 4d2eac78e..cb2e2bcde 100644 --- a/source/shaderslmfao/ColorSwap.hx +++ b/source/shaderslmfao/ColorSwap.hx @@ -12,18 +12,12 @@ class ColorSwap public function new():Void { shader = new ColorSwapShader(); - shader.colorOld.value = []; - shader.colorNew.value = []; } function set_colorToReplace(color:FlxColor):FlxColor { colorToReplace = color; - shader.colorOld.value[0] = color.red; - shader.colorOld.value[1] = color.green; - shader.colorOld.value[2] = color.blue; - return color; } @@ -31,10 +25,6 @@ class ColorSwap { newColor = color; - shader.colorNew.value[0] = color.red; - shader.colorNew.value[1] = color.green; - shader.colorNew.value[2] = color.blue; - return color; } } @@ -44,10 +34,6 @@ class ColorSwapShader extends FlxShader @:glFragmentSource(' #pragma header - uniform vec3 colorOld; - uniform vec3 colorNew; - uniform float u_time; - vec3 normalizeColor(vec3 color) { return vec3( @@ -57,29 +43,37 @@ class ColorSwapShader extends FlxShader ); } - vec3 hueShift(vec3 color, float hue) { - const vec3 k = vec3(0.57735, 0.57735, 0.57735); - float cosAngle = cos(hue); - return vec3(color * cosAngle + cross(k, color) * sin(hue) + k * dot(k, color) * (1.0 - cosAngle)); + 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() { - vec4 pixel = texture2D(bitmap, openfl_TextureCoordv); + vec4 color = flixel_texture2D(bitmap, openfl_TextureCoordv); - vec3 eps = vec3(0.02, 0.02, 0.02); + vec4 swagColor = vec4(rgb2hsv(vec3(color[0], color[1], color[2])), color[3]); + + // [0] is the hue??? + swagColor[0] += 2; + // swagColor[1] += 0.5; - vec3 colorOldNormalized = normalizeColor(colorOld); - vec3 colorNewNormalized = normalizeColor(colorNew); + color = vec4(hsv2rgb(vec3(swagColor[0], swagColor[1], swagColor[2])), swagColor[3]); - if (all(greaterThanEqual(pixel, vec4(colorOldNormalized - eps, 1.0)) ) && all(lessThanEqual(pixel, vec4(colorOldNormalized + eps, 1.0)) ) - ) - { - pixel = vec4(hueShift(colorOldNormalized, 0.7), 1.0); - } - - gl_FragColor = pixel; + gl_FragColor = color; } ') From c80d8cc09ef88e97aaf2bf288964eefa05def28f Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Sat, 20 Mar 2021 15:20:00 -0400 Subject: [PATCH 2/4] shader bullshit --- source/TitleState.hx | 10 +++++++++- source/shaderslmfao/ColorSwap.hx | 19 +++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/source/TitleState.hx b/source/TitleState.hx index 23b5eac82..b825af96e 100644 --- a/source/TitleState.hx +++ b/source/TitleState.hx @@ -42,12 +42,16 @@ class TitleState extends MusicBeatState var lastBeat:Int = 0; + // var swagShader:ColorSwap; + override public function create():Void { #if polymod polymod.Polymod.init({modRoot: "mods", dirs: ['introMod'], framework: OPENFL}); #end + // swagShader = new ColorSwap(); + FlxG.sound.muteKeys = [ZERO]; PlayerSettings.init(); @@ -150,6 +154,8 @@ class TitleState extends MusicBeatState logoBl.animation.play('bump'); logoBl.updateHitbox(); + // logoBl.shader = swagShader.shader; + // trace(); // logoBl.screenCenter(); // logoBl.color = FlxColor.BLACK; @@ -161,7 +167,7 @@ class TitleState extends MusicBeatState gfDance.antialiasing = true; add(gfDance); - gfDance.shader = new ColorSwap().shader; + // gfDance.shader = swagShader.shader; add(logoBl); @@ -364,6 +370,8 @@ class TitleState extends MusicBeatState { super.beatHit(); + // swagShader.update(FlxG.random.float(0.1, 0.7)); + logoBl.animation.play('bump', true); danceLeft = !danceLeft; diff --git a/source/shaderslmfao/ColorSwap.hx b/source/shaderslmfao/ColorSwap.hx index cb2e2bcde..ff13871b3 100644 --- a/source/shaderslmfao/ColorSwap.hx +++ b/source/shaderslmfao/ColorSwap.hx @@ -8,10 +8,17 @@ class ColorSwap public var shader(default, null):ColorSwapShader; public var colorToReplace(default, set):FlxColor; public var newColor(default, set):FlxColor; + public var daTime(default, set):Float; public function new():Void { shader = new ColorSwapShader(); + shader.uTime.value = [0]; + } + + public function update(elapsed:Float):Void + { + shader.uTime.value[0] += elapsed; } function set_colorToReplace(color:FlxColor):FlxColor @@ -21,6 +28,11 @@ class ColorSwap return color; } + function set_daTime(daTime:Float):Float + { + return daTime; + } + function set_newColor(color:FlxColor):FlxColor { newColor = color; @@ -34,6 +46,9 @@ class ColorSwapShader extends FlxShader @:glFragmentSource(' #pragma header + + uniform float uTime; + vec3 normalizeColor(vec3 color) { return vec3( @@ -68,8 +83,8 @@ class ColorSwapShader extends FlxShader vec4 swagColor = vec4(rgb2hsv(vec3(color[0], color[1], color[2])), color[3]); // [0] is the hue??? - swagColor[0] += 2; - // swagColor[1] += 0.5; + swagColor[0] += uTime; + // swagColor[1] += uTime; color = vec4(hsv2rgb(vec3(swagColor[0], swagColor[1], swagColor[2])), swagColor[3]); From 75ed1d52313b741c8692191353ad1af2d2451eec Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Sun, 21 Mar 2021 14:45:46 -0400 Subject: [PATCH 3/4] color swap shit in progress --- source/ColorpickSubstate.hx | 56 ++++++++++++++++++++++++++++++++ source/Note.hx | 17 +++++++--- source/OptionsSubState.hx | 5 ++- source/TitleState.hx | 22 +++++++++---- source/shaderslmfao/ColorSwap.hx | 8 ++++- 5 files changed, 96 insertions(+), 12 deletions(-) create mode 100644 source/ColorpickSubstate.hx diff --git a/source/ColorpickSubstate.hx b/source/ColorpickSubstate.hx new file mode 100644 index 000000000..b39957de5 --- /dev/null +++ b/source/ColorpickSubstate.hx @@ -0,0 +1,56 @@ +package; + +import flixel.group.FlxGroup.FlxTypedGroup; +import shaderslmfao.ColorSwap; + +class ColorpickSubstate extends MusicBeatSubstate +{ + var curSelected:Int = 0; + + var grpNotes:FlxTypedGroup; + + public function new() + { + super(); + + grpNotes = new FlxTypedGroup(); + add(grpNotes); + + for (i in 0...4) + { + var note:Note = new Note(0, i); + + note.x = (100 * i) + i; + note.screenCenter(Y); + + grpNotes.add(note); + } + } + + override function update(elapsed:Float) + { + if (controls.RIGHT_P) + curSelected += 1; + if (controls.LEFT_P) + curSelected -= 1; + + if (curSelected < 0) + curSelected = grpNotes.members.length - 1; + if (curSelected >= grpNotes.members.length) + curSelected = 0; + + if (controls.UP) + { + grpNotes.members[curSelected].colorSwap.update(elapsed * 0.3); + Note.arrowColors[curSelected] += elapsed * 0.3; + } + + if (controls.DOWN) + { + grpNotes.members[curSelected].colorSwap.update(-elapsed * 0.3); + Note.arrowColors[curSelected] += -elapsed * 0.3; + } + + super.update(elapsed); + } +} diff --git a/source/Note.hx b/source/Note.hx index 9659ad3c0..c39bf8bc1 100644 --- a/source/Note.hx +++ b/source/Note.hx @@ -28,6 +28,7 @@ class Note extends FlxSprite public var sustainLength:Float = 0; public var isSustainNote:Bool = false; + public var colorSwap:ColorSwap; public var noteScore:Float = 1; public static var swagWidth:Float = 160 * 0.7; @@ -36,6 +37,8 @@ class Note extends FlxSprite public static var BLUE_NOTE:Int = 1; public static var RED_NOTE:Int = 3; + public static var arrowColors:Array = [1, 1, 1, 1]; + public function new(strumTime:Float, noteData:Int, ?prevNote:Note, ?sustainNote:Bool = false) { super(); @@ -105,10 +108,6 @@ class Note extends FlxSprite updateHitbox(); antialiasing = true; - var colorSwap = new ColorSwap(); - - // shader = colorSwap.shader; - // colorSwap.colorToReplace = 0xFFF9393F; // colorSwap.newColor = 0xFF00FF00; @@ -117,11 +116,15 @@ class Note extends FlxSprite // replaceColor(0xFFC1C1C1, FlxColor.RED); } + colorSwap = new ColorSwap(); + shader = colorSwap.shader; + switch (noteData) { case 0: x += swagWidth * 0; animation.play('purpleScroll'); + case 1: x += swagWidth * 1; animation.play('blueScroll'); @@ -155,6 +158,7 @@ class Note extends FlxSprite } updateHitbox(); + updateColors(); x -= width / 2; @@ -182,6 +186,11 @@ class Note extends FlxSprite } } + public function updateColors():Void + { + colorSwap.update(arrowColors[noteData]); + } + override function update(elapsed:Float) { super.update(elapsed); diff --git a/source/OptionsSubState.hx b/source/OptionsSubState.hx index 00ca548f1..323094b7e 100644 --- a/source/OptionsSubState.hx +++ b/source/OptionsSubState.hx @@ -8,7 +8,7 @@ import flixel.util.FlxColor; class OptionsSubState extends MusicBeatSubstate { - var textMenuItems:Array = ['Master Volume', 'Sound Volume', 'Controls']; + var textMenuItems:Array = ['Master Volume', 'Sound Volume', 'Controls', 'Colors']; var selector:FlxSprite; var curSelected:Int = 0; @@ -67,6 +67,9 @@ class OptionsSubState extends MusicBeatSubstate { switch (textMenuItems[curSelected]) { + case "Colors": + FlxG.state.closeSubState(); + FlxG.state.openSubState(new ColorpickSubstate()); case "Controls": FlxG.state.closeSubState(); FlxG.state.openSubState(new ControlsSubState()); diff --git a/source/TitleState.hx b/source/TitleState.hx index b825af96e..ca5340b93 100644 --- a/source/TitleState.hx +++ b/source/TitleState.hx @@ -42,7 +42,7 @@ class TitleState extends MusicBeatState var lastBeat:Int = 0; - // var swagShader:ColorSwap; + var swagShader:ColorSwap; override public function create():Void { @@ -50,7 +50,7 @@ class TitleState extends MusicBeatState polymod.Polymod.init({modRoot: "mods", dirs: ['introMod'], framework: OPENFL}); #end - // swagShader = new ColorSwap(); + swagShader = new ColorSwap(); FlxG.sound.muteKeys = [ZERO]; @@ -154,7 +154,7 @@ class TitleState extends MusicBeatState logoBl.animation.play('bump'); logoBl.updateHitbox(); - // logoBl.shader = swagShader.shader; + logoBl.shader = swagShader.shader; // trace(); // logoBl.screenCenter(); @@ -167,7 +167,7 @@ class TitleState extends MusicBeatState gfDance.antialiasing = true; add(gfDance); - // gfDance.shader = swagShader.shader; + gfDance.shader = swagShader.shader; add(logoBl); @@ -333,6 +333,16 @@ class TitleState extends MusicBeatState skipIntro(); } + if (controls.LEFT) + { + swagShader.update(-elapsed * 0.1); + } + + if (controls.RIGHT) + { + swagShader.update(elapsed * 0.1); + } + super.update(elapsed); } @@ -366,12 +376,12 @@ class TitleState extends MusicBeatState } } + var isRainbow:Bool = false; + override function beatHit() { super.beatHit(); - // swagShader.update(FlxG.random.float(0.1, 0.7)); - logoBl.animation.play('bump', true); danceLeft = !danceLeft; diff --git a/source/shaderslmfao/ColorSwap.hx b/source/shaderslmfao/ColorSwap.hx index ff13871b3..1f57dc7a0 100644 --- a/source/shaderslmfao/ColorSwap.hx +++ b/source/shaderslmfao/ColorSwap.hx @@ -9,16 +9,20 @@ class ColorSwap public var colorToReplace(default, set):FlxColor; public var newColor(default, set):FlxColor; public var daTime(default, set):Float; + public var hueShit:Float = 0; public function new():Void { shader = new ColorSwapShader(); shader.uTime.value = [0]; + shader.money.value = [0]; } public function update(elapsed:Float):Void { shader.uTime.value[0] += elapsed; + hueShit += elapsed; + // trace(shader.money.value[0]); } function set_colorToReplace(color:FlxColor):FlxColor @@ -46,8 +50,8 @@ class ColorSwapShader extends FlxShader @:glFragmentSource(' #pragma header - uniform float uTime; + uniform float money; vec3 normalizeColor(vec3 color) { @@ -86,6 +90,8 @@ class ColorSwapShader extends FlxShader swagColor[0] += uTime; // swagColor[1] += uTime; + // money += swagColor[0]; + color = vec4(hsv2rgb(vec3(swagColor[0], swagColor[1], swagColor[2])), swagColor[3]); gl_FragColor = color; From dd49ae79902ca28ced625c4b2a98602e3fb9554b Mon Sep 17 00:00:00 2001 From: Cameron Taylor Date: Sun, 21 Mar 2021 16:29:47 -0400 Subject: [PATCH 4/4] note color bullshit and also disabled 'stuns'?? --- source/ColorpickSubstate.hx | 7 +++++++ source/Note.hx | 2 +- source/OptionsSubState.hx | 7 ++++++- source/PlayState.hx | 16 ++++++++++++---- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/source/ColorpickSubstate.hx b/source/ColorpickSubstate.hx index b39957de5..6123acc9b 100644 --- a/source/ColorpickSubstate.hx +++ b/source/ColorpickSubstate.hx @@ -1,5 +1,6 @@ package; +import flixel.FlxG; import flixel.group.FlxGroup.FlxTypedGroup; import shaderslmfao.ColorSwap; @@ -29,6 +30,12 @@ class ColorpickSubstate extends MusicBeatSubstate override function update(elapsed:Float) { + if (controls.BACK) + { + FlxG.state.closeSubState(); + FlxG.state.openSubState(new OptionsSubState()); + } + if (controls.RIGHT_P) curSelected += 1; if (controls.LEFT_P) diff --git a/source/Note.hx b/source/Note.hx index c39bf8bc1..786a23e53 100644 --- a/source/Note.hx +++ b/source/Note.hx @@ -118,6 +118,7 @@ class Note extends FlxSprite colorSwap = new ColorSwap(); shader = colorSwap.shader; + updateColors(); switch (noteData) { @@ -158,7 +159,6 @@ class Note extends FlxSprite } updateHitbox(); - updateColors(); x -= width / 2; diff --git a/source/OptionsSubState.hx b/source/OptionsSubState.hx index 323094b7e..ee27bdfc1 100644 --- a/source/OptionsSubState.hx +++ b/source/OptionsSubState.hx @@ -8,7 +8,7 @@ import flixel.util.FlxColor; class OptionsSubState extends MusicBeatSubstate { - var textMenuItems:Array = ['Master Volume', 'Sound Volume', 'Controls', 'Colors']; + var textMenuItems:Array = ['Master Volume', 'Sound Volume', 'Controls', 'Colors', 'Back']; var selector:FlxSprite; var curSelected:Int = 0; @@ -63,6 +63,9 @@ class OptionsSubState extends MusicBeatSubstate txt.color = FlxColor.YELLOW; }); + if (controls.BACK) + FlxG.switchState(new MainMenuState()); + if (controls.ACCEPT) { switch (textMenuItems[curSelected]) @@ -76,6 +79,8 @@ class OptionsSubState extends MusicBeatSubstate case "Mods": FlxG.state.closeSubState(); FlxG.state.openSubState(new ModdingSubstate()); + case "Back": + FlxG.switchState(new MainMenuState()); } } } diff --git a/source/PlayState.hx b/source/PlayState.hx index afbdc4d82..013a8c2de 100644 --- a/source/PlayState.hx +++ b/source/PlayState.hx @@ -1,8 +1,5 @@ package; -#if desktop -import Discord.DiscordClient; -#end import Section.SwagSection; import Song.SwagSong; import WiggleEffect.WiggleEffectType; @@ -41,9 +38,14 @@ import lime.utils.Assets; import openfl.display.BlendMode; import openfl.display.StageQuality; import openfl.filters.ShaderFilter; +import shaderslmfao.ColorSwap; using StringTools; +#if desktop +import Discord.DiscordClient; +#end + class PlayState extends MusicBeatState { public static var curStage:String = ''; @@ -1189,6 +1191,9 @@ class PlayState extends MusicBeatState { // FlxG.log.add(i); var babyArrow:FlxSprite = new FlxSprite(0, strumLine.y); + var colorswap:ColorSwap = new ColorSwap(); + babyArrow.shader = colorswap.shader; + colorswap.update(Note.arrowColors[i]); switch (curStage) { @@ -2007,8 +2012,11 @@ class PlayState extends MusicBeatState var controlArray:Array = [leftP, downP, upP, rightP]; // FlxG.watch.addQuick('asdfa', upP); - if ((upP || rightP || downP || leftP) && !boyfriend.stunned && generatedMusic) + if ((upP || rightP || downP || leftP) && generatedMusic) { + // note to self, used to have stunned + // && !boyfriend.stunned + boyfriend.holdTimer = 0; var possibleNotes:Array = [];