Merge pull request #2171 from 3b1b/fix-vert-index-issue

Remove use of gl_VertexID
This commit is contained in:
Grant Sanderson
2024-10-01 11:27:57 -07:00
committed by GitHub
9 changed files with 15 additions and 30 deletions

View File

@ -2029,17 +2029,17 @@ class Mobject(object):
result = []
for submobs, sid in batches:
shader_wrapper = submobs[0].shader_wrapper
data_list = list(it.chain(*(sm.get_shader_data() for sm in submobs)))
data_list = [sm.get_shader_data() for sm in submobs]
shader_wrapper.read_in(data_list)
result.append(shader_wrapper)
return result
def get_shader_data(self) -> Iterable[np.ndarray]:
def get_shader_data(self) -> np.ndarray:
indices = self.get_shader_vert_indices()
if indices is not None:
return [self.data[indices]]
return self.data[indices]
else:
return [self.data]
return self.data
def get_uniforms(self):
return self.uniforms

View File

@ -117,6 +117,7 @@ class VMobject(Mobject):
self.needs_new_joint_angles = True
self.needs_new_unit_normal = True
self.subpath_end_indices = None
self.outer_vert_indices = np.zeros(0, dtype=int)
super().__init__(**kwargs)
@ -1048,8 +1049,10 @@ class VMobject(Mobject):
Returns the pattern (0, 1, 2, 2, 3, 4, 4, 5, 6, ...)
"""
n_curves = self.get_num_curves()
if len(self.outer_vert_indices) != 3 * n_curves:
# Creates the pattern (0, 1, 2, 2, 3, 4, 4, 5, 6, ...)
return (np.arange(1, 3 * n_curves + 1) * 2) // 3
self.outer_vert_indices = (np.arange(1, 3 * n_curves + 1) * 2) // 3
return self.outer_vert_indices
# Data for shaders that may need refreshing
@ -1270,11 +1273,14 @@ class VMobject(Mobject):
super().refresh_shader_wrapper_id()
return self
def get_shader_data(self) -> Iterable[np.ndarray]:
def get_shader_data(self) -> np.ndarray:
# Do we want this elsewhere? Say whenever points are refreshed or something?
self.get_joint_angles()
self.data["base_normal"][0::2] = self.data["point"][0]
return [self.data, self.data[-1:]]
return super().get_shader_data()
def get_shader_vert_indices(self) -> Optional[np.ndarray]:
return self.get_outer_vert_indices()
class VGroup(Group, VMobject, Generic[SubVmobjectType]):

View File

@ -225,7 +225,7 @@ class VShaderWrapper(ShaderWrapper):
mobject_uniforms: Optional[UniformDict] = None, # A dictionary mapping names of uniform variables
texture_paths: Optional[dict[str, str]] = None, # A dictionary mapping names to filepaths for textures.
depth_test: bool = False,
render_primitive: int = moderngl.TRIANGLE_STRIP,
render_primitive: int = moderngl.TRIANGLES,
code_replacements: dict[str, str] = dict(),
stroke_behind: bool = False,
):

View File

@ -5,7 +5,6 @@ layout (triangle_strip, max_vertices = 6) out;
in vec3 verts[3];
in vec3 v_base_point[3];
in int v_vert_index[3];
out float depth;
@ -22,10 +21,6 @@ void emit_triangle(vec3 points[3]){
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;

View File

@ -5,10 +5,8 @@ in vec3 base_normal;
out vec3 verts;
out vec3 v_base_point;
out int v_vert_index;
void main(){
verts = point;
v_base_point = base_normal;
v_vert_index = gl_VertexID;
}

View File

@ -6,7 +6,6 @@ layout (triangle_strip, max_vertices = 6) out;
in vec3 verts[3];
in vec4 v_color[3];
in vec3 v_base_normal[3];
in int v_vert_index[3];
out vec4 color;
out float fill_all;
@ -44,10 +43,6 @@ void emit_triangle(vec3 points[3], vec4 v_color[3], vec3 unit_normal){
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;

View File

@ -7,11 +7,9 @@ in vec3 base_normal;
out vec3 verts; // Bezier control point
out vec4 v_color;
out vec3 v_base_normal;
out int v_vert_index;
void main(){
verts = point;
v_color = fill_rgba;
v_base_normal = base_normal;
v_vert_index = gl_VertexID;
}

View File

@ -15,7 +15,6 @@ in float v_joint_angle[3];
in float v_stroke_width[3];
in vec4 v_color[3];
in vec3 v_unit_normal[3];
in int v_vert_index[3];
out vec4 color;
out float dist_to_aaw;
@ -156,10 +155,6 @@ void emit_point_with_width(
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;

View File

@ -16,7 +16,6 @@ out vec4 v_color;
out float v_stroke_width;
out float v_joint_angle;
out vec3 v_unit_normal;
out int v_vert_index;
const float STROKE_WIDTH_CONVERSION = 0.01;
@ -26,5 +25,4 @@ void main(){
v_stroke_width = STROKE_WIDTH_CONVERSION * stroke_width * mix(frame_scale, 1, is_fixed_in_frame);
v_joint_angle = joint_angle;
v_unit_normal = unit_normal;
v_vert_index = gl_VertexID;
}