Skip to content

feat(sim): filament renderer integration and mujoco 4.0 bump - #344

Merged
juelg merged 17 commits into
masterfrom
feat/filament
Nov 20, 2026
Merged

juelg merged 17 commits into
masterfrom
feat/filament

Conversation

@juelg

@juelg juelg commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor
  • add support for filament renderer
  • mujoco 4.0 bump
  • camera rendering ported to python (removed cpp rendering part -> become more performant due to frame copy avoid)
  • reduced default max ring buffer sizes in sim and hardware cameras to 30 (1 second for 30 fps)
  • fixed callbacks: called after mj_step2 to avoid stale image, unified to use the same callback structure for all, fixed callback timing to avoid drift
  • breaking: remove camera types as only fixed cameras were used (simplifies code)
  • fix buffer size max -> min

juelg added 14 commits October 6, 2026 16:23
- sim config flag that switches between renderers
- pystudio viewer when filament renderer is active
- fr3 cart example uses filament renderer
Filament moved out of mujoco.experimental in 4.0 and some mjrf bindings
were renamed (ModelObjects -> ModelResources, ReadPixelsRequest ->
ReadRequest, force_software_rendering -> software_rendering). Studio's
ViewerApp became mujoco.studio.app.App. Importing studio.window to
register Filament assets is no longer needed.

The Filament tests now only skip on mujoco < 4 and fail if the import
breaks, so a moved module can no longer silently skip them.
MuJoCo 4.0 renders Filament's depth draw mode without post processing,
so reading it into an R32F target gives reversed-z values that convert
to metric depth like the classic depth buffer. This replaces the extra
classic OpenGL depth pass of FilamentSimCameraSet and removes the now
unused _ClassicDepthRenderer.
Filament's OpenGL backend uses GLX on Linux: without an X display it
prints "Failed to open X display. (exiting)" and then hangs. Default to
Vulkan on Linux without DISPLAY and raise instead of hanging when OpenGL
is requested explicitly there.

Destroying a Filament Vulkan context on NVIDIA drivers calls
eglTerminate() on the default EGL display, which invalidates the classic
renderer's EGL context (eglMakeCurrent fails with EGL_NOT_INITIALIZED).
Filament contexts are therefore pooled per thread and reused instead of
destroyed. Pooled contexts are kept alive at exit, as destroying them on
the main thread aborts for contexts created by other threads.
All cameras share one mjvScene, and mjv_updateScene positions infinite
planes such as the floor relative to scene.camera before it updates the
camera, i.e. relative to the previously rendered camera. This shifted
the floor (and its shadows) by grid cells depending on which camera was
rendered before, so images differed between calls on the same state and
between single- and multi-camera setups. Update the camera before the
scene.
GPUs generally do not support 3 channel 8 bit render targets (Vulkan's
R8G8B8_UNORM has no image features on NVIDIA), so Filament emulates
RGB8 with a slow readback. Render into RGBA8 and drop alpha with
cv2.cvtColor, which is ~100x faster than a numpy slice copy. Images are
identical, 3 cameras at 1280x720 go from ~8.5 to ~5.3 ms on Vulkan.
Sim.register_state_capture records the simulation state (mj_getState)
at a fixed rate of simulation time into a ring buffer, e.g. at the
exposure times of a camera, so that frames can later be rendered from
the state a real camera would have recorded. Captures follow a fixed
schedule (no drift), happen at the physics step closest to each capture
time after integration, and restart on reset or when time goes back.
SimCameraSet now renders in Python with either MuJoCo's classic OpenGL
renderer or Filament, from a separate render-only MjData whose
kinematics are recomputed from the state, so images, time stamps and
extrinsics always belong together. With render_on_demand=True frames
show the state at request time; with render_on_demand=False they show
the state captured at each camera's frame rate (the last exposure of a
real camera) and are rendered from it on request.

This removes the C++ camera implementation (SimCameraSet, FrameSet,
Renderer and the rendering callbacks that ran in every physics step),
the C++ EGL context handoff and the EGL headers dependency. Rendering
from Python is faster: frames are read into numpy arrays directly
instead of being copied through Eigen and pybind11.
@juelg juelg changed the title feat(sim): filament renderer integration feat(sim): filament renderer integration and mujoco 4.0 bump Nov 14, 2026
Callbacks were called when more than seconds_between_calls had passed
since their last call, so each period was rounded up to the next physics
step and the calls drifted (e.g. 98 instead of 100 calls in 10 s at a
0.1 s interval and a 2 ms timestep). They also ran between mj_step1 and
mj_step2, i.e. on a state that was not yet integrated.

All callbacks now share the scheduling of the state captures: the k-th
call is due at start + k * period and happens at the closest physics
step, after integration. The schedule restarts on reset and whenever
the simulation time goes backwards, which previously stopped callbacks
until the time caught up again. The state capture is now a regular
callback with a restart hook instead of a separate mechanism, and since
nothing runs between the two step halves anymore, step uses mj_step.
The number of buffered framesets was max(len + 1, max_buffer_frames)
instead of min(...), so it was at least the buffer size after the first
frameset. Until the buffer was full once, get_timestamp_frames then
searched empty slots and failed an assertion.
Sim cameras could be free, tracking, fixed or default_free cameras, but
only fixed cameras were usable: SimCameraConfig had no parameters for
the pose of free or the target of tracking cameras, and the intrinsics
and extrinsics of default_free cameras silently came from the last
camera of the model. All env configs use fixed cameras, and moving
cameras, e.g. for videos, are cameras attached to a body or with a
tracking mode in MJCF.

SimCameraSet now always renders the camera of the model named by the
identifier and raises if it does not exist. CameraType, the type field
and src/sim/camera.h are removed, SimCameraConfig is kept as an alias
of BaseCameraConfig.

BREAKING CHANGE: rcs._core.sim.CameraType and the type argument and
field of SimCameraConfig are removed.
@juelg
juelg requested a review from pkrack November 20, 2026 22:05
@juelg
juelg merged commit 7963e8b into master Nov 20, 2026
7 checks passed
@juelg
juelg deleted the feat/filament branch November 20, 2026 23:38
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.

1 participant