diff --git a/genesis/options/surfaces.py b/genesis/options/surfaces.py index 789e1c644a..503aa38e78 100644 --- a/genesis/options/surfaces.py +++ b/genesis/options/surfaces.py @@ -641,7 +641,9 @@ def requires_uv(self) -> bool: ) def get_rgba(self, batch: bool = False) -> BatchTexture | Texture: - color = self.emissive_texture if self.emissive_texture is not None else self.diffuse_texture + color = self.diffuse_texture + if (color is None or color.is_black) and self.emissive_texture is not None: + color = self.emissive_texture return _make_rgba(color, self.opacity_texture, batch) @model_validator(mode="after") diff --git a/tests/test_misc.py b/tests/test_misc.py index 790dff966b..bfb72f3967 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -234,6 +234,40 @@ class Wrapper(BaseModel): gs.surfaces.Glass(thickness=0.02, thickness_texture=ColorTexture(color=(0.05,))) +@pytest.mark.required +def test_bsdf_rgba_prefers_base_color_over_emissive_texture(): + diffuse = gs.textures.ImageTexture(image_array=np.full((4, 4, 3), (201, 166, 105), dtype=np.uint8)) + opacity = gs.textures.ImageTexture(image_array=np.full((4, 4), 255, dtype=np.uint8)) + emissive = gs.textures.ImageTexture(image_array=np.full((2, 2, 3), 9, dtype=np.uint8)) + + rgba = gs.surfaces.BSDF( + diffuse_texture=diffuse, + opacity_texture=opacity, + emissive_texture=emissive, + ).get_rgba() + + assert rgba.image_array.shape == (4, 4, 4) + assert np.array_equal(rgba.image_array[..., :3], diffuse.image_array) + assert np.array_equal(rgba.image_array[..., 3], opacity.image_array) + + black_diffuse = gs.textures.ImageTexture( + image_array=np.full((2, 2, 3), (201, 166, 105), dtype=np.uint8), + image_color=(0.0, 0.0, 0.0), + ) + emissive_terrain = gs.textures.ImageTexture(image_array=np.full((2, 2, 3), (76, 122, 64), dtype=np.uint8)) + rgba = gs.surfaces.BSDF( + diffuse_texture=black_diffuse, + opacity_texture=gs.textures.ImageTexture(image_array=np.full((2, 2), 255, dtype=np.uint8)), + emissive_texture=emissive_terrain, + ).get_rgba() + + assert np.array_equal(rgba.image_array[..., :3], emissive_terrain.image_array) + + rgba = gs.surfaces.BSDF(color=(0.0, 0.0, 0.0)).get_rgba() + + assert rgba.color == (0.0, 0.0, 0.0, 1.0) + + @pytest.mark.required def test_fps_algorithm_core(): # Shape, dtype, determinism, anchor-on-no-seed, and invalid n_samples all in one test.