diff --git a/manimlib/shaders/inserts/get_xy_to_uv.glsl b/manimlib/shaders/inserts/get_xy_to_uv.glsl index 1b09ce32..1880919b 100644 --- a/manimlib/shaders/inserts/get_xy_to_uv.glsl +++ b/manimlib/shaders/inserts/get_xy_to_uv.glsl @@ -1,32 +1,3 @@ -float cross2d(vec2 v, vec2 w){ - return v.x * w.y - w.x * v.y; -} - - -vec2 complex_div(vec2 v, vec2 w){ - return vec2(dot(v, w), cross2d(w, v)) / dot(w, w); -} - - -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 - section of the parabola y = x^2 between those values - is isometric to the given quadratic bezier. - - Adapated from https://github.com/raphlinus/raphlinus.github.io/blob/master/_posts/2019-12-23-flatten-quadbez.md - */ - vec2 dd = normalize(2 * b1 - b0 - b2); - - float u0 = dot(b1 - b0, dd); - float u2 = dot(b2 - b1, dd); - float cp = cross2d(b2 - b0, dd); - - return vec2(u0 / cp, u2 / cp); -} - - vec2 xs_on_clean_parabola(vec3 b0, vec3 b1, vec3 b2){ /* Given three control points for a quadratic bezier, @@ -47,34 +18,6 @@ vec2 xs_on_clean_parabola(vec3 b0, vec3 b1, vec3 b2){ } -mat3 map_point_pairs(vec2 src0, vec2 src1, vec2 dst0, vec2 dst1){ - /* - Returns an orthogonal matrix which will map - src0 onto dst0 and src1 onto dst1. - */ - mat3 shift1 = mat3( - 1.0, 0.0, 0.0, - 0.0, 1.0, 0.0, - -src0.x, -src0.y, 1.0 - ); - mat3 shift2 = mat3( - 1.0, 0.0, 0.0, - 0.0, 1.0, 0.0, - dst0.x, dst0.y, 1.0 - ); - - // Compute complex division dest_vect / src_vect to determine rotation - vec2 complex_rot = complex_div(dst1 - dst0, src1 - src0); - mat3 rotate = mat3( - complex_rot.x, complex_rot.y, 0.0, - -complex_rot.y, complex_rot.x, 0.0, - 0.0, 0.0, 1.0 - ); - - return shift2 * rotate * shift1; -} - - mat4 map_triangles(vec3 src0, vec3 src1, vec3 src2, vec3 dst0, vec3 dst1, vec3 dst2){ /* Return an affine transform which maps the triangle (src0, src1, src2) @@ -179,36 +122,3 @@ mat4 get_xyz_to_uv(vec3 b0, vec3 b1, vec3 b2, float temp_is_linear, out float is // return map_point_pairs(b0, b2, dst0, dst1); return map_triangles(b0, b1, b2, dst0, dst1, dst2); } - - -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 dst0; - vec2 dst1; - 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(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{ - dst0 = vec2(x0, x0 * x0); - dst1 = vec2(x2, x2 * x2); - } - } - // Check if is_linear status changed above - if (bool(is_linear)){ - dst0 = vec2(0, 0); - dst1 = vec2(1, 0); - } - - return map_point_pairs(b0, b2, dst0, dst1); -}