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

46 lines
1.1 KiB
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 vec2 uv_coords;
in vec2 uv_b2;
in float uv_stroke_width;
in vec4 color;
in float uv_anti_alias_width;
in float has_prev;
in float has_next;
in float bezier_degree;
out vec4 frag_color;
2023-01-08 23:33:39 -05:00
#INSERT quadratic_bezier_distance.glsl
float dist_to_curve(){
float dist = min_dist_to_curve(uv_coords, uv_b2, bezier_degree);
if(has_prev == 0 && uv_coords.x < 0){
float buff = 0.5 * uv_stroke_width - uv_anti_alias_width;
return max(-uv_coords.x + buff, dist);
}
if(has_next == 0 && uv_coords.x > uv_b2.x){
float buff = 0.5 * uv_stroke_width - uv_anti_alias_width;
vec2 v12 = normalize(uv_b2 - vec2(1, 0));
float perp_dist = dot(uv_coords - uv_b2, v12);
if (perp_dist > 0) return max(perp_dist + buff, dist);
}
return dist;
}
2020-02-03 10:52:39 -08:00
void main() {
if (uv_stroke_width == 0) discard;
2023-01-08 23:33:39 -05:00
2020-02-03 10:52:39 -08:00
// An sdf for the region around the curve we wish to color.
2023-01-08 23:33:39 -05:00
float signed_dist = abs(dist_to_curve()) - 0.5 * uv_stroke_width;
frag_color = color;
2020-02-03 10:52:39 -08:00
frag_color.a *= smoothstep(0.5, -0.5, signed_dist / uv_anti_alias_width);
}