Skip to content

Commit 8d923a5

Browse files
committed
Disable shadow and plane reflection when using software rendering.
1 parent 692a2fb commit 8d923a5

File tree

6 files changed

+50
-35
lines changed

6 files changed

+50
-35
lines changed

genesis/engine/sensors/imu.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ def _draw_debug(self, context: "RasterizerContext", buffer_updates: dict[str, np
271271
data = self.read(env_idx)
272272
acc_vec = data.lin_acc.reshape((3,)) * self._options.debug_acc_scale
273273
gyro_vec = data.ang_vel.reshape((3,)) * self._options.debug_gyro_scale
274-
mag_vec = data.mag.reshape((3,)) * self._options.debug_mag_scale # added mag debug
274+
mag_vec = data.mag.reshape((3,)) * self._options.debug_mag_scale
275275

276276
# transform from local frame to world frame
277277
offset_quat = transform_quat_by_quat(self.quat_offset, quat)
@@ -286,8 +286,8 @@ def _draw_debug(self, context: "RasterizerContext", buffer_updates: dict[str, np
286286
self.debug_objects += filter(
287287
None,
288288
(
289-
context.draw_debug_arrow(pos=pos, vec=acc_vec, color=self._options.debug_acc_color),
290-
context.draw_debug_arrow(pos=pos, vec=gyro_vec, color=self._options.debug_gyro_color),
291-
context.draw_debug_arrow(pos=pos, vec=mag_vec, color=self._options.debug_mag_color),
289+
context.draw_debug_arrow(pos=pos, vec=acc_vec, radius=0.006, color=self._options.debug_acc_color),
290+
context.draw_debug_arrow(pos=pos, vec=gyro_vec, radius=0.0055, color=self._options.debug_gyro_color),
291+
context.draw_debug_arrow(pos=pos, vec=mag_vec, radius=0.005, color=self._options.debug_mag_color),
292292
),
293293
)

genesis/ext/pyrender/viewer.py

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -654,12 +654,18 @@ def on_close(self):
654654
super().close()
655655
except Exception:
656656
pass
657-
finally:
657+
try:
658658
super().on_close()
659-
try:
660-
pyglet.app.exit()
661-
except Exception:
662-
pass
659+
except Exception:
660+
pass
661+
try:
662+
pyglet.app.exit()
663+
except Exception:
664+
pass
665+
try:
666+
pyglet.app.platform_event_loop.stop()
667+
except Exception:
668+
pass
663669

664670
self._offscreen_semaphore.release()
665671

@@ -998,9 +1004,9 @@ def _render(self, camera_node=None, renderer=None, normal=False):
9981004
elif self.render_flags["all_solid"]:
9991005
flags |= RenderFlags.ALL_SOLID
10001006

1001-
if self.render_flags["shadows"]:
1007+
if self.render_flags["shadows"] and not self._is_software:
10021008
flags |= RenderFlags.SHADOWS_ALL
1003-
if self.render_flags["plane_reflection"]:
1009+
if self.render_flags["plane_reflection"] and not self._is_software:
10041010
flags |= RenderFlags.REFLECTIVE_FLOOR
10051011
if self.render_flags["env_separate_rigid"]:
10061012
flags |= RenderFlags.ENV_SEPARATE
@@ -1149,12 +1155,16 @@ def start(self, auto_refresh=True):
11491155
confs.insert(0, conf)
11501156
raise
11511157

1158+
# Determine if software emulation is being used
1159+
glinfo = self.context.get_info()
1160+
renderer = glinfo.get_renderer()
1161+
self._is_software = any(e in renderer for e in ("llvmpipe", "Apple Software Renderer"))
1162+
11521163
# Run the entire rendering pipeline first without window, to make sure that all kernels are compiled
11531164
self.refresh()
11541165

1155-
# At this point, we are all set to display the graphical window if requested
1156-
if not pyglet.options["headless"]:
1157-
self.set_visible(True)
1166+
# At this point, we are all set to display the graphical window
1167+
self.set_visible(True)
11581168

11591169
# Run the entire rendering pipeline once again, as a final validation that everything is fine
11601170
self.refresh()
@@ -1202,6 +1212,13 @@ def start(self, auto_refresh=True):
12021212
if not self._initialized_event.is_set():
12031213
self._initialized_event.set()
12041214

1215+
gs.logger.debug(f"Using interactive viewer OpenGL device: {renderer}")
1216+
if self._is_software:
1217+
gs.logger.info(
1218+
"Software rendering context detected. Shadows and plane reflection not supported. Beware rendering "
1219+
"will be extremely slow."
1220+
)
1221+
12051222
if auto_refresh:
12061223
while self._is_active:
12071224
try:

genesis/options/sensors/options.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -226,15 +226,15 @@ class IMU(RigidSensorOptionsMixin, NoisySensorOptionsMixin, SensorOptions):
226226
mag_random_walk : tuple[float, float, float]
227227
The standard deviation of the bias drift for each axis of the magnetometer.
228228
debug_acc_color : float, optional
229-
The rgba color of the debug acceleration arrow. Defaults to (0.0, 1.0, 1.0, 0.5).
229+
The rgba color of the debug acceleration arrow. Defaults to (1.0, 0.0, 0.0, 0.6).
230230
debug_acc_scale: float, optional
231231
The scale factor for the debug acceleration arrow. Defaults to 0.01.
232232
debug_gyro_color : float, optional
233-
The rgba color of the debug gyroscope arrow. Defaults to (1.0, 1.0, 0.0, 0.5).
233+
The rgba color of the debug gyroscope arrow. Defaults to (0.0, 1.0, 0.0, 0.6).
234234
debug_gyro_scale: float, optional
235235
The scale factor for the debug gyroscope arrow. Defaults to 0.01.
236236
debug_mag_color : float, optional
237-
The rgba color of the debug magnetometer arrow. Defaults to (1.0, 1.0, 0.0, 0.5).
237+
The rgba color of the debug magnetometer arrow. Defaults to (0.0, 0.0, 1.0, 0.6).
238238
debug_mag_scale: float, optional
239239
The scale factor for the debug magnetometer arrow. Defaults to 0.01.
240240
"""
@@ -261,12 +261,12 @@ class IMU(RigidSensorOptionsMixin, NoisySensorOptionsMixin, SensorOptions):
261261
mag_random_walk: MaybeTuple3FType = 0.0
262262
magnetic_field: MaybeTuple3FType = (0.0, 0.0, 0.5)
263263

264-
debug_acc_color: tuple[float, float, float, float] = (0.0, 1.0, 1.0, 0.5)
264+
debug_acc_color: tuple[float, float, float, float] = (1.0, 0.0, 0.0, 0.6)
265265
debug_acc_scale: float = 0.01
266-
debug_gyro_color: tuple[float, float, float, float] = (1.0, 1.0, 0.0, 0.5)
266+
debug_gyro_color: tuple[float, float, float, float] = (0.0, 1.0, 0.0, 0.6)
267267
debug_gyro_scale: float = 0.01
268-
debug_mag_color: tuple[float, float, float, float] = (0.0, 0.0, 1.0, 0.5)
269-
debug_mag_scale: float = 2.0
268+
debug_mag_color: tuple[float, float, float, float] = (0.0, 0.0, 1.0, 0.6)
269+
debug_mag_scale: float = 0.5
270270

271271
def model_post_init(self, _):
272272
self._validate_cross_axis_coupling(self.acc_cross_axis_coupling)

genesis/vis/viewer.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,6 @@ def build(self, scene):
137137

138138
gs.logger.info(f"Viewer created. Resolution: ~<{self._res[0]}×{self._res[1]}>~, max_FPS: ~<{self._max_FPS}>~.")
139139

140-
glinfo = self._pyrender_viewer.context.get_info()
141-
renderer = glinfo.get_renderer()
142-
gs.logger.debug(f"Using interactive viewer OpenGL device: {renderer}")
143-
144140
self._is_built = True
145141

146142
def run(self):

tests/test_render.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ def test_draw_debug(renderer, show_viewer):
10361036
@pytest.mark.parametrize("n_envs", [0, 2])
10371037
@pytest.mark.parametrize("renderer_type", [RENDERER_TYPE.RASTERIZER])
10381038
@pytest.mark.skipif(not IS_INTERACTIVE_VIEWER_AVAILABLE, reason="Interactive viewer not supported on this platform.")
1039-
def test_sensors_draw_debug(n_envs, renderer, png_snapshot):
1039+
def test_sensors_draw_debug(n_envs, renderer_type, renderer, png_snapshot):
10401040
"""Test that sensor debug drawing works correctly and renders visible debug elements."""
10411041
scene = gs.Scene(
10421042
viewer_options=gs.options.ViewerOptions(
@@ -1047,6 +1047,10 @@ def test_sensors_draw_debug(n_envs, renderer, png_snapshot):
10471047
# Enable running in background thread if supported by the platform
10481048
run_in_thread=(sys.platform == "linux"),
10491049
),
1050+
vis_options=gs.options.VisOptions(
1051+
# Disable shadows systematically for Rasterizer because they are forcibly disabled on CPU backend anyway
1052+
shadow=(renderer_type != RENDERER_TYPE.RASTERIZER),
1053+
),
10501054
profiling_options=gs.options.ProfilingOptions(
10511055
show_FPS=False,
10521056
),
@@ -1143,19 +1147,13 @@ def test_sensors_draw_debug(n_envs, renderer, png_snapshot):
11431147
if renderer == "Apple Software Renderer":
11441148
pytest.xfail("Tile ground colors are altered on Apple Software Renderer.")
11451149

1146-
try:
1147-
assert rgb_array_to_png_bytes(rgb_arr) == png_snapshot
1148-
except AssertionError:
1149-
# TODO: Need to investigate root cause and either fix rendering consistency
1150-
if sys.platform == "linux" and gs.use_ndarray:
1151-
pytest.xfail("Sensor debug drawing produces inconsistent results on Linux with static array mode.")
1152-
raise
1150+
assert rgb_array_to_png_bytes(rgb_arr) == png_snapshot
11531151

11541152

11551153
@pytest.mark.required
11561154
@pytest.mark.parametrize("renderer_type", [RENDERER_TYPE.RASTERIZER])
11571155
@pytest.mark.skipif(not IS_INTERACTIVE_VIEWER_AVAILABLE, reason="Interactive viewer not supported on this platform.")
1158-
def test_interactive_viewer_key_press(tmp_path, monkeypatch, renderer, png_snapshot):
1156+
def test_interactive_viewer_key_press(renderer_type, tmp_path, monkeypatch, renderer, png_snapshot):
11591157
IMAGE_FILENAME = tmp_path / "screenshot.png"
11601158

11611159
# Mock 'get_save_filename' to avoid poping up an interactive dialog
@@ -1188,6 +1186,10 @@ def on_key_press(self, symbol: int, modifiers: int):
11881186
# 'EventLoop.run() must be called from the same thread that imports pyglet.app'.
11891187
run_in_thread=(sys.platform == "linux"),
11901188
),
1189+
vis_options=gs.options.VisOptions(
1190+
# Disable shadows systematically for Rasterizer because they are forcibly disabled on CPU backend anyway
1191+
shadow=(renderer_type != RENDERER_TYPE.RASTERIZER),
1192+
),
11911193
renderer=renderer,
11921194
show_viewer=True,
11931195
show_FPS=False,

tests/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
DEFAULT_BRANCH_NAME = "main"
3838

3939
HUGGINGFACE_ASSETS_REVISION = "ca29b66018b449a37738257a3a76a78529d29bcc"
40-
HUGGINGFACE_SNAPSHOT_REVISION = "0cf1780dd70b67dc426023cd97738037f0d834e3"
40+
HUGGINGFACE_SNAPSHOT_REVISION = "bbce87b3546a12e3f86bf2b465efa82775a7f752"
4141

4242
MESH_EXTENSIONS = (".mtl", *MESH_FORMATS, *GLTF_FORMATS, *USD_FORMATS)
4343
IMAGE_EXTENSIONS = (".png", ".jpg")

0 commit comments

Comments
 (0)