Skip to content
Merged
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
12 changes: 9 additions & 3 deletions genesis/ext/pyrender/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,23 @@ def format_texture_source(texture, target_channels="RGB"):
if texture.shape[2] == 1:
texture = np.repeat(texture, 3, axis=2)
elif texture.shape[2] == 2:
raise ValueError("Cannot reformat 2-channel texture into RGB")
# Convert 2-channel texture to grayscale RGB by duplicating the first channel
texture = texture[:, :, (0, 0, 0)]
else:
texture = texture[:, :, (0, 1, 2)]
elif target_channels == "RGBA":
if texture.shape[2] == 1:
texture = np.repeat(texture, 4, axis=2)
texture[:, :, 3] = 255
elif texture.shape[2] == 2:
raise ValueError("Cannot reformat 2-channel texture into RGBA")
# Convert 2-channel texture (luminance + alpha) to RGBA by duplicating luminance to RGB
luminance = texture[:, :, :1]
alpha = texture[:, :, 1]
texture = np.empty((*texture.shape[:2], 4), dtype=texture.dtype)
texture[:, :, :3] = luminance
texture[:, :, 3] = alpha
elif texture.shape[2] == 3:
tx = np.empty((texture.shape[0], texture.shape[1], 4), dtype=np.uint8)
tx = np.empty((*texture.shape[:2], 4), dtype=np.uint8)
tx[:, :, :3] = texture
tx[:, :, 3] = 255
texture = tx
Expand Down
17 changes: 17 additions & 0 deletions tests/test_render.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,3 +655,20 @@ def test_madrona_batch_rendering(tmp_path, use_rasterizer, render_all_cameras, n
for image_file in sorted(tmp_path.rglob("*.png")):
with open(image_file, "rb") as f:
assert f.read() == png_snapshot


@pytest.mark.required
@pytest.mark.parametrize("backend", [gs.cpu])
def test_2_channels_luminance_alpha_textures(show_viewer):
scene = gs.Scene(
show_viewer=show_viewer,
show_FPS=False,
)
asset_path = get_hf_dataset(pattern="fridge/*")
fridge = scene.add_entity(
gs.morphs.URDF(
file=f"{asset_path}/fridge/fridge.urdf",
fixed=True,
)
)
scene.build()