Small cleanup for fill shader

This commit is contained in:
Grant Sanderson 2023-01-08 23:34:02 -05:00
parent 89d9e260eb
commit 16390283cf
2 changed files with 13 additions and 13 deletions

View file

@ -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{

View file

@ -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);
}