mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Fix zero stroke width issue
This commit is contained in:
parent
108db87087
commit
d8edccdab4
2 changed files with 13 additions and 11 deletions
|
@ -1,17 +1,18 @@
|
|||
#version 330
|
||||
|
||||
// Value between -1 and 1
|
||||
in float scaled_signed_dist_to_curve;
|
||||
in float anti_alias_prop;
|
||||
in float dist_to_curve;
|
||||
in float half_stroke_width;
|
||||
in float half_anti_alias_width;
|
||||
in vec4 color;
|
||||
|
||||
out vec4 frag_color;
|
||||
|
||||
void main() {
|
||||
if(anti_alias_prop < 0) discard;
|
||||
if(half_stroke_width == 0) discard;
|
||||
frag_color = color;
|
||||
|
||||
// sdf for the region around the curve we wish to color.
|
||||
float signed_dist_to_region = abs(scaled_signed_dist_to_curve) - 1.0;
|
||||
frag_color.a *= smoothstep(0, -anti_alias_prop, signed_dist_to_region);
|
||||
float signed_dist_to_region = abs(dist_to_curve) - half_stroke_width;
|
||||
frag_color.a *= smoothstep(half_anti_alias_width, -half_anti_alias_width, signed_dist_to_region);
|
||||
}
|
|
@ -16,8 +16,9 @@ in float v_stroke_width[3];
|
|||
in vec4 v_color[3];
|
||||
|
||||
out vec4 color;
|
||||
out float anti_alias_prop;
|
||||
out float scaled_signed_dist_to_curve;
|
||||
out float dist_to_curve;
|
||||
out float half_stroke_width;
|
||||
out float half_anti_alias_width;
|
||||
|
||||
// Codes for joint types
|
||||
const int NO_JOINT = 0;
|
||||
|
@ -167,8 +168,8 @@ void emit_point_with_width(
|
|||
|
||||
// Set styling
|
||||
color = finalize_color(joint_color, point, unit_normal);
|
||||
float aaw = anti_alias_width * pixel_size;
|
||||
anti_alias_prop = (width == 0) ? -1.0 : 2 * aaw / (width + 2 * aaw);
|
||||
half_anti_alias_width = 0.5 * anti_alias_width * pixel_size;
|
||||
half_stroke_width = 0.5 * width;
|
||||
|
||||
// Figure out the step from the point to the corners of the
|
||||
// triangle strip around the polyline
|
||||
|
@ -178,8 +179,8 @@ void emit_point_with_width(
|
|||
// The frag shader will receive a value from -1 to 1,
|
||||
// reflecting where in the stroke that point is
|
||||
for (int sign = -1; sign <= 1; sign += 2){
|
||||
scaled_signed_dist_to_curve = sign;
|
||||
emit_gl_Position(point + 0.5 * (width + aaw) * sign * step);
|
||||
dist_to_curve = sign * (half_stroke_width + half_anti_alias_width);
|
||||
emit_gl_Position(point + dist_to_curve * step);
|
||||
EmitVertex();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue