diff --git a/genesis/ext/pyrender/utils.py b/genesis/ext/pyrender/utils.py index ae10c22c58..2395a4a8a9 100644 --- a/genesis/ext/pyrender/utils.py +++ b/genesis/ext/pyrender/utils.py @@ -87,7 +87,8 @@ 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": @@ -95,9 +96,14 @@ def format_texture_source(texture, target_channels="RGB"): 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 diff --git a/tests/test_render.py b/tests/test_render.py index 421a0ffa95..c69e71d640 100644 --- a/tests/test_render.py +++ b/tests/test_render.py @@ -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()