mirror of
https://github.com/3b1b/manim.git
synced 2025-09-19 04:41:56 +00:00
Fix thin stroke issue for low resolutions
This commit is contained in:
parent
df0ae6fdc9
commit
04347e7876
2 changed files with 7 additions and 8 deletions
|
@ -2,16 +2,16 @@
|
||||||
|
|
||||||
// Value between -1 and 1
|
// Value between -1 and 1
|
||||||
in float scaled_signed_dist_to_curve;
|
in float scaled_signed_dist_to_curve;
|
||||||
in float scaled_anti_alias_width;
|
in float anti_alias_prop;
|
||||||
in vec4 color;
|
in vec4 color;
|
||||||
|
|
||||||
out vec4 frag_color;
|
out vec4 frag_color;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
if(scaled_anti_alias_width < 0) discard;
|
if(anti_alias_prop < 0) discard;
|
||||||
frag_color = color;
|
frag_color = color;
|
||||||
|
|
||||||
// sdf for the region around the curve we wish to 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;
|
float signed_dist_to_region = abs(scaled_signed_dist_to_curve) - 1.0;
|
||||||
frag_color.a *= smoothstep(0, -scaled_anti_alias_width, signed_dist_to_region);
|
frag_color.a *= smoothstep(0, -anti_alias_prop, signed_dist_to_region);
|
||||||
}
|
}
|
|
@ -16,7 +16,7 @@ in float v_stroke_width[3];
|
||||||
in vec4 v_color[3];
|
in vec4 v_color[3];
|
||||||
|
|
||||||
out vec4 color;
|
out vec4 color;
|
||||||
out float scaled_anti_alias_width;
|
out float anti_alias_prop;
|
||||||
out float scaled_signed_dist_to_curve;
|
out float scaled_signed_dist_to_curve;
|
||||||
|
|
||||||
// Codes for joint types
|
// Codes for joint types
|
||||||
|
@ -167,9 +167,8 @@ void emit_point_with_width(
|
||||||
|
|
||||||
// Set styling
|
// Set styling
|
||||||
color = finalize_color(joint_color, point, unit_normal);
|
color = finalize_color(joint_color, point, unit_normal);
|
||||||
scaled_anti_alias_width = (width == 0) ?
|
float aaw = anti_alias_width * pixel_size;
|
||||||
-1.0 : // Signal to discard in the frag shader
|
anti_alias_prop = (width == 0) ? -1.0 : 2 * aaw / (width + 2 * aaw);
|
||||||
2.0 * anti_alias_width * pixel_size / width;
|
|
||||||
|
|
||||||
// Figure out the step from the point to the corners of the
|
// Figure out the step from the point to the corners of the
|
||||||
// triangle strip around the polyline
|
// triangle strip around the polyline
|
||||||
|
@ -180,7 +179,7 @@ void emit_point_with_width(
|
||||||
// reflecting where in the stroke that point is
|
// reflecting where in the stroke that point is
|
||||||
for (int sign = -1; sign <= 1; sign += 2){
|
for (int sign = -1; sign <= 1; sign += 2){
|
||||||
scaled_signed_dist_to_curve = sign;
|
scaled_signed_dist_to_curve = sign;
|
||||||
emit_gl_Position(point + 0.5 * width * sign * step);
|
emit_gl_Position(point + 0.5 * (width + aaw) * sign * step);
|
||||||
EmitVertex();
|
EmitVertex();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue