2020-02-03 10:52:39 -08:00
|
|
|
#version 330
|
|
|
|
|
|
|
|
layout (triangles) in;
|
2023-01-24 20:03:23 -08:00
|
|
|
layout (triangle_strip, max_vertices = 6) out;
|
2020-02-03 10:52:39 -08:00
|
|
|
|
2023-01-24 20:03:23 -08:00
|
|
|
uniform bool winding;
|
2021-01-09 10:30:42 -08:00
|
|
|
|
2023-01-13 17:26:59 -08:00
|
|
|
in vec3 verts[3];
|
2020-02-03 10:52:39 -08:00
|
|
|
in vec4 v_color[3];
|
2023-01-24 13:29:34 -08:00
|
|
|
in vec3 v_base_point[3];
|
2023-01-27 12:35:43 -08:00
|
|
|
in vec3 v_unit_normal[3];
|
2024-08-19 08:05:32 -05:00
|
|
|
in int v_vert_index[3];
|
2023-01-24 13:29:34 -08:00
|
|
|
|
2020-02-03 10:52:39 -08:00
|
|
|
out vec4 color;
|
2023-01-24 13:49:43 -08:00
|
|
|
out float fill_all;
|
2023-01-24 20:03:23 -08:00
|
|
|
out float orientation;
|
2023-01-09 19:54:09 -08:00
|
|
|
// uv space is where the curve coincides with y = x^2
|
2020-02-03 10:52:39 -08:00
|
|
|
out vec2 uv_coords;
|
2023-01-10 09:49:51 -08:00
|
|
|
|
2023-01-24 20:03:23 -08:00
|
|
|
// A quadratic bezier curve with these points coincides with y = x^2
|
|
|
|
const vec2 SIMPLE_QUADRATIC[3] = vec2[3](
|
|
|
|
vec2(0.0, 0.0),
|
|
|
|
vec2(0.5, 0),
|
|
|
|
vec2(1.0, 1.0)
|
|
|
|
);
|
2021-01-07 16:16:20 -08:00
|
|
|
|
|
|
|
// Analog of import for manim only
|
2023-01-30 18:43:28 -08:00
|
|
|
#INSERT emit_gl_Position.glsl
|
2023-02-02 12:04:23 -08:00
|
|
|
#INSERT finalize_color.glsl
|
2020-02-03 10:52:39 -08:00
|
|
|
|
2020-06-03 17:10:33 -07:00
|
|
|
|
2023-01-24 20:03:23 -08:00
|
|
|
void emit_triangle(vec3 points[3], vec4 v_color[3]){
|
2023-02-02 12:04:23 -08:00
|
|
|
vec3 unit_normal = v_unit_normal[1];
|
|
|
|
|
2023-01-27 12:43:21 -08:00
|
|
|
orientation = sign(determinant(mat3(
|
|
|
|
unit_normal,
|
|
|
|
points[1] - points[0],
|
|
|
|
points[2] - points[0]
|
|
|
|
)));
|
2023-01-24 20:03:23 -08:00
|
|
|
|
|
|
|
for(int i = 0; i < 3; i++){
|
|
|
|
uv_coords = SIMPLE_QUADRATIC[i];
|
2023-02-02 12:04:23 -08:00
|
|
|
color = finalize_color(v_color[i], points[i], unit_normal);
|
2023-01-30 18:43:28 -08:00
|
|
|
emit_gl_Position(points[i]);
|
2023-01-24 20:03:23 -08:00
|
|
|
EmitVertex();
|
|
|
|
}
|
|
|
|
EndPrimitive();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-24 21:10:57 -08:00
|
|
|
void emit_simple_triangle(){
|
2023-01-24 20:03:23 -08:00
|
|
|
emit_triangle(
|
|
|
|
vec3[3](verts[0], verts[1], verts[2]),
|
|
|
|
vec4[3](v_color[0], v_color[1], v_color[2])
|
|
|
|
);
|
2020-06-03 17:10:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-03 10:52:39 -08:00
|
|
|
void main(){
|
2024-08-19 08:05:32 -05:00
|
|
|
// Vector graphic shaders use TRIANGLE_STRIP, but only
|
|
|
|
// every other one needs to be rendered
|
|
|
|
if (v_vert_index[0] % 2 != 0) return;
|
|
|
|
|
2023-01-24 13:49:43 -08:00
|
|
|
// Curves are marked as ended when the handle after
|
2023-01-24 13:29:34 -08:00
|
|
|
// the first anchor is set equal to that anchor
|
|
|
|
if (verts[0] == verts[1]) return;
|
|
|
|
|
2024-08-19 08:05:32 -05:00
|
|
|
// Check zero fill
|
|
|
|
if (vec3(v_color[0].a, v_color[1].a, v_color[2].a) == vec3(0.0, 0.0, 0.0)) return;
|
|
|
|
|
|
|
|
|
2023-01-24 20:03:23 -08:00
|
|
|
if(winding){
|
2023-01-24 13:49:43 -08:00
|
|
|
// Emit main triangle
|
2023-01-24 15:29:35 -08:00
|
|
|
fill_all = 1.0;
|
2023-01-24 20:03:23 -08:00
|
|
|
emit_triangle(
|
|
|
|
vec3[3](v_base_point[0], verts[0], verts[2]),
|
|
|
|
vec4[3](v_color[1], v_color[0], v_color[2])
|
|
|
|
);
|
|
|
|
// Edge triangle
|
2023-01-24 15:29:35 -08:00
|
|
|
fill_all = 0.0;
|
2023-01-24 21:10:57 -08:00
|
|
|
emit_simple_triangle();
|
2023-01-24 20:03:23 -08:00
|
|
|
}else{
|
|
|
|
// In this case, one should fill all if the vertices are
|
|
|
|
// not in sequential order
|
|
|
|
fill_all = float(
|
|
|
|
(v_vert_index[1] - v_vert_index[0]) != 1.0 ||
|
|
|
|
(v_vert_index[2] - v_vert_index[1]) != 1.0
|
2023-01-24 14:09:41 -08:00
|
|
|
);
|
2023-01-24 21:10:57 -08:00
|
|
|
emit_simple_triangle();
|
2023-01-24 13:49:43 -08:00
|
|
|
}
|
2020-02-03 10:52:39 -08:00
|
|
|
}
|
|
|
|
|