2023-11-07 09:04:22 +00:00
|
|
|
package funkin.graphics.shaders;
|
2021-10-22 03:08:48 +00:00
|
|
|
|
|
|
|
import flixel.system.FlxAssets.FlxShader;
|
2024-08-30 00:03:11 +00:00
|
|
|
import flixel.util.FlxColor;
|
2021-10-22 03:08:48 +00:00
|
|
|
|
|
|
|
class AngleMask extends FlxShader
|
|
|
|
{
|
2024-08-30 00:03:11 +00:00
|
|
|
public var extraColor(default, set):FlxColor = 0xFFFFFFFF;
|
|
|
|
|
|
|
|
function set_extraColor(value:FlxColor):FlxColor
|
|
|
|
{
|
|
|
|
extraTint.value = [value.redFloat, value.greenFloat, value.blueFloat];
|
|
|
|
this.extraColor = value;
|
|
|
|
|
|
|
|
return this.extraColor;
|
|
|
|
}
|
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
@:glFragmentSource('
|
2024-06-11 19:57:45 +00:00
|
|
|
#pragma header
|
2021-10-22 03:08:48 +00:00
|
|
|
|
2024-08-30 00:03:11 +00:00
|
|
|
uniform vec3 extraTint;
|
|
|
|
|
2024-06-11 19:57:45 +00:00
|
|
|
uniform vec2 endPosition;
|
|
|
|
vec2 hash22(vec2 p) {
|
|
|
|
vec3 p3 = fract(vec3(p.xyx) * vec3(.1031, .1030, .0973));
|
|
|
|
p3 += dot(p3, p3.yzx + 33.33);
|
|
|
|
return fract((p3.xx + p3.yz) * p3.zy);
|
|
|
|
}
|
2021-10-22 03:08:48 +00:00
|
|
|
|
2023-06-08 20:30:45 +00:00
|
|
|
|
2021-10-22 03:08:48 +00:00
|
|
|
|
2024-06-11 19:57:45 +00:00
|
|
|
// ====== GAMMA CORRECTION ====== //
|
|
|
|
// Helps with color mixing -- good to have by default in almost any shader
|
|
|
|
// See https://www.shadertoy.com/view/lscSzl
|
|
|
|
vec3 gamma(in vec3 color) {
|
|
|
|
return pow(color, vec3(1.0 / 2.2));
|
|
|
|
}
|
2021-10-22 03:08:48 +00:00
|
|
|
|
2024-06-11 19:57:45 +00:00
|
|
|
vec4 mainPass(vec2 fragCoord) {
|
|
|
|
vec4 base = texture2D(bitmap, fragCoord);
|
2021-10-22 03:08:48 +00:00
|
|
|
|
2024-06-11 19:57:45 +00:00
|
|
|
vec2 uv = fragCoord.xy;
|
2021-10-22 03:08:48 +00:00
|
|
|
|
2024-06-11 19:57:45 +00:00
|
|
|
vec2 start = vec2(0.0, 0.0);
|
|
|
|
vec2 end = vec2(endPosition.x / openfl_TextureSize.x, 1.0);
|
2021-10-22 03:08:48 +00:00
|
|
|
|
2024-06-11 19:57:45 +00:00
|
|
|
float dx = end.x - start.x;
|
|
|
|
float dy = end.y - start.y;
|
2021-10-22 03:08:48 +00:00
|
|
|
|
2024-06-11 19:57:45 +00:00
|
|
|
float angle = atan(dy, dx);
|
2021-10-22 03:08:48 +00:00
|
|
|
|
2024-06-11 19:57:45 +00:00
|
|
|
uv.x -= start.x;
|
|
|
|
uv.y -= start.y;
|
|
|
|
|
|
|
|
float uvA = atan(uv.y, uv.x);
|
|
|
|
|
|
|
|
if (uvA < angle)
|
|
|
|
return base;
|
|
|
|
else
|
|
|
|
return vec4(0.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
vec4 antialias(vec2 fragCoord) {
|
|
|
|
|
|
|
|
const float AA_STAGES = 2.0;
|
|
|
|
|
|
|
|
const float AA_TOTAL_PASSES = AA_STAGES * AA_STAGES + 1.0;
|
|
|
|
const float AA_JITTER = 0.5;
|
|
|
|
|
|
|
|
// Run the shader multiple times with a random subpixel offset each time and average the results
|
|
|
|
vec4 color = mainPass(fragCoord);
|
|
|
|
for (float x = 0.0; x < AA_STAGES; x++)
|
|
|
|
{
|
|
|
|
for (float y = 0.0; y < AA_STAGES; y++)
|
|
|
|
{
|
|
|
|
vec2 offset = AA_JITTER * (2.0 * hash22(vec2(x, y)) - 1.0) / openfl_TextureSize.xy;
|
|
|
|
color += mainPass(fragCoord + offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return color / AA_TOTAL_PASSES;
|
|
|
|
}
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
vec4 col = antialias(openfl_TextureCoordv);
|
2024-08-30 00:03:11 +00:00
|
|
|
col.xyz = col.xyz * extraTint.xyz;
|
2024-06-11 19:57:45 +00:00
|
|
|
// col.xyz = gamma(col.xyz);
|
|
|
|
gl_FragColor = col;
|
|
|
|
}')
|
2023-01-23 03:25:45 +00:00
|
|
|
public function new()
|
|
|
|
{
|
|
|
|
super();
|
2021-10-22 03:08:48 +00:00
|
|
|
|
2023-01-23 03:25:45 +00:00
|
|
|
endPosition.value = [90, 100]; // 100 AS DEFAULT WORKS NICELY FOR FREEPLAY?
|
2024-08-30 00:03:11 +00:00
|
|
|
extraTint.value = [1, 1, 1];
|
2023-01-23 03:25:45 +00:00
|
|
|
}
|
2021-10-22 03:08:48 +00:00
|
|
|
}
|