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

37 lines
666 B
Text
Raw Normal View History

2020-02-03 10:52:39 -08:00
#version 330
#INSERT camera_uniform_declarations.glsl
2020-06-02 16:18:44 -07:00
2020-02-03 10:52:39 -08:00
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 bezier_degree;
out vec4 frag_color;
float sdf(){
float x0 = uv_coords.x;
float y0 = uv_coords.y;
if(bezier_degree == 1.0){
return abs(y0);
}
float Fxy = y0 - x0 * x0;
if(orientation * Fxy >= 0){
return 0.0;
2020-06-09 12:34:00 -07:00
}
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;
if (fill_all == 1.0) return;
2020-02-03 10:52:39 -08:00
frag_color.a *= smoothstep(1, 0, sdf() / uv_anti_alias_width);
}