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; } ')