Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion genesis/options/surfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
34 changes: 34 additions & 0 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down