Skip to content

Commit c66b958

Browse files
committed
Disable shadow and plane reflection when using software rendering.
1 parent ef34cd3 commit c66b958

File tree

6 files changed

+56
-42
lines changed

6 files changed

+56
-42
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: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959

6060

6161
pyglet.options["shadow_window"] = False
62+
pyglet.options["dpi_scaling"] = "real"
6263

6364

6465
MODULE_DIR = os.path.dirname(__file__)
@@ -366,9 +367,7 @@ def __init__(
366367
#######################################################################
367368
# Initialize OpenGL context and renderer
368369
#######################################################################
369-
self._renderer = Renderer(
370-
self._viewport_size[0], self._viewport_size[1], context.jit, self.render_flags["point_size"]
371-
)
370+
self._renderer = Renderer(*self._viewport_size, context.jit, self.render_flags["point_size"])
372371
self._is_active = True
373372

374373
# Starting the viewer would raise an exception if the OpenGL context is invalid for some reason. This exception
@@ -654,12 +653,18 @@ def on_close(self):
654653
super().close()
655654
except Exception:
656655
pass
657-
finally:
656+
try:
658657
super().on_close()
659-
try:
660-
pyglet.app.exit()
661-
except Exception:
662-
pass
658+
except Exception:
659+
pass
660+
try:
661+
pyglet.app.exit()
662+
except Exception:
663+
pass
664+
try:
665+
pyglet.app.platform_event_loop.stop()
666+
except Exception:
667+
pass
663668

664669
self._offscreen_semaphore.release()
665670

@@ -788,8 +793,8 @@ def on_resize(self, width: int, height: int) -> EVENT_HANDLE_STATE:
788793

789794
self._viewport_size = (width, height)
790795
self._trackball.resize(self._viewport_size)
791-
self._renderer.viewport_width = self._viewport_size[0]
792-
self._renderer.viewport_height = self._viewport_size[1]
796+
self._renderer.viewport_width = width
797+
self._renderer.viewport_height = height
793798
self.on_draw()
794799

795800
def on_mouse_motion(self, x: int, y: int, dx: int, dy: int) -> EVENT_HANDLE_STATE:
@@ -998,9 +1003,9 @@ def _render(self, camera_node=None, renderer=None, normal=False):
9981003
elif self.render_flags["all_solid"]:
9991004
flags |= RenderFlags.ALL_SOLID
10001005

1001-
if self.render_flags["shadows"]:
1006+
if self.render_flags["shadows"] and not self._is_software:
10021007
flags |= RenderFlags.SHADOWS_ALL
1003-
if self.render_flags["plane_reflection"]:
1008+
if self.render_flags["plane_reflection"] and not self._is_software:
10041009
flags |= RenderFlags.REFLECTIVE_FLOOR
10051010
if self.render_flags["env_separate_rigid"]:
10061011
flags |= RenderFlags.ENV_SEPARATE
@@ -1149,12 +1154,16 @@ def start(self, auto_refresh=True):
11491154
confs.insert(0, conf)
11501155
raise
11511156

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

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)
1165+
# At this point, we are all set to display the graphical window
1166+
self.set_visible(True)
11581167

11591168
# Run the entire rendering pipeline once again, as a final validation that everything is fine
11601169
self.refresh()
@@ -1202,6 +1211,13 @@ def start(self, auto_refresh=True):
12021211
if not self._initialized_event.is_set():
12031212
self._initialized_event.set()
12041213

1214+
gs.logger.debug(f"Using interactive viewer OpenGL device: {renderer}")
1215+
if self._is_software:
1216+
gs.logger.info(
1217+
"Software rendering context detected. Shadows and plane reflection not supported. Beware rendering "
1218+
"will be extremely slow."
1219+
)
1220+
12051221
if auto_refresh:
12061222
while self._is_active:
12071223
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: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,17 +1036,21 @@ 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(
10431043
camera_pos=(2.0, 2.0, 2.0),
10441044
camera_lookat=(0.0, 0.0, 0.2),
10451045
# Force screen-independent low-quality resolution when running unit tests for consistency
1046-
res=(640, 480),
1046+
res=(480, 320),
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
@@ -1181,13 +1179,17 @@ def on_key_press(self, symbol: int, modifiers: int):
11811179
scene = gs.Scene(
11821180
viewer_options=gs.options.ViewerOptions(
11831181
# Force screen-independent low-quality resolution when running unit tests for consistency
1184-
res=(640, 480),
1182+
res=(480, 320),
11851183
# Enable running in background thread if supported by the platform.
11861184
# Note that windows is not supported because it would trigger the following exception if some previous tests
11871185
# was only using rasterizer without interactive viewer:
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)