mirror of
https://github.com/3b1b/manim.git
synced 2025-09-19 04:41:56 +00:00
Small cleanup for fill shader
This commit is contained in:
parent
89d9e260eb
commit
16390283cf
2 changed files with 13 additions and 13 deletions
|
@ -10,14 +10,11 @@ in vec3 xyz_coords;
|
||||||
in float orientation;
|
in float orientation;
|
||||||
in vec2 uv_coords;
|
in vec2 uv_coords;
|
||||||
in vec2 uv_b2;
|
in vec2 uv_b2;
|
||||||
|
in vec2 simp_coords;
|
||||||
in float bezier_degree;
|
in float bezier_degree;
|
||||||
|
|
||||||
out vec4 frag_color;
|
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
|
#INSERT quadratic_bezier_distance.glsl
|
||||||
|
|
||||||
|
@ -32,17 +29,10 @@ float sdf(){
|
||||||
if(abs(v2 / u2) < 0.1 * uv_anti_alias_width){
|
if(abs(v2 / u2) < 0.1 * uv_anti_alias_width){
|
||||||
return abs(uv_coords[1]);
|
return abs(uv_coords[1]);
|
||||||
}
|
}
|
||||||
// This converts uv_coords to yet another space where the bezier points sit on
|
vec2 p = simp_coords;
|
||||||
// (0, 0), (1/2, 0) and (1, 1), so that the curve can be expressed implicityly
|
float Fp = (p.x * p.x - p.y);
|
||||||
// as y = x^2.
|
|
||||||
mat2 to_simple_space = mat2(
|
|
||||||
v2, 0,
|
|
||||||
2 - u2, 4 * v2
|
|
||||||
);
|
|
||||||
vec2 p = to_simple_space * uv_coords;
|
|
||||||
// Sign takes care of whether we should be filling the inside or outside of curve.
|
// Sign takes care of whether we should be filling the inside or outside of curve.
|
||||||
float sgn = orientation * sign(v2);
|
float sgn = orientation * sign(v2);
|
||||||
float Fp = (p.x * p.x - p.y);
|
|
||||||
if(sgn * Fp <= 0){
|
if(sgn * Fp <= 0){
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}else{
|
}else{
|
||||||
|
|
|
@ -31,6 +31,7 @@ out float orientation;
|
||||||
// uv space is where b0 = (0, 0), b1 = (1, 0), and transform is orthogonal
|
// uv space is where b0 = (0, 0), b1 = (1, 0), and transform is orthogonal
|
||||||
out vec2 uv_coords;
|
out vec2 uv_coords;
|
||||||
out vec2 uv_b2;
|
out vec2 uv_b2;
|
||||||
|
out vec2 simp_coords;
|
||||||
out float bezier_degree;
|
out float bezier_degree;
|
||||||
|
|
||||||
vec3 unit_normal;
|
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_b2 = (xyz_to_uv * vec4(p2, 1)).xy;
|
||||||
uv_anti_alias_width = aaw / length(p1 - p0);
|
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++){
|
for(int i = 0; i < 5; i++){
|
||||||
vec3 corner = corners[i];
|
vec3 corner = corners[i];
|
||||||
uv_coords = (xyz_to_uv * vec4(corner, 1)).xy;
|
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]
|
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);
|
emit_vertex_wrapper(corner, j);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue