Skip to content

Conversation

@Narsil
Copy link
Contributor

@Narsil Narsil commented Jan 8, 2026

Description

This reallows RasterizerCameraSensor to work with n_envs > 1.

The PyRenderer requires env_separate_rigid=True to correctly separate the rendering.
This requires OpenGL 4.2 which is not available on Metal.

I moved the errorring out to the .build() since I think it's easier on users to have errors earlier rather than later.

I chose not to change the batched dimension on the Rasterizer (it can return a non batched variant when use_separate_rigid=False) to minimize the surface of this change.

Diff unfortunately includes some ruff format modifications, not reverted automatically by black.
I can manually revert if necessary.

Motivation and Context

It's important to have rendering when using n_envs>1 in the context of leveraging the batched simulation.
This version works, even if not optimal compared to a purely batched rendering.

I decided to not change other renderers as they belong in other PRs IMHO.

Screenshots (if appropriate):

https://huggingface.co/datasets/Genesis-Intelligence/snapshots/commit/1029f0b5ec874b93dc5170179f7f5a3e770b10ea

Checklist:

  • I read the CONTRIBUTING document.
  • I followed the Submitting Code Changes section of CONTRIBUTING document.
  • I tagged the title correctly (including BUG FIX/FEATURE/MISC/BREAKING)
  • I updated the documentation accordingly or no change is needed.
  • I tested my changes and added instructions on how to test it for reviewers.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@Narsil Narsil force-pushed the nicolas/sensors_n_envs branch from b7d59ed to c76de2f Compare January 8, 2026 13:15
@duburcqa
Copy link
Collaborator

duburcqa commented Jan 8, 2026

Diff unfortunately includes some ruff format modifications, not reverted automatically by black.
I can manually revert if necessary.

Yes, that would be great indeed.

@Narsil Narsil force-pushed the nicolas/sensors_n_envs branch 5 times, most recently from 0e879d0 to cbd55e8 Compare January 8, 2026 14:19
@duburcqa
Copy link
Collaborator

duburcqa commented Jan 8, 2026

You should probably also apply this patch:

diff --git a/genesis/ext/pyrender/jit_render.py b/genesis/ext/pyrender/jit_render.py
index e163af05..beacb87c 100644
--- a/genesis/ext/pyrender/jit_render.py
+++ b/genesis/ext/pyrender/jit_render.py
@@ -374,7 +374,7 @@ class JITRenderer:
         self.gl = GLWrapper()

         IS_OPENGL_42_AVAILABLE = hasattr(self.gl.wrapper_instance, "glDrawElementsInstancedBaseInstance")
-        OPENGL_42_ERROR_MSG = "Seperated env rendering not supported because OpenGL 4.2 not available on this machine."
+        OPENGL_42_ERROR_MSG = "Separated env rendering not supported because OpenGL 4.2 not available on this machine."

         @nb.jit(
             nb.none(
diff --git a/genesis/ext/pyrender/renderer.py b/genesis/ext/pyrender/renderer.py
index 4f72e509..a3d7c2ed 100644
--- a/genesis/ext/pyrender/renderer.py
+++ b/genesis/ext/pyrender/renderer.py
@@ -152,7 +152,7 @@ class Renderer(object):

         if flags & RenderFlags.ENV_SEPARATE and flags & RenderFlags.OFFSCREEN:
             n_envs = scene.n_envs
-            use_env_idx = True
+            use_env_idx = True and scene.n_envs > 1
         else:
             n_envs = 1
             use_env_idx = False
diff --git a/genesis/vis/camera.py b/genesis/vis/camera.py
index c1fb8bfb..32cedefa 100644
--- a/genesis/vis/camera.py
+++ b/genesis/vis/camera.py
@@ -156,7 +156,7 @@ class Camera(RBC):
                 self._raytracer.add_camera(self)
             else:
                 self._is_batched = False
-                if self._visualizer.scene.n_envs > 0 and self._visualizer._context.env_separate_rigid:
+                if self._visualizer.scene.n_envs > 1 and self._visualizer._context.env_separate_rigid:
                     gs.logger.warning(
                         "Batched rendering via 'VisOptions.env_separate_rigid=True' is only partially supported by "
                         "Rasterizer for now. The same camera transform will be used for all the environments."
@@ -165,7 +165,7 @@ class Camera(RBC):
                 if self._env_idx is None:
                     if not self._is_batched:
                         self._env_idx = int(self._visualizer._context.rendered_envs_idx[0])
-                        if self._visualizer.scene.n_envs > 0:
+                        if self._visualizer.scene.n_envs > 1:
                             gs.logger.info(
                                 "Raytracer and Rasterizer requires binding to the camera with a specific environment "
                                 "index. Defaulting to 'rendered_envs_idx[0]'. Please specify 'env_idx' if necessary."

@Narsil Narsil force-pushed the nicolas/sensors_n_envs branch from cbd55e8 to df9e938 Compare January 8, 2026 14:26
@Narsil Narsil force-pushed the nicolas/sensors_n_envs branch from df9e938 to fbdfa79 Compare January 8, 2026 14:37
@Narsil
Copy link
Contributor Author

Narsil commented Jan 8, 2026

What does use_env_idx mean. I've seen it in the code, but I dont' really understand its purpose...

@Narsil Narsil force-pushed the nicolas/sensors_n_envs branch from fbdfa79 to 4f24497 Compare January 8, 2026 14:44
@duburcqa
Copy link
Collaborator

duburcqa commented Jan 8, 2026

What does use_env_idx mean. I've seen it in the code, but I dont' really understand its purpose...

use_env_idx is an internal flag of pyrender to determine whether it should filter "geometries" based on env idx (which requires OpenGL>4.2) and just consider all of them no matter what.

@Narsil Narsil force-pushed the nicolas/sensors_n_envs branch from 4f24497 to 7789708 Compare January 8, 2026 15:43
@Narsil Narsil force-pushed the nicolas/sensors_n_envs branch from f26e933 to 6083c08 Compare January 8, 2026 16:43
@duburcqa duburcqa merged commit baef3d4 into main Jan 8, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants