mirror of
https://github.com/3b1b/manim.git
synced 2025-07-31 22:13:30 +08:00
Merge pull request #2171 from 3b1b/fix-vert-index-issue
Remove use of gl_VertexID
This commit is contained in:
@ -2029,17 +2029,17 @@ class Mobject(object):
|
|||||||
result = []
|
result = []
|
||||||
for submobs, sid in batches:
|
for submobs, sid in batches:
|
||||||
shader_wrapper = submobs[0].shader_wrapper
|
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)
|
shader_wrapper.read_in(data_list)
|
||||||
result.append(shader_wrapper)
|
result.append(shader_wrapper)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def get_shader_data(self) -> Iterable[np.ndarray]:
|
def get_shader_data(self) -> np.ndarray:
|
||||||
indices = self.get_shader_vert_indices()
|
indices = self.get_shader_vert_indices()
|
||||||
if indices is not None:
|
if indices is not None:
|
||||||
return [self.data[indices]]
|
return self.data[indices]
|
||||||
else:
|
else:
|
||||||
return [self.data]
|
return self.data
|
||||||
|
|
||||||
def get_uniforms(self):
|
def get_uniforms(self):
|
||||||
return self.uniforms
|
return self.uniforms
|
||||||
|
@ -117,6 +117,7 @@ class VMobject(Mobject):
|
|||||||
self.needs_new_joint_angles = True
|
self.needs_new_joint_angles = True
|
||||||
self.needs_new_unit_normal = True
|
self.needs_new_unit_normal = True
|
||||||
self.subpath_end_indices = None
|
self.subpath_end_indices = None
|
||||||
|
self.outer_vert_indices = np.zeros(0, dtype=int)
|
||||||
|
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
@ -1048,8 +1049,10 @@ class VMobject(Mobject):
|
|||||||
Returns the pattern (0, 1, 2, 2, 3, 4, 4, 5, 6, ...)
|
Returns the pattern (0, 1, 2, 2, 3, 4, 4, 5, 6, ...)
|
||||||
"""
|
"""
|
||||||
n_curves = self.get_num_curves()
|
n_curves = self.get_num_curves()
|
||||||
# Creates the pattern (0, 1, 2, 2, 3, 4, 4, 5, 6, ...)
|
if len(self.outer_vert_indices) != 3 * n_curves:
|
||||||
return (np.arange(1, 3 * n_curves + 1) * 2) // 3
|
# Creates the pattern (0, 1, 2, 2, 3, 4, 4, 5, 6, ...)
|
||||||
|
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
|
# Data for shaders that may need refreshing
|
||||||
|
|
||||||
@ -1270,11 +1273,14 @@ class VMobject(Mobject):
|
|||||||
super().refresh_shader_wrapper_id()
|
super().refresh_shader_wrapper_id()
|
||||||
return self
|
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?
|
# Do we want this elsewhere? Say whenever points are refreshed or something?
|
||||||
self.get_joint_angles()
|
self.get_joint_angles()
|
||||||
self.data["base_normal"][0::2] = self.data["point"][0]
|
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]):
|
class VGroup(Group, VMobject, Generic[SubVmobjectType]):
|
||||||
|
@ -225,7 +225,7 @@ class VShaderWrapper(ShaderWrapper):
|
|||||||
mobject_uniforms: Optional[UniformDict] = None, # A dictionary mapping names of uniform variables
|
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.
|
texture_paths: Optional[dict[str, str]] = None, # A dictionary mapping names to filepaths for textures.
|
||||||
depth_test: bool = False,
|
depth_test: bool = False,
|
||||||
render_primitive: int = moderngl.TRIANGLE_STRIP,
|
render_primitive: int = moderngl.TRIANGLES,
|
||||||
code_replacements: dict[str, str] = dict(),
|
code_replacements: dict[str, str] = dict(),
|
||||||
stroke_behind: bool = False,
|
stroke_behind: bool = False,
|
||||||
):
|
):
|
||||||
|
@ -5,7 +5,6 @@ layout (triangle_strip, max_vertices = 6) out;
|
|||||||
|
|
||||||
in vec3 verts[3];
|
in vec3 verts[3];
|
||||||
in vec3 v_base_point[3];
|
in vec3 v_base_point[3];
|
||||||
in int v_vert_index[3];
|
|
||||||
|
|
||||||
out float depth;
|
out float depth;
|
||||||
|
|
||||||
@ -22,10 +21,6 @@ void emit_triangle(vec3 points[3]){
|
|||||||
|
|
||||||
|
|
||||||
void main(){
|
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
|
// Curves are marked as ended when the handle after
|
||||||
// the first anchor is set equal to that anchor
|
// the first anchor is set equal to that anchor
|
||||||
if (verts[0] == verts[1]) return;
|
if (verts[0] == verts[1]) return;
|
||||||
|
@ -5,10 +5,8 @@ in vec3 base_normal;
|
|||||||
|
|
||||||
out vec3 verts;
|
out vec3 verts;
|
||||||
out vec3 v_base_point;
|
out vec3 v_base_point;
|
||||||
out int v_vert_index;
|
|
||||||
|
|
||||||
void main(){
|
void main(){
|
||||||
verts = point;
|
verts = point;
|
||||||
v_base_point = base_normal;
|
v_base_point = base_normal;
|
||||||
v_vert_index = gl_VertexID;
|
|
||||||
}
|
}
|
@ -6,7 +6,6 @@ layout (triangle_strip, max_vertices = 6) out;
|
|||||||
in vec3 verts[3];
|
in vec3 verts[3];
|
||||||
in vec4 v_color[3];
|
in vec4 v_color[3];
|
||||||
in vec3 v_base_normal[3];
|
in vec3 v_base_normal[3];
|
||||||
in int v_vert_index[3];
|
|
||||||
|
|
||||||
out vec4 color;
|
out vec4 color;
|
||||||
out float fill_all;
|
out float fill_all;
|
||||||
@ -44,10 +43,6 @@ void emit_triangle(vec3 points[3], vec4 v_color[3], vec3 unit_normal){
|
|||||||
|
|
||||||
|
|
||||||
void main(){
|
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
|
// Curves are marked as ended when the handle after
|
||||||
// the first anchor is set equal to that anchor
|
// the first anchor is set equal to that anchor
|
||||||
if (verts[0] == verts[1]) return;
|
if (verts[0] == verts[1]) return;
|
||||||
|
@ -7,11 +7,9 @@ in vec3 base_normal;
|
|||||||
out vec3 verts; // Bezier control point
|
out vec3 verts; // Bezier control point
|
||||||
out vec4 v_color;
|
out vec4 v_color;
|
||||||
out vec3 v_base_normal;
|
out vec3 v_base_normal;
|
||||||
out int v_vert_index;
|
|
||||||
|
|
||||||
void main(){
|
void main(){
|
||||||
verts = point;
|
verts = point;
|
||||||
v_color = fill_rgba;
|
v_color = fill_rgba;
|
||||||
v_base_normal = base_normal;
|
v_base_normal = base_normal;
|
||||||
v_vert_index = gl_VertexID;
|
|
||||||
}
|
}
|
@ -15,7 +15,6 @@ in float v_joint_angle[3];
|
|||||||
in float v_stroke_width[3];
|
in float v_stroke_width[3];
|
||||||
in vec4 v_color[3];
|
in vec4 v_color[3];
|
||||||
in vec3 v_unit_normal[3];
|
in vec3 v_unit_normal[3];
|
||||||
in int v_vert_index[3];
|
|
||||||
|
|
||||||
out vec4 color;
|
out vec4 color;
|
||||||
out float dist_to_aaw;
|
out float dist_to_aaw;
|
||||||
@ -156,10 +155,6 @@ void emit_point_with_width(
|
|||||||
|
|
||||||
|
|
||||||
void main() {
|
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
|
// Curves are marked as ended when the handle after
|
||||||
// the first anchor is set equal to that anchor
|
// the first anchor is set equal to that anchor
|
||||||
if (verts[0] == verts[1]) return;
|
if (verts[0] == verts[1]) return;
|
||||||
|
@ -16,7 +16,6 @@ out vec4 v_color;
|
|||||||
out float v_stroke_width;
|
out float v_stroke_width;
|
||||||
out float v_joint_angle;
|
out float v_joint_angle;
|
||||||
out vec3 v_unit_normal;
|
out vec3 v_unit_normal;
|
||||||
out int v_vert_index;
|
|
||||||
|
|
||||||
const float STROKE_WIDTH_CONVERSION = 0.01;
|
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_stroke_width = STROKE_WIDTH_CONVERSION * stroke_width * mix(frame_scale, 1, is_fixed_in_frame);
|
||||||
v_joint_angle = joint_angle;
|
v_joint_angle = joint_angle;
|
||||||
v_unit_normal = unit_normal;
|
v_unit_normal = unit_normal;
|
||||||
v_vert_index = gl_VertexID;
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user