Interleave base_point and unit_normal in the same array

This commit is contained in:
Grant Sanderson 2024-08-19 16:50:49 -05:00
parent b7337f0781
commit c064b11e2a
5 changed files with 19 additions and 25 deletions

View file

@ -69,8 +69,7 @@ class VMobject(Mobject):
('stroke_width', np.float32, (1,)),
('joint_product', np.float32, (4,)),
('fill_rgba', np.float32, (4,)),
('base_point', np.float32, (3,)),
('unit_normal', np.float32, (3,)),
('base_normal', np.float32, (3,)), # Every other holds base point and unit normal vector
('fill_border_width', np.float32, (1,)),
])
pre_function_handle_to_anchor_scale_factor: float = 0.01
@ -907,7 +906,7 @@ class VMobject(Mobject):
points[1] - points[0],
points[2] - points[1],
)
self.data["unit_normal"][:] = normal
self.data["base_normal"][1::2] = normal
return normal
def refresh_unit_normal(self) -> Self:
@ -1278,7 +1277,7 @@ class VMobject(Mobject):
continue
inner_ends = mob.get_subpath_end_indices()[:-1]
mob.data["point"][inner_ends + 1] = mob.data["point"][inner_ends + 2]
mob.data["unit_normal"] *= -1
mob.data["base_normal"][1::2] *= -1
super().reverse_points()
return self
@ -1344,7 +1343,7 @@ class VMobject(Mobject):
stroke_behind = False
for submob in family:
if submob._has_fill:
submob.data["base_point"] = submob.data["point"][0]
submob.data["base_normal"][0::2] = submob.data["point"][0]
if submob.stroke_behind:
stroke_behind = True

View file

@ -265,20 +265,19 @@ class VShaderWrapper(ShaderWrapper):
# stroke_width 1
# joint_product 4
# fill_rgba 4
# base_point 3
# unit_normal 3
# base_normal 3
# fill_border_width 1
self.stroke_vert_format = '3f 4f 1f 4f 44x'
self.stroke_vert_format = '3f 4f 1f 4f 32x'
self.stroke_vert_attributes = ['point', 'stroke_rgba', 'stroke_width', 'joint_product']
self.fill_vert_format = '3f 36x 4f 3f 3f 4x'
self.fill_vert_attributes = ['point', 'fill_rgba', 'base_point', 'unit_normal']
self.fill_vert_format = '3f 36x 4f 3f 4x'
self.fill_vert_attributes = ['point', 'fill_rgba', 'base_normal']
self.fill_border_vert_format = '3f 20x 4f 4f 24x 1f'
self.fill_border_vert_format = '3f 20x 4f 4f 12x 1f'
self.fill_border_vert_attributes = ['point', 'joint_product', 'stroke_rgba', 'stroke_width']
self.fill_depth_vert_format = '3f 52x 3f 16x'
self.fill_depth_vert_attributes = ['point', 'base_point']
self.fill_depth_vert_format = '3f 40x 3f 16x'
self.fill_depth_vert_attributes = ['point', 'base_normal']
def init_vertex_objects(self):
self.vbo = None

View file

@ -1,7 +1,7 @@
#version 330
in vec3 point;
in vec3 base_point;
in vec3 base_normal;
out vec3 verts;
out vec3 v_base_point;
@ -9,6 +9,6 @@ out int v_vert_index;
void main(){
verts = point;
v_base_point = base_point;
v_base_point = base_normal;
v_vert_index = gl_VertexID;
}

View file

@ -5,8 +5,7 @@ layout (triangle_strip, max_vertices = 6) out;
in vec3 verts[3];
in vec4 v_color[3];
in vec3 v_base_point[3];
in vec3 v_unit_normal[3];
in vec3 v_base_normal[3];
in int v_vert_index[3];
out vec4 color;
@ -28,7 +27,7 @@ const vec2 SIMPLE_QUADRATIC[3] = vec2[3](
void emit_triangle(vec3 points[3], vec4 v_color[3]){
vec3 unit_normal = v_unit_normal[1];
vec3 unit_normal = v_base_normal[1];
orientation = sign(determinant(mat3(
unit_normal,
@ -61,7 +60,7 @@ void main(){
// Emit main triangle
fill_all = 1.0;
emit_triangle(
vec3[3](v_base_point[0], verts[0], verts[2]),
vec3[3](v_base_normal[0], verts[0], verts[2]),
vec4[3](v_color[1], v_color[0], v_color[2])
);
// Edge triangle

View file

@ -2,19 +2,16 @@
in vec3 point;
in vec4 fill_rgba;
in vec3 base_point;
in vec3 unit_normal;
in vec3 base_normal;
out vec3 verts; // Bezier control point
out vec4 v_color;
out vec3 v_base_point;
out vec3 v_unit_normal;
out vec3 v_base_normal;
out int v_vert_index;
void main(){
verts = point;
v_color = fill_rgba;
v_base_point = base_point;
v_unit_normal = unit_normal;
v_base_normal = base_normal;
v_vert_index = gl_VertexID;
}