mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Small style tweaks to quadratic_bezier_fill/geom
This commit is contained in:
parent
e832bb775f
commit
394d87effb
3 changed files with 26 additions and 30 deletions
|
@ -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);
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue