From 2cbad30f45c7181b62fd51c3c177dcd26841d44a Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Tue, 31 Jan 2023 11:45:53 -0800 Subject: [PATCH] Change VMobject rendering mode to TRIANGLES And set indices appropriately when reading in to the ShaderWrapper --- manimlib/mobject/types/vectorized_mobject.py | 19 +++++++------------ manimlib/shader_wrapper.py | 4 ++-- .../shaders/quadratic_bezier_fill/geom.glsl | 4 ---- .../shaders/quadratic_bezier_stroke/geom.glsl | 5 ----- .../shaders/quadratic_bezier_stroke/vert.glsl | 2 -- 5 files changed, 9 insertions(+), 25 deletions(-) diff --git a/manimlib/mobject/types/vectorized_mobject.py b/manimlib/mobject/types/vectorized_mobject.py index 3b19b9dd..d7916e29 100644 --- a/manimlib/mobject/types/vectorized_mobject.py +++ b/manimlib/mobject/types/vectorized_mobject.py @@ -68,8 +68,8 @@ class VMobject(Mobject): fill_data_names = ['point', 'fill_rgba', 'base_point', 'unit_normal'] stroke_data_names = ['point', 'stroke_rgba', 'stroke_width', 'joint_product'] - fill_render_primitive: int = moderngl.TRIANGLE_STRIP - stroke_render_primitive: int = moderngl.TRIANGLE_STRIP + fill_render_primitive: int = moderngl.TRIANGLES + stroke_render_primitive: int = moderngl.TRIANGLES pre_function_handle_to_anchor_scale_factor: float = 0.01 make_smooth_after_applying_functions: bool = False @@ -1300,21 +1300,17 @@ class VMobject(Mobject): submob.get_joint_products() has_fill = submob.has_fill() has_stroke = submob.has_stroke() + indices = submob.get_outer_vert_indices() if has_stroke: lst = back_stroke_datas if submob.stroke_behind else stroke_datas - lst.append(submob.data[stroke_names]) - # Set data array to be one longer than number of points, - # with a dummy vertex added at the end. This is to ensure - # it can be safely stacked onto other stroke data arrays. - lst.append(submob.data[stroke_names][-1:]) + lst.append(submob.data[stroke_names][indices]) if has_fill: data = submob.data[fill_names] data["base_point"][:] = data["point"][0] - fill_datas.append(data) if self._use_winding_fill: - # Add dummy, as above - fill_datas.append(data[-1:]) + fill_datas.append(data[indices]) else: + fill_datas.append(data) fill_indices.append(submob.get_triangulation()) if not has_stroke and has_fill: # Add fill border @@ -1322,8 +1318,7 @@ class VMobject(Mobject): names[names.index('stroke_rgba')] = 'fill_rgba' names[names.index('stroke_width')] = 'fill_border_width' border_stroke_data = submob.data[names] - fill_border_datas.append(border_stroke_data) - fill_border_datas.append(border_stroke_data[-1:]) + fill_border_datas.append(border_stroke_data[indices]) shader_wrappers = [ diff --git a/manimlib/shader_wrapper.py b/manimlib/shader_wrapper.py index f9a90275..1f522fe7 100644 --- a/manimlib/shader_wrapper.py +++ b/manimlib/shader_wrapper.py @@ -285,7 +285,7 @@ class FillShaderWrapper(ShaderWrapper): winding = (len(self.vert_indices) == 0) vao.program['winding'].value = winding if not winding: - vao.render(moderngl.TRIANGLES) + vao.render() return original_fbo = self.ctx.fbo @@ -303,7 +303,7 @@ class FillShaderWrapper(ShaderWrapper): gl.glBlendEquationSeparate(gl.GL_FUNC_ADD, gl.GL_MAX) self.ctx.blend_equation = moderngl.FUNC_ADD, moderngl.MAX - vao.render(moderngl.TRIANGLE_STRIP) + vao.render() original_fbo.use() gl.glBlendFunc(gl.GL_ONE, gl.GL_ONE_MINUS_SRC_ALPHA) diff --git a/manimlib/shaders/quadratic_bezier_fill/geom.glsl b/manimlib/shaders/quadratic_bezier_fill/geom.glsl index 24723b9b..c9428e67 100644 --- a/manimlib/shaders/quadratic_bezier_fill/geom.glsl +++ b/manimlib/shaders/quadratic_bezier_fill/geom.glsl @@ -57,10 +57,6 @@ void emit_simple_triangle(){ void main(){ - // We use the triangle strip primative, but - // actually only need every other strip element - if (winding && int(v_vert_index[0]) % 2 == 1) 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; diff --git a/manimlib/shaders/quadratic_bezier_stroke/geom.glsl b/manimlib/shaders/quadratic_bezier_stroke/geom.glsl index 6598c3ce..81103c18 100644 --- a/manimlib/shaders/quadratic_bezier_stroke/geom.glsl +++ b/manimlib/shaders/quadratic_bezier_stroke/geom.glsl @@ -13,7 +13,6 @@ in vec3 verts[3]; in vec4 v_joint_product[3]; in float v_stroke_width[3]; in vec4 v_color[3]; -in float v_vert_index[3]; out vec4 color; out float uv_stroke_width; @@ -154,10 +153,6 @@ void get_corners( } void main() { - // We use the triangle strip primative, but - // actually only need every other strip element - if (int(v_vert_index[0]) % 2 == 1) 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; diff --git a/manimlib/shaders/quadratic_bezier_stroke/vert.glsl b/manimlib/shaders/quadratic_bezier_stroke/vert.glsl index b221536a..f26a1261 100644 --- a/manimlib/shaders/quadratic_bezier_stroke/vert.glsl +++ b/manimlib/shaders/quadratic_bezier_stroke/vert.glsl @@ -15,7 +15,6 @@ out vec3 verts; out vec4 v_joint_product; out float v_stroke_width; out vec4 v_color; -out float v_vert_index; const float STROKE_WIDTH_CONVERSION = 0.01; @@ -27,5 +26,4 @@ void main(){ } v_joint_product = joint_product; v_color = stroke_rgba; - v_vert_index = gl_VertexID; } \ No newline at end of file