Funkin/source/shaderslmfao/ColorSwap.hx

160 lines
4.3 KiB
Haxe
Raw Normal View History

package shaderslmfao;
import flixel.system.FlxAssets.FlxShader;
import flixel.util.FlxColor;
class ColorSwap
{
public var shader(default, null):ColorSwapShader;
public var colorToReplace(default, set):FlxColor;
public var newColor(default, set):FlxColor;
2021-03-20 15:20:00 -04:00
public var daTime(default, set):Float;
2021-03-24 18:41:54 -04:00
public var hasOutline(default, set):Bool = false;
2021-03-21 14:45:46 -04:00
public var hueShit:Float = 0;
public function new():Void
{
shader = new ColorSwapShader();
2021-03-20 15:20:00 -04:00
shader.uTime.value = [0];
2021-03-21 14:45:46 -04:00
shader.money.value = [0];
2021-03-24 18:41:54 -04:00
shader.awesomeOutline.value = [hasOutline];
2021-03-20 15:20:00 -04:00
}
public function update(elapsed:Float):Void
{
shader.uTime.value[0] += elapsed;
2021-03-21 14:45:46 -04:00
hueShit += elapsed;
// trace(shader.money.value[0]);
}
function set_colorToReplace(color:FlxColor):FlxColor
{
colorToReplace = color;
return color;
}
2021-03-24 18:41:54 -04:00
function set_hasOutline(lol:Bool):Bool
{
shader.awesomeOutline.value = [lol];
return lol;
}
2021-03-20 15:20:00 -04:00
function set_daTime(daTime:Float):Float
{
return daTime;
}
function set_newColor(color:FlxColor):FlxColor
{
newColor = color;
return color;
}
}
class ColorSwapShader extends FlxShader
{
@:glFragmentSource('
#pragma header
2021-03-20 15:20:00 -04:00
uniform float uTime;
2021-03-21 14:45:46 -04:00
uniform float money;
2021-03-24 18:41:54 -04:00
uniform bool awesomeOutline;
2021-03-20 15:20:00 -04:00
2021-03-23 18:43:08 -04:00
const float offset = 1.0 / 128.0;
2021-03-24 18:41:54 -04:00
2021-03-23 18:43:08 -04:00
vec3 normalizeColor(vec3 color)
{
return vec3(
color[0] / 255.0,
color[1] / 255.0,
color[2] / 255.0
);
}
2021-03-20 14:55:29 -04:00
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);
}
2021-03-20 14:55:29 -04:00
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()
{
2021-03-20 14:55:29 -04:00
vec4 color = flixel_texture2D(bitmap, openfl_TextureCoordv);
2021-03-20 14:55:29 -04:00
vec4 swagColor = vec4(rgb2hsv(vec3(color[0], color[1], color[2])), color[3]);
// [0] is the hue???
2021-03-20 15:20:00 -04:00
swagColor[0] += uTime;
// swagColor[1] += uTime;
2021-03-21 14:45:46 -04:00
// money += swagColor[0];
2021-03-20 14:55:29 -04:00
color = vec4(hsv2rgb(vec3(swagColor[0], swagColor[1], swagColor[2])), swagColor[3]);
2021-03-24 18:41:54 -04:00
if (awesomeOutline)
{
// Outline bullshit?
vec2 size = vec2(3, 3);
if (color.a <= 0.5) {
float w = size.x / openfl_TextureSize.x;
float h = size.y / openfl_TextureSize.y;
if (flixel_texture2D(bitmap, vec2(openfl_TextureCoordv.x + w, openfl_TextureCoordv.y)).a != 0.
|| flixel_texture2D(bitmap, vec2(openfl_TextureCoordv.x - w, openfl_TextureCoordv.y)).a != 0.
|| flixel_texture2D(bitmap, vec2(openfl_TextureCoordv.x, openfl_TextureCoordv.y + h)).a != 0.
|| flixel_texture2D(bitmap, vec2(openfl_TextureCoordv.x, openfl_TextureCoordv.y - h)).a != 0.)
color = vec4(1.0, 1.0, 1.0, 1.0);
}
}
2021-03-23 21:33:17 -04:00
gl_FragColor = color;
/*
2021-03-23 18:43:08 -04:00
if (color.a > 0.5)
gl_FragColor = color;
else
{
float a = flixel_texture2D(bitmap, vec2(openfl_TextureCoordv + offset, openfl_TextureCoordv.y)).a +
flixel_texture2D(bitmap, vec2(openfl_TextureCoordv, openfl_TextureCoordv.y - offset)).a +
flixel_texture2D(bitmap, vec2(openfl_TextureCoordv - offset, openfl_TextureCoordv.y)).a +
flixel_texture2D(bitmap, vec2(openfl_TextureCoordv, openfl_TextureCoordv.y + offset)).a;
if (color.a < 1.0 && a > 0.0)
gl_FragColor = vec4(0.0, 0.0, 0.0, 0.8);
else
gl_FragColor = color;
2021-03-24 18:41:54 -04:00
} */
}
')
public function new()
{
super();
}
}