From e534206eb60dd5ab7d7b356a1c6d24c4d7f70106 Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Fri, 13 Jan 2023 17:37:08 -0800 Subject: [PATCH] Small style change to get_xy_to_uv --- manimlib/shaders/inserts/get_xy_to_uv.glsl | 25 ++++++++----------- .../shaders/quadratic_bezier_fill/geom.glsl | 2 +- .../shaders/quadratic_bezier_stroke/geom.glsl | 2 +- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/manimlib/shaders/inserts/get_xy_to_uv.glsl b/manimlib/shaders/inserts/get_xy_to_uv.glsl index 15c1702b..5f3e2deb 100644 --- a/manimlib/shaders/inserts/get_xy_to_uv.glsl +++ b/manimlib/shaders/inserts/get_xy_to_uv.glsl @@ -8,7 +8,7 @@ vec2 complex_div(vec2 v, vec2 w){ } -vec2 xs_on_clean_parabola(vec2 controls[3]){ +vec2 xs_on_clean_parabola(vec2 b0, vec2 b1, vec2 b2){ /* Given three control points for a quadratic bezier, this returns the two values (x0, x2) such that the @@ -17,10 +17,6 @@ vec2 xs_on_clean_parabola(vec2 controls[3]){ Adapated from https://github.com/raphlinus/raphlinus.github.io/blob/master/_posts/2019-12-23-flatten-quadbez.md */ - vec2 b0 = controls[0]; - vec2 b1 = controls[1]; - vec2 b2 = controls[2]; - vec2 dd = normalize(2 * b1 - b0 - b2); float u0 = dot(b1 - b0, dd); @@ -59,35 +55,34 @@ mat3 map_point_pairs(vec2 src0, vec2 src1, vec2 dest0, vec2 dest1){ } -mat3 get_xy_to_uv(vec2 controls[3], float temp_is_linear, out float is_linear){ +mat3 get_xy_to_uv(vec2 b0, vec2 b1, vec2 b2, float temp_is_linear, out float is_linear){ /* Returns a matrix for an affine transformation which maps a set of quadratic bezier controls points into a new coordinate system such that the bezier curve coincides with y = x^2, or in the case of a linear curve, it's mapped to the x-axis. */ - vec2[2] dest; + vec2 dest0; + vec2 dest1; is_linear = temp_is_linear; // Portions of the parabola y = x^2 where abs(x) exceeds // this value are treated as straight lines. float thresh = 2.0; if (!bool(is_linear)){ - vec2 xs = xs_on_clean_parabola(controls); + vec2 xs = xs_on_clean_parabola(b0, b1, b2); float x0 = xs.x; float x2 = xs.y; if((x0 > thresh && x2 > thresh) || (x0 < -thresh && x2 < -thresh)){ is_linear = 1.0; }else{ - dest[0] = vec2(x0, x0 * x0); - dest[1] = vec2(x2, x2 * x2); + dest0 = vec2(x0, x0 * x0); + dest1 = vec2(x2, x2 * x2); } } // Check if is_linear status changed above if (bool(is_linear)){ - dest[0] = vec2(0, 0); - dest[1] = vec2(1, 0); + dest0 = vec2(0, 0); + dest1 = vec2(1, 0); } - return map_point_pairs( - controls[0], controls[2], dest[0], dest[1] - ); + return map_point_pairs(b0, b2, dest0, dest1); } diff --git a/manimlib/shaders/quadratic_bezier_fill/geom.glsl b/manimlib/shaders/quadratic_bezier_fill/geom.glsl index 7b0918d4..41af86db 100644 --- a/manimlib/shaders/quadratic_bezier_fill/geom.glsl +++ b/manimlib/shaders/quadratic_bezier_fill/geom.glsl @@ -96,7 +96,7 @@ void emit_pentagon(vec3 p0, vec3 p1, vec3 p2, vec3 normal){ } // Compute xy_to_uv matrix, and potentially re-evaluate bezier degree - mat3 xy_to_uv = get_xy_to_uv(vec2[3](p0.xy, p1.xy, p2.xy), is_linear, is_linear); + mat3 xy_to_uv = get_xy_to_uv(p0.xy, p1.xy, p2.xy, is_linear, is_linear); uv_anti_alias_width = aaw * length(xy_to_uv[0].xy); for(int i = 0; i < 5; i++){ diff --git a/manimlib/shaders/quadratic_bezier_stroke/geom.glsl b/manimlib/shaders/quadratic_bezier_stroke/geom.glsl index 49cdf275..609c8c80 100644 --- a/manimlib/shaders/quadratic_bezier_stroke/geom.glsl +++ b/manimlib/shaders/quadratic_bezier_stroke/geom.glsl @@ -164,7 +164,7 @@ void main() { // coincides with y = x^2, between some values x0 and x2. Or, in // the case of a linear curve (bezier degree 1), just put it on // the segment from (0, 0) to (1, 0) - mat3 xy_to_uv = get_xy_to_uv(vec2[3](p0.xy, p1.xy, p2.xy), is_linear, is_linear); + mat3 xy_to_uv = get_xy_to_uv(p0.xy, p1.xy, p2.xy, is_linear, is_linear); float uv_scale_factor = length(xy_to_uv[0].xy); float scaled_aaw = anti_alias_width * (frame_shape.y / pixel_shape.y);