diff --git a/manimlib/shaders/quadratic_bezier_stroke/frag.glsl b/manimlib/shaders/quadratic_bezier_stroke/frag.glsl index 38a295b9..ca95938b 100644 --- a/manimlib/shaders/quadratic_bezier_stroke/frag.glsl +++ b/manimlib/shaders/quadratic_bezier_stroke/frag.glsl @@ -12,18 +12,21 @@ out vec4 frag_color; const float QUICK_DIST_WIDTH = 0.2; -// Distance from (x0, y0) to the curve y = x^2 -float dist_to_curve(float x0, float y0){ +float dist_to_curve(){ + // Returns distance from uv_coords to the curve v = u^2 + float x0 = uv_coords.x; + float y0 = uv_coords.y; + // In the linear case, the curve will have // been set to equal the x axis - if(bool(is_linear)) return y0; + if(bool(is_linear)) return abs(y0); if(uv_stroke_width < QUICK_DIST_WIDTH){ // This is a quick approximation for computing // the distance to the curve. // Evaluate F(x, y) = y - x^2 // divide by its gradient's magnitude - return (y0 - x0 * x0) / sqrt(1 + 4 * x0 * x0); + return abs((y0 - x0 * x0) / sqrt(1 + 4 * x0 * x0)); } // Otherwise, solve for the minimal distance. // The distance squared between (x0, y0) and a point (x, x^2) looks like @@ -50,9 +53,8 @@ float dist_to_curve(float x0, float y0){ void main() { if (uv_stroke_width == 0) discard; - // Compute sdf for the region around the curve we wish to color. - float dist = dist_to_curve(uv_coords.x, uv_coords.y); - float signed_dist = abs(dist) - 0.5 * uv_stroke_width; + // sdf for the region around the curve we wish to color. + float signed_dist = dist_to_curve() - 0.5 * uv_stroke_width; frag_color = color; frag_color.a *= smoothstep(0.5, -0.5, signed_dist / uv_anti_alias_width);