diff --git a/manimlib/shaders/quadratic_bezier_fill/geom.glsl b/manimlib/shaders/quadratic_bezier_fill/geom.glsl index 183d634e..a8eed5a4 100644 --- a/manimlib/shaders/quadratic_bezier_fill/geom.glsl +++ b/manimlib/shaders/quadratic_bezier_fill/geom.glsl @@ -67,28 +67,25 @@ void emit_simple_triangle(){ } -void emit_pentagon(vec3[3] points){ - vec2 p0 = points[0].xy; - vec2 p1 = points[1].xy; - vec2 p2 = points[2].xy; +void emit_pentagon(vec3[3] points, vec3 normal){ + vec3 p0 = points[0]; + vec3 p1 = points[1]; + vec3 p2 = points[2]; // Tangent vectors - vec2 t01 = normalize(p1 - p0); - vec2 t12 = normalize(p2 - p1); + vec3 t01 = normalize(p1 - p0); + vec3 t12 = normalize(p2 - p1); - // Vectors perpendicular to the curve in the plane - // of the curve pointing outside the curve - float cross_prod = cross2d(t01, t12); - float sgn = cross_prod >= 0.0 ? 1.0 : -1.0; - vec2 p0_perp = sgn * vec2(t01.y, -t01.x); - vec2 p2_perp = sgn * vec2(t12.y, -t12.x); + // Vectors perpendicular to the curve in the plane of the curve pointing outside the curve + vec3 p0_perp = cross(t01, normal); + vec3 p2_perp = cross(t12, normal); - float angle = asin(clamp(cross_prod, -1, 1)); - is_linear = float(abs(angle) < ANGLE_THRESHOLD); + float angle = acos(clamp(dot(t01, t12), -1, 1)); + is_linear = float(angle < ANGLE_THRESHOLD); bool fill_inside = orientation > 0.0; float aaw = anti_alias_width * frame_shape.y / pixel_shape.y; - vec2 corners[5] = vec2[5](p0, p0, p1, p2, p2); + vec3 corners[5] = vec3[5](p0, p0, p1, p2, p2); if(fill_inside || bool(is_linear)){ // Add buffer outside the curve @@ -103,13 +100,13 @@ void emit_pentagon(vec3[3] points){ } // Compute xy_to_uv matrix, and potentially re-evaluate bezier degree - mat3 xy_to_uv = get_xy_to_uv(vec2[3](p0, p1, p2), is_linear, is_linear); + mat3 xy_to_uv = get_xy_to_uv(vec2[3](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++){ int j = int(sign(i - 1) + 1); // Maps i = [0, 1, 2, 3, 4] onto j = [0, 0, 1, 2, 2] - vec3 corner = vec3(corners[i], points[j].z); - uv_coords = (xy_to_uv * vec3(corners[i], 1.0)).xy; + vec3 corner = corners[i]; + uv_coords = (xy_to_uv * vec3(corner.xy, 1.0)).xy; emit_vertex_wrapper(corner, j); } EndPrimitive(); @@ -132,6 +129,6 @@ void main(){ unit_normal = get_unit_normal(verts); orientation = v_orientation[0]; - emit_pentagon(verts); + emit_pentagon(verts, unit_normal); }