3b1b-manim/manimlib/shaders/quadratic_bezier_fill/frag.glsl

30 lines
593 B
Text
Raw Normal View History

2020-02-03 10:52:39 -08:00
#version 330
in vec4 color;
2021-11-01 13:05:13 -07:00
in float fill_all; // Either 0 or 1
2020-02-03 10:52:39 -08:00
in float uv_anti_alias_width;
in float orientation;
2020-02-03 10:52:39 -08:00
in vec2 uv_coords;
in float is_linear;
2020-02-03 10:52:39 -08:00
out vec4 frag_color;
float sdf(float x0, float y0){
if(bool(is_linear)) return abs(y0);
float Fxy = y0 - x0 * x0;
if(orientation * Fxy >= 0) return 0.0;
return abs(Fxy) / sqrt(1 + 4 * x0 * x0);
2020-02-03 10:52:39 -08:00
}
void main() {
if (color.a == 0) discard;
frag_color = color;
2023-01-10 09:49:51 -08:00
if (bool(fill_all)) return;
float dist = sdf(uv_coords.x, uv_coords.y);
frag_color.a *= smoothstep(1, 0, dist / uv_anti_alias_width);
}