2023-11-07 04:04:22 -05:00
|
|
|
package funkin.graphics.shaders;
|
2021-10-21 23:08:48 -04:00
|
|
|
|
|
|
|
import flixel.system.FlxAssets.FlxShader;
|
|
|
|
|
|
|
|
class AngleMask extends FlxShader
|
|
|
|
{
|
2023-01-22 22:25:45 -05:00
|
|
|
@:glFragmentSource('
|
2024-06-11 15:57:45 -04:00
|
|
|
#pragma header
|
2021-10-21 23:08:48 -04:00
|
|
|
|
2024-06-11 15:57:45 -04: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-21 23:08:48 -04:00
|
|
|
|
2023-06-08 16:30:45 -04:00
|
|
|
|
2021-10-21 23:08:48 -04:00
|
|
|
|
2024-06-11 15:57:45 -04: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-21 23:08:48 -04:00
|
|
|
|
2024-06-11 15:57:45 -04:00
|
|
|
vec4 mainPass(vec2 fragCoord) {
|
|
|
|
vec4 base = texture2D(bitmap, fragCoord);
|
2021-10-21 23:08:48 -04:00
|
|
|
|
2024-06-11 15:57:45 -04:00
|
|
|
vec2 uv = fragCoord.xy;
|
2021-10-21 23:08:48 -04:00
|
|
|
|
2024-06-11 15:57:45 -04:00
|
|
|
vec2 start = vec2(0.0, 0.0);
|
|
|
|
vec2 end = vec2(endPosition.x / openfl_TextureSize.x, 1.0);
|
2021-10-21 23:08:48 -04:00
|
|
|
|
2024-06-11 15:57:45 -04:00
|
|
|
float dx = end.x - start.x;
|
|
|
|
float dy = end.y - start.y;
|
2021-10-21 23:08:48 -04:00
|
|
|
|
2024-06-11 15:57:45 -04:00
|
|
|
float angle = atan(dy, dx);
|
2021-10-21 23:08:48 -04:00
|
|
|
|
2024-06-11 15:57:45 -04: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);
|
|
|
|
// col.xyz = gamma(col.xyz);
|
|
|
|
gl_FragColor = col;
|
|
|
|
}')
|
2023-01-22 22:25:45 -05:00
|
|
|
public function new()
|
|
|
|
{
|
|
|
|
super();
|
2021-10-21 23:08:48 -04:00
|
|
|
|
2023-01-22 22:25:45 -05:00
|
|
|
endPosition.value = [90, 100]; // 100 AS DEFAULT WORKS NICELY FOR FREEPLAY?
|
|
|
|
}
|
2021-10-21 23:08:48 -04:00
|
|
|
}
|