From 394d87effb99bea1d935a82b730ca2ba3edf9a4b Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Fri, 13 Jan 2023 17:26:59 -0800 Subject: [PATCH] Small style tweaks to quadratic_bezier_fill/geom --- manimlib/shaders/inserts/get_unit_normal.glsl | 34 +++++++++---------- .../shaders/quadratic_bezier_fill/geom.glsl | 18 +++++----- .../shaders/quadratic_bezier_fill/vert.glsl | 4 +-- 3 files changed, 26 insertions(+), 30 deletions(-) diff --git a/manimlib/shaders/inserts/get_unit_normal.glsl b/manimlib/shaders/inserts/get_unit_normal.glsl index f5d43382..879871d8 100644 --- a/manimlib/shaders/inserts/get_unit_normal.glsl +++ b/manimlib/shaders/inserts/get_unit_normal.glsl @@ -1,22 +1,20 @@ -vec3 get_unit_normal(in vec3[3] points){ +vec3 get_unit_normal(vec3 p0, vec3 p1, vec3 p2){ float tol = 1e-6; - vec3 v1 = normalize(points[1] - points[0]); - vec3 v2 = normalize(points[2] - points[1]); + vec3 v1 = normalize(p1 - p0); + vec3 v2 = normalize(p2 - p1); vec3 cp = cross(v1, v2); float cp_norm = length(cp); - if(cp_norm < tol){ - // Three points form a line, so find a normal vector - // to that line in the plane shared with the z-axis - vec3 k_hat = vec3(0.0, 0.0, 1.0); - vec3 comb = v1 + v2; - vec3 new_cp = cross(cross(comb, k_hat), comb); - float new_cp_norm = length(new_cp); - if(new_cp_norm < tol){ - // We only come here if all three points line up - // on the z-axis. - return vec3(0.0, -1.0, 0.0); - } - return new_cp / new_cp_norm; - } - return cp / cp_norm; + + if(cp_norm > tol) return cp / cp_norm; + + // Otherwise, three pionts form a line, so find + // a normal vector to that line in the plane shared + // with the z-axis + vec3 comb = v1 + v2; + cp = cross(cross(comb, vec3(0.0, 0.0, 1.0)), comb); + cp_norm = length(cp); + if(cp_norm > tol) return cp / cp_norm; + + // Otherwise, the points line up with the z-axis. + return vec3(0.0, -1.0, 0.0); } \ No newline at end of file diff --git a/manimlib/shaders/quadratic_bezier_fill/geom.glsl b/manimlib/shaders/quadratic_bezier_fill/geom.glsl index 7f53a8a7..7b0918d4 100644 --- a/manimlib/shaders/quadratic_bezier_fill/geom.glsl +++ b/manimlib/shaders/quadratic_bezier_fill/geom.glsl @@ -17,7 +17,7 @@ uniform float reflectiveness; uniform float gloss; uniform float shadow; -in vec3 bp[3]; +in vec3 verts[3]; in float v_orientation[3]; in vec4 v_color[3]; in float v_vert_index[3]; @@ -61,17 +61,13 @@ void emit_vertex_wrapper(vec3 point, int index){ void emit_simple_triangle(){ for(int i = 0; i < 3; i++){ - emit_vertex_wrapper(bp[i], i); + emit_vertex_wrapper(verts[i], i); } EndPrimitive(); } -void emit_pentagon(vec3[3] points, vec3 normal){ - vec3 p0 = points[0]; - vec3 p1 = points[1]; - vec3 p2 = points[2]; - +void emit_pentagon(vec3 p0, vec3 p1, vec3 p2, vec3 normal){ // Tangent vectors vec3 t01 = normalize(p1 - p0); vec3 t12 = normalize(p2 - p1); @@ -125,10 +121,12 @@ void main(){ return; } - vec3[3] verts = vec3[3](bp[0], bp[1], bp[2]); - unit_normal = get_unit_normal(verts); + vec3 p0 = verts[0]; + vec3 p1 = verts[1]; + vec3 p2 = verts[2]; + unit_normal = get_unit_normal(p0, p1, p2); orientation = v_orientation[1]; - emit_pentagon(verts, unit_normal); + emit_pentagon(p0, p1, p2, unit_normal); } diff --git a/manimlib/shaders/quadratic_bezier_fill/vert.glsl b/manimlib/shaders/quadratic_bezier_fill/vert.glsl index 2a0fc1a2..2c0ca1c3 100644 --- a/manimlib/shaders/quadratic_bezier_fill/vert.glsl +++ b/manimlib/shaders/quadratic_bezier_fill/vert.glsl @@ -7,7 +7,7 @@ in float orientation; in vec4 color; in float vert_index; -out vec3 bp; // Bezier control point +out vec3 verts; // Bezier control point out float v_orientation; out vec4 v_color; out float v_vert_index; @@ -16,7 +16,7 @@ out float v_vert_index; #INSERT position_point_into_frame.glsl void main(){ - bp = position_point_into_frame(point); + verts = position_point_into_frame(point); v_orientation = orientation; v_color = color; v_vert_index = vert_index;