3b1b-manim/manimlib/shaders/quadratic_bezier_fill/geom.glsl

74 lines
1.8 KiB
Text
Raw Normal View History

2020-02-03 10:52:39 -08:00
#version 330
layout (triangles) in;
layout (triangle_strip, max_vertices = 6) out;
2020-02-03 10:52:39 -08:00
in vec3 verts[3];
2020-02-03 10:52:39 -08:00
in vec4 v_color[3];
in vec3 v_base_normal[3];
in int v_vert_index[3];
2020-02-03 10:52:39 -08:00
out vec4 color;
out float fill_all;
out float orientation;
// 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
// 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)
);
// Analog of import for manim only
#INSERT emit_gl_Position.glsl
#INSERT finalize_color.glsl
2020-02-03 10:52:39 -08:00
void emit_triangle(vec3 points[3], vec4 v_color[3]){
vec3 unit_normal = v_base_normal[1];
2023-01-27 12:43:21 -08:00
orientation = sign(determinant(mat3(
unit_normal,
points[1] - points[0],
points[2] - points[0]
)));
for(int i = 0; i < 3; i++){
uv_coords = SIMPLE_QUADRATIC[i];
color = finalize_color(v_color[i], points[i], unit_normal);
emit_gl_Position(points[i]);
EmitVertex();
}
EndPrimitive();
}
2020-02-03 10:52:39 -08:00
void main(){
// Vector graphic shaders use TRIANGLE_STRIP, but only
// every other one needs to be rendered
if (v_vert_index[0] % 2 != 0) return;
// Curves are marked as ended when the handle after
// the first anchor is set equal to that anchor
if (verts[0] == verts[1]) return;
// 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;
// Emit main triangle
fill_all = 1.0;
emit_triangle(
vec3[3](v_base_normal[0], verts[0], verts[2]),
vec4[3](v_color[1], v_color[0], v_color[2])
);
// Edge triangle
fill_all = 0.0;
emit_triangle(
vec3[3](verts[0], verts[1], verts[2]),
vec4[3](v_color[0], v_color[1], v_color[2])
);
2020-02-03 10:52:39 -08:00
}