diff --git a/manimlib/mobject/types/image_mobject.py b/manimlib/mobject/types/image_mobject.py index 80efe5aa43..4ec3c9b5bb 100644 --- a/manimlib/mobject/types/image_mobject.py +++ b/manimlib/mobject/types/image_mobject.py @@ -34,7 +34,9 @@ def __init__( self.height = height self.image_path = get_full_raster_image_path(filename) self.image = Image.open(self.image_path) - super().__init__(texture_paths={"Texture": self.image_path}, **kwargs) + _id = id(self) + key = "T%d" % (_id) + super().__init__(texture_paths={key: self.image_path}, **kwargs) def init_data(self) -> None: super().init_data(length=4) diff --git a/manimlib/mobject/types/surface.py b/manimlib/mobject/types/surface.py index aaac1ebe87..0142c637ec 100644 --- a/manimlib/mobject/types/surface.py +++ b/manimlib/mobject/types/surface.py @@ -302,9 +302,12 @@ def __init__( else: self.num_textures = 2 + _id = id(self) + key_light = "L%d"%(_id) + key_dark = "D%d"%(_id) texture_paths = { - "LightTexture": get_full_raster_image_path(image_file), - "DarkTexture": get_full_raster_image_path(dark_image_file), + key_light: get_full_raster_image_path(image_file), + key_dark: get_full_raster_image_path(dark_image_file), } self.uv_surface = uv_surface diff --git a/manimlib/shader_wrapper.py b/manimlib/shader_wrapper.py index 4e81114789..452de3e0d9 100644 --- a/manimlib/shader_wrapper.py +++ b/manimlib/shader_wrapper.py @@ -50,6 +50,8 @@ def __init__( self.shader_folder = shader_folder self.depth_test = depth_test self.render_primitive = render_primitive + + self.texture_paths = texture_paths self.program_uniform_mirror: UniformDict = dict() self.bind_to_mobject_uniforms(mobject_uniforms or dict()) @@ -63,9 +65,20 @@ def __init__( def init_program_code(self) -> None: def get_code(name: str) -> str | None: - return get_shader_code_from_file( + code = get_shader_code_from_file( os.path.join(self.shader_folder, f"{name}.glsl") ) + + if code is not None and self.texture_paths is not None: + for k in self.texture_paths: + if k.startswith("L"): + code = code.replace("LightTexture",k) + elif k.startswith("D"): + code = code.replace("DarkTexture",k) + elif k.startswith("T"): + code = code.replace("Texture",k) + + return code self.program_code: dict[str, str | None] = { "vertex_shader": get_code("vert"),