From 82582d08bd40270ad89a2d95d26b3d6d2cc305bd Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Tue, 20 Aug 2024 13:32:52 -0500 Subject: [PATCH] Fewer parameters for stroke frag shader --- manimlib/shaders/quadratic_bezier/stroke/frag.glsl | 14 ++++++-------- manimlib/shaders/quadratic_bezier/stroke/geom.glsl | 12 ++++++------ 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/manimlib/shaders/quadratic_bezier/stroke/frag.glsl b/manimlib/shaders/quadratic_bezier/stroke/frag.glsl index 7fb668aa..a26b2334 100644 --- a/manimlib/shaders/quadratic_bezier/stroke/frag.glsl +++ b/manimlib/shaders/quadratic_bezier/stroke/frag.glsl @@ -1,18 +1,16 @@ #version 330 -// Value between -1 and 1 -in float dist_to_curve; -in float half_stroke_width; -in float half_anti_alias_width; +// Distance to the curve, and half the curve width, both as +// a ratio of the antialias width +in float dist_to_aaw; +in float half_width_to_aaw; in vec4 color; out vec4 frag_color; void main() { - 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(dist_to_curve) - half_stroke_width; - frag_color.a *= smoothstep(half_anti_alias_width, -half_anti_alias_width, signed_dist_to_region); + float signed_dist_to_region = abs(dist_to_aaw) - half_width_to_aaw; + frag_color.a *= smoothstep(0.5, -0.5, signed_dist_to_region); } \ No newline at end of file diff --git a/manimlib/shaders/quadratic_bezier/stroke/geom.glsl b/manimlib/shaders/quadratic_bezier/stroke/geom.glsl index a34db252..d4667bdd 100644 --- a/manimlib/shaders/quadratic_bezier/stroke/geom.glsl +++ b/manimlib/shaders/quadratic_bezier/stroke/geom.glsl @@ -17,9 +17,8 @@ in vec4 v_color[3]; in int v_vert_index[3]; out vec4 color; -out float dist_to_curve; -out float half_stroke_width; -out float half_anti_alias_width; +out float dist_to_aaw; +out float half_width_to_aaw; // Codes for joint types const int NO_JOINT = 0; @@ -169,19 +168,20 @@ void emit_point_with_width( // Set styling color = finalize_color(joint_color, point, unit_normal); - 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 vec3 step = step_to_corner(point, tangent, unit_normal, joint_product, inside_curve); + float aaw = max(anti_alias_width * pixel_size, 1e-8); // Emit two corners // 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){ - dist_to_curve = sign * (half_stroke_width + half_anti_alias_width); + float dist_to_curve = sign * 0.5 * (width + aaw); emit_gl_Position(point + dist_to_curve * step); + half_width_to_aaw = 0.5 * width / aaw; + dist_to_aaw = dist_to_curve / aaw; EmitVertex(); } }