diff --git a/manimlib/shaders/quadratic_bezier_fill/frag.glsl b/manimlib/shaders/quadratic_bezier_fill/frag.glsl index 73d5c5e4..517da8ec 100644 --- a/manimlib/shaders/quadratic_bezier_fill/frag.glsl +++ b/manimlib/shaders/quadratic_bezier_fill/frag.glsl @@ -10,14 +10,11 @@ in vec3 xyz_coords; in float orientation; in vec2 uv_coords; in vec2 uv_b2; +in vec2 simp_coords; in float bezier_degree; out vec4 frag_color; -// Needed for quadratic_bezier_distance insertion below -float modify_distance_for_endpoints(vec2 p, float dist, float t){ - return dist; -} #INSERT quadratic_bezier_distance.glsl @@ -32,17 +29,10 @@ float sdf(){ if(abs(v2 / u2) < 0.1 * uv_anti_alias_width){ return abs(uv_coords[1]); } - // This converts uv_coords to yet another space where the bezier points sit on - // (0, 0), (1/2, 0) and (1, 1), so that the curve can be expressed implicityly - // as y = x^2. - mat2 to_simple_space = mat2( - v2, 0, - 2 - u2, 4 * v2 - ); - vec2 p = to_simple_space * uv_coords; + vec2 p = simp_coords; + float Fp = (p.x * p.x - p.y); // Sign takes care of whether we should be filling the inside or outside of curve. float sgn = orientation * sign(v2); - float Fp = (p.x * p.x - p.y); if(sgn * Fp <= 0){ return 0.0; }else{ diff --git a/manimlib/shaders/quadratic_bezier_fill/geom.glsl b/manimlib/shaders/quadratic_bezier_fill/geom.glsl index 96ff1978..60ce7d1b 100644 --- a/manimlib/shaders/quadratic_bezier_fill/geom.glsl +++ b/manimlib/shaders/quadratic_bezier_fill/geom.glsl @@ -31,6 +31,7 @@ out float orientation; // uv space is where b0 = (0, 0), b1 = (1, 0), and transform is orthogonal out vec2 uv_coords; out vec2 uv_b2; +out vec2 simp_coords; out float bezier_degree; vec3 unit_normal; @@ -114,9 +115,18 @@ void emit_pentagon(vec3[3] points, vec3 normal){ uv_b2 = (xyz_to_uv * vec4(p2, 1)).xy; uv_anti_alias_width = aaw / length(p1 - p0); + // Matrix from the uv space to an even simpler + // one where the curve is equal to y = x^2 + mat2 to_simple_space = mat2( + uv_b2.y, 0, + 2 - uv_b2.x, 4 * uv_b2.y + ); + // + for(int i = 0; i < 5; i++){ vec3 corner = corners[i]; uv_coords = (xyz_to_uv * vec4(corner, 1)).xy; + simp_coords = to_simple_space * uv_coords; int j = int(sign(i - 1) + 1); // Maps i = [0, 1, 2, 3, 4] onto j = [0, 0, 1, 2, 2] emit_vertex_wrapper(corner, j); }