Delete get_reduced_control_points

This commit is contained in:
Grant Sanderson 2023-01-09 00:00:31 -05:00
parent 47d0dca087
commit a6e5f25912
2 changed files with 6 additions and 50 deletions

View file

@ -46,47 +46,3 @@ mat4 get_xyz_to_uv(vec3 b0, vec3 b1, vec3 unit_normal){
);
return (1.0 / scale_factor) * rotate * shift;
}
// Returns 0 for null curve, 1 for linear, 2 for quadratic.
// Populates new_points with bezier control points for the curve,
// which for quadratics will be the same, but for linear and null
// might change. The idea is to inform the caller of the degree,
// while also passing tangency information in the linear case.
// float get_reduced_control_points(vec3 b0, vec3 b1, vec3 b2, out vec3 new_points[3]){
float get_reduced_control_points(in vec3 points[3], out vec3 new_points[3]){
float length_threshold = 1e-8;
float angle_threshold = 1e-3;
vec3 p0 = points[0];
vec3 p1 = points[1];
vec3 p2 = points[2];
vec3 v01 = (p1 - p0);
vec3 v12 = (p2 - p1);
float dot_prod = clamp(dot(normalize(v01), normalize(v12)), -1, 1);
bool aligned = acos(dot_prod) < angle_threshold;
bool distinct_01 = length(v01) > length_threshold; // v01 is considered nonzero
bool distinct_12 = length(v12) > length_threshold; // v12 is considered nonzero
int n_uniques = int(distinct_01) + int(distinct_12);
bool quadratic = (n_uniques == 2) && !aligned;
bool linear = (n_uniques == 1) || ((n_uniques == 2) && aligned);
bool constant = (n_uniques == 0);
if(quadratic){
new_points[0] = p0;
new_points[1] = p1;
new_points[2] = p2;
return 2.0;
}else if(linear){
new_points[0] = p0;
new_points[1] = 0.5 * (p0 + p2);
new_points[2] = p2;
return 1.0;
}else{
new_points[0] = p0;
new_points[1] = p0;
new_points[2] = p0;
return 0.0;
}
}

View file

@ -146,14 +146,14 @@ void main(){
return;
}
vec3 new_bp[3];
bezier_degree = get_reduced_control_points(vec3[3](bp[0], bp[1], bp[2]), new_bp);
vec3 v01 = normalize(bp[1] - bp[0]);
vec3 v12 = normalize(bp[2] - bp[1]);
float angle = acos(clamp(dot(v01, v12), -1, 1));
bezier_degree = (angle < 1e-3) ? 1.0 : 2.0;
vec3[3] new_bp = vec3[3](bp[0], bp[1], bp[2]);
unit_normal = get_unit_normal(new_bp);
orientation = v_orientation[0];
if(bezier_degree >= 1){
emit_pentagon(new_bp, unit_normal);
}
// Don't emit any vertices for bezier_degree 0
emit_pentagon(new_bp, unit_normal);
}