Skip to content

Commit 2d668af

Browse files
authored
[FEATURE] Support 2-channel (LA) textures in Rasterizer. (Genesis-Embodied-AI#1519)
1 parent b91e39a commit 2d668af

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

genesis/ext/pyrender/utils.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,23 @@ def format_texture_source(texture, target_channels="RGB"):
8787
if texture.shape[2] == 1:
8888
texture = np.repeat(texture, 3, axis=2)
8989
elif texture.shape[2] == 2:
90-
raise ValueError("Cannot reformat 2-channel texture into RGB")
90+
# Convert 2-channel texture to grayscale RGB by duplicating the first channel
91+
texture = texture[:, :, (0, 0, 0)]
9192
else:
9293
texture = texture[:, :, (0, 1, 2)]
9394
elif target_channels == "RGBA":
9495
if texture.shape[2] == 1:
9596
texture = np.repeat(texture, 4, axis=2)
9697
texture[:, :, 3] = 255
9798
elif texture.shape[2] == 2:
98-
raise ValueError("Cannot reformat 2-channel texture into RGBA")
99+
# Convert 2-channel texture (luminance + alpha) to RGBA by duplicating luminance to RGB
100+
luminance = texture[:, :, :1]
101+
alpha = texture[:, :, 1]
102+
texture = np.empty((*texture.shape[:2], 4), dtype=texture.dtype)
103+
texture[:, :, :3] = luminance
104+
texture[:, :, 3] = alpha
99105
elif texture.shape[2] == 3:
100-
tx = np.empty((texture.shape[0], texture.shape[1], 4), dtype=np.uint8)
106+
tx = np.empty((*texture.shape[:2], 4), dtype=np.uint8)
101107
tx[:, :, :3] = texture
102108
tx[:, :, 3] = 255
103109
texture = tx

tests/test_render.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,3 +655,20 @@ def test_madrona_batch_rendering(tmp_path, use_rasterizer, render_all_cameras, n
655655
for image_file in sorted(tmp_path.rglob("*.png")):
656656
with open(image_file, "rb") as f:
657657
assert f.read() == png_snapshot
658+
659+
660+
@pytest.mark.required
661+
@pytest.mark.parametrize("backend", [gs.cpu])
662+
def test_2_channels_luminance_alpha_textures(show_viewer):
663+
scene = gs.Scene(
664+
show_viewer=show_viewer,
665+
show_FPS=False,
666+
)
667+
asset_path = get_hf_dataset(pattern="fridge/*")
668+
fridge = scene.add_entity(
669+
gs.morphs.URDF(
670+
file=f"{asset_path}/fridge/fridge.urdf",
671+
fixed=True,
672+
)
673+
)
674+
scene.build()

0 commit comments

Comments
 (0)