Skip to content

Heterogeneous visual materials with GPU attribute randomization - #6299

Merged
kellyguo11 merged 20 commits into
isaac-sim:developfrom
ooctipus:zhengyuz/kitless-visual-color-randomization
Aug 21, 2026
Merged

kellyguo11 merged 20 commits into
isaac-sim:developfrom
ooctipus:zhengyuz/kitless-visual-color-randomization

Conversation

@ooctipus

@ooctipus ooctipus commented Jun 30, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

This PR rebases visual-material randomization onto current develop and keeps the original declarative scene API while moving runtime writes onto renderer-native GPU paths.

Architecture and ownership

VisualMaterialCfg remains a first-class AssetBaseCfg in InteractiveSceneCfg:

  1. The material is declared beside the robot and other assets.
  2. Its source prim is spawned before assets that bind it.
  3. It participates in the same clone plan as the rest of the scene. {ENV_REGEX_NS} creates one material clone per environment; an absolute path creates one shared material.
  4. Normal asset initialization resolves the cloned material/shader paths and registers the material with RenderContext.
  5. RenderContext concatenates each numeric channel into one flat device buffer and asks active renderer/visualizer consumers for their writer.
  6. Reset/runtime events sample directly on the target device and use one generic Warp scatter to update selected material/environment rows.

There is no owner-asset hierarchy, plan merging/reindexing, queued-material adapter, runtime relationship rewrite, or SimulationContext material service. SimulationContext only owns the shared RenderContext lifecycle.

Runtime backend paths

  • Kit / Isaac RTX: cached Fabric shader selections and batched Warp writes.
  • OVRTX: cached native addresses for both legacy and OVStage APIs; dirty channel buffers are published directly from CUDA. Native cloning preserves relative material bindings.
  • Newton: material bindings are compiled once into flat material-to-shape rows, then color updates scatter into model.shape_color with one Warp launch.

Runtime material writes do not author USD, walk the stage, transfer environment IDs to the CPU, convert tensors to lists, or loop over environment rows in Python. USD work is restricted to scene construction/import. OVRTX currently publishes the full dirty channel because its write API does not expose indexed row updates; the Lab-side partial reset remains a device scatter.

Public behavior

VisualMaterialCfg, VisualMaterial.write_channels, read_channel, randomize_visual_material, randomize_visual_color, and the Newton-only randomize_visual_shape event remain available.

Numeric channels are:

  • Preview Surface: color, roughness, metallic, emissive color, opacity.
  • OmniPBR: color, roughness, metallic, specular, emissive color/intensity, opacity, UV scale/offset/rotation.
  • OmniGlass: color, frosting roughness, and IOR.

Texture asset paths remain construction-time USD data. One static texture may be preloaded and its numeric UV channels randomized, but runtime texture-path selection is intentionally unsupported by this GPU-only pipeline. prestartup material writes are also rejected because renderer writers exist only after scene cloning/finalization.

Material and shape granularity stay separate:

  • randomize_visual_material samples per declared material and environment on supported renderers.
  • randomize_visual_shape samples per selected link and environment against Newton's live shape storage. Other renderers should declare one material per independently randomized part.

Demo

scripts/demos/visual_color_randomization.py keeps the original heterogeneous five-style ANYmal scene:

  1. Original authored appearance.
  2. Textured body, legs, and feet.
  3. Glass body, legs, and feet.
  4. Solid body, legs, and feet.
  5. Mixed textured body, solid legs, and glass feet.

Each family uses scene-declared per-environment materials for body, legs, and feet. The demo defaults to 512 environments and resets random subsets so partial writes are visible.

# PhysX + Kit/Fabric
uv run --extra isaacsim python scripts/demos/visual_color_randomization.py

# Newton physics + Newton GL
uv run python scripts/demos/visual_color_randomization.py \
    --physics newton_mjwarp --visualizer newton_gl

Validation

  • Repository formatting, Ruff, whitespace, conflict, codespell, license, RST, changelog, secret, and Git LFS gates passed.
  • Core material/event, scene lifecycle, USD relationship, PhysX/Fabric, Newton material/shape, OVRTX clone/material, and visualizer hook suites passed.
  • Broad cloner suite: 43 passed.
  • Local CI-equivalent core [2/3]: 78/78 files, 2,212 tests, 0 failures/errors, 16 skipped.
  • SimulationContext suite: 51 passed.
  • Fresh golden-image rendering passed for Kit/Fabric, Newton Warp, OVRTX legacy, and OVRTX OVStage.
  • git diff --check passed and uv.lock is unchanged.

Synchronized RTX 5090 measurements for 4096 environments:

Path Full reset 512-env partial reset
Core flat-buffer scatter 0.041 ms 0.044 ms
Newton material events 0.351 ms 0.368 ms
Kit/Fabric material events 1.008 ms 1.047 ms
OVRTX legacy publish 0.216 ms 0.233 ms
OVRTX OVStage publish 8.682 ms 8.329 ms

The production implementation is 862 net lines smaller than the previous PR revision (about 43%) while preserving the declarative asset/event/demo boundaries.

@github-actions github-actions Bot added the isaac-lab Related to Isaac Lab team label Jun 30, 2026
@greptile-apps

greptile-apps Bot commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR replaces the original Kit-only Replicator event with a fully refactored, three-backend visual-color randomization system (RTX/Isaac, kitless Newton, OVRTX). It introduces a shared backend-neutral VisualColorTargetPlan, a new prepare_before_physics_ready lifecycle hook on ManagerTermBase, and three independent writer classes that each own their renderer-specific stage mutations.

  • Architecture: EventManager now calls prepare_before_physics_ready on all class-based terms before PHYSICS_READY, enabling OVRTX/RTX to author USD materials before the renderer bakes the stage; the resolved plan is passed through cfg.__dict__ to __init__, which constructs a lazy writer after physics starts.
  • Newton writer: resolves shape rows once at construction into a padded index tensor, then performs a zero-copy wp.to_torch scatter with GPU-side sRGB encoding; the test suite includes a source-inspection assertion that forbids any host-sync call on the write path.
  • OVRTX writer: pre-bakes deterministic OmniPBR materials under a SHA-256-keyed scope before prepare_stage, then limits runtime writes to the new OVRTXRenderer.write_visual_colors boundary.

Confidence Score: 4/5

Safe to merge with minor follow-up; the new multi-backend architecture is solid and the test suite is thorough across all three renderer paths.

The rework is well-structured and heavily tested (69 tests across RTX, Newton, OVRTX, and unit suites). Two style-level concerns are worth noting: the colors identity dispatch in randomize_visual_color.call creates an undocumented coupling to the EventManager argument-passing behaviour, and the _find_matching_visual_prims token regex can misparse alternation body-name patterns, adding unexpected false-positive prims to the proxy-walk candidates. Neither causes incorrect output on any known codepath.

source/isaaclab/isaaclab/utils/visual_color.py (regex token BFS) and source/isaaclab/isaaclab/envs/mdp/events.py (call color dispatch) warrant a second look; all other files are clean.

Important Files Changed

Filename Overview
source/isaaclab/isaaclab/envs/mdp/events.py Refactored randomize_visual_color to a multi-backend architecture; added backend resolution, pre-physics-ready hook, and lazy writer construction. One subtle fragility in the per-call color-dispatch path.
source/isaaclab/isaaclab/utils/visual_color.py New backend-neutral target plan resolver; prim traversal, clone-plan integration, initial color reading, and env-id normalization. Token-level regex compilation inside _find_matching_visual_prims is unescaped.
source/isaaclab/isaaclab/managers/event_manager.py Adds prepare_before_physics_ready hook dispatch and promotes mode-validation checks before the hook runs; logic is correct.
source/isaaclab/isaaclab/managers/manager_base.py Adds no-op prepare_before_physics_ready classmethod to ManagerTermBase and guards callback registration against None cfg; both changes are safe.
source/isaaclab_newton/isaaclab_newton/visual/newton_shape_color_writer.py New kitless Newton sink: resolves shape rows once, pads into a fixed-width index tensor, and performs zero-copy Torch scatter with sRGB encoding. Logic is correct and the test suite validates the hot path sync-free contract.
source/isaaclab_ov/isaaclab_ov/visual/ovrtx_visual_color_writer.py OVRTX writer pre-bakes deterministic OmniPBR materials and drives runtime writes through OVRTXRenderer.write_visual_colors. Validation and de-instancing logic is thorough.
source/isaaclab_ov/isaaclab_ov/renderers/ovrtx_renderer.py Adds write_visual_colors public boundary that forwards to the private renderer handle; encapsulation is correct.
source/isaaclab/isaaclab/renderers/render_context.py Adds renderer_entries property returning a read-only tuple snapshot; straightforward and safe.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant U as User / EnvCfg
    participant EM as EventManager
    participant RVC as randomize_visual_color
    participant VCU as visual_color utils
    participant W as Backend Writer

    U->>EM: __init__(cfg)
    EM->>EM: deepcopy(term_cfg) + validate mode
    EM->>RVC: prepare_before_physics_ready(name, cfg, env)
    RVC->>VCU: resolve_visual_color_target_plan()
    VCU-->>RVC: VisualColorTargetPlan
    RVC->>W: pre_physics_ready_setup(env, plan)
    Note over W: RTX: de-instance prims
    Note over W: OVRTX: author USD materials
    Note over W: Newton: no-op
    RVC->>RVC: store plan on cfg.__dict__
    Note over EM,RVC: PHYSICS_READY
    EM->>RVC: __init__(cfg, env)
    RVC->>RVC: pop plan from cfg.__dict__
    Note over EM,W: First reset
    EM->>RVC: __call__(env, env_ids, colors)
    RVC->>RVC: normalize env_ids to target_indices
    RVC->>RVC: _ensure_writer() lazy construct
    RVC->>W: write_colors(target_indices, random_colors)
    W-->>RVC: colors written to renderer
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant U as User / EnvCfg
    participant EM as EventManager
    participant RVC as randomize_visual_color
    participant VCU as visual_color utils
    participant W as Backend Writer

    U->>EM: __init__(cfg)
    EM->>EM: deepcopy(term_cfg) + validate mode
    EM->>RVC: prepare_before_physics_ready(name, cfg, env)
    RVC->>VCU: resolve_visual_color_target_plan()
    VCU-->>RVC: VisualColorTargetPlan
    RVC->>W: pre_physics_ready_setup(env, plan)
    Note over W: RTX: de-instance prims
    Note over W: OVRTX: author USD materials
    Note over W: Newton: no-op
    RVC->>RVC: store plan on cfg.__dict__
    Note over EM,RVC: PHYSICS_READY
    EM->>RVC: __init__(cfg, env)
    RVC->>RVC: pop plan from cfg.__dict__
    Note over EM,W: First reset
    EM->>RVC: __call__(env, env_ids, colors)
    RVC->>RVC: normalize env_ids to target_indices
    RVC->>RVC: _ensure_writer() lazy construct
    RVC->>W: write_colors(target_indices, random_colors)
    W-->>RVC: colors written to renderer
Loading

Comments Outside Diff (1)

  1. source/isaaclab/isaaclab/utils/visual_color.py, line 921-933 (link)

    P2 |-alternation tokens compile as incorrect regexes. When mesh_prim_path is built from a list of body names (e.g. body_0|body_1), splitting on / yields a single token like body_0|body_1. Compiling ^body_0|body_1$ as a regex matches any string that starts with body_0 or ends with body_1 — not just the two intended names. The proxy-walk candidates would include spuriously matched prim names. The primary find_matching_prims result is unaffected, and downstream _resolve_visual_root filtering limits the blast radius to false positives in the proxy-augmented list, but targets with odd names could be added to the plan unexpectedly. Wrapping the token in a non-capturing group ((?:body_0|body_1)) before compiling fixes the alternation precedence.

Reviews (1): Last reviewed commit: "OMPE-96097: Simplify kitless visual colo..." | Re-trigger Greptile

Comment on lines +2905 to +2910
if colors is self.cfg.params.get("colors"):
color_low, color_high = self._color_low, self._color_high
else:
colors = colors if colors else self._cfg.params.get("colors")

# parse the colors into replicator format
if isinstance(colors, dict):
# (r, g, b) - low, high --> (low_r, low_g, low_b) and (high_r, high_g, high_b)
color_low = [colors[key][0] for key in ["r", "g", "b"]]
color_high = [colors[key][1] for key in ["r", "g", "b"]]
colors = [color_low, color_high]
else:
colors = list(colors)

num_prims = len(self.material_prims)
random_colors = self.color_rng.generator.uniform(colors[0], colors[1], size=(num_prims, 3))

rep.functional.modify.attribute(self.material_prims, "diffuse_color_constant", random_colors)
color_low_cpu, color_high_cpu = _visual_color_range(colors, "cpu")
color_low = color_low_cpu.to(env.device)
color_high = color_high_cpu.to(env.device)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Object-identity cache bypass is fragile. colors is self.cfg.params.get("colors") works today because EventManager passes kwarg values directly from cfg.params without copying, so the colors argument and the stored value are the same Python object. If the dispatch layer ever wraps or reconstructs params, this check would always be False, silently moving every call site onto the per-call _visual_color_range validation path and allocating new device tensors every reset. A sentinel or an explicit _override_colors keyword would make the contract visible.

Suggested change
if colors is self.cfg.params.get("colors"):
color_low, color_high = self._color_low, self._color_high
else:
colors = colors if colors else self._cfg.params.get("colors")
# parse the colors into replicator format
if isinstance(colors, dict):
# (r, g, b) - low, high --> (low_r, low_g, low_b) and (high_r, high_g, high_b)
color_low = [colors[key][0] for key in ["r", "g", "b"]]
color_high = [colors[key][1] for key in ["r", "g", "b"]]
colors = [color_low, color_high]
else:
colors = list(colors)
num_prims = len(self.material_prims)
random_colors = self.color_rng.generator.uniform(colors[0], colors[1], size=(num_prims, 3))
rep.functional.modify.attribute(self.material_prims, "diffuse_color_constant", random_colors)
color_low_cpu, color_high_cpu = _visual_color_range(colors, "cpu")
color_low = color_low_cpu.to(env.device)
color_high = color_high_cpu.to(env.device)
# Use cached bounds when the caller passes the config's own colors object (the common
# manager path). Any other object is treated as a per-call override and re-validated.
if colors is self.cfg.params.get("colors"):
color_low, color_high = self._color_low, self._color_high
else:
color_low_cpu, color_high_cpu = _visual_color_range(colors, "cpu")
color_low = color_low_cpu.to(env.device)
color_high = color_high_cpu.to(env.device)

Comment on lines +162 to +163
for token in normalized_expr.split("/")[1:]:
token_pattern = re.compile(f"^{token}$")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Token-level regex compilation uses raw token strings as patterns without escaping. re.compile(f"^{token}$") means a path component like env.0 would generate the pattern ^env.0$, which matches envX0, env_0, etc. USD prim names conventionally contain only [A-Za-z0-9_], so this is not an active bug, but adding re.escape for literal components makes the intent explicit and prevents silent mismatch if paths ever contain literal dots or other regex metacharacters.

Suggested change
for token in normalized_expr.split("/")[1:]:
token_pattern = re.compile(f"^{token}$")
for token in normalized_expr.split("/")[1:]:
# Escape literal components; leave explicit regex wildcards (.*) intact.
safe_token = token if token == ".*" else re.escape(token)
token_pattern = re.compile(f"^{safe_token}$")

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@ooctipus
ooctipus force-pushed the zhengyuz/kitless-visual-color-randomization branch 7 times, most recently from 3c0a3f9 to 19addc0 Compare July 1, 2026 00:06
@ooctipus
ooctipus requested a review from pascal-roth as a code owner July 1, 2026 00:06
@ooctipus
ooctipus force-pushed the zhengyuz/kitless-visual-color-randomization branch 2 times, most recently from 5c12e5c to 25aadef Compare July 1, 2026 00:47
@ooctipus
ooctipus requested a review from kellyguo11 as a code owner July 2, 2026 02:45
@ooctipus
ooctipus force-pushed the zhengyuz/kitless-visual-color-randomization branch from 698133f to f5cba20 Compare July 2, 2026 03:46
@ooctipus ooctipus changed the title OMPE-96097: Simplify kitless visual color randomization Heterogenous Visual Material Spawning and Support with new cloner Jul 6, 2026
@ooctipus
ooctipus force-pushed the zhengyuz/kitless-visual-color-randomization branch from 74ef76e to 6aa9155 Compare July 6, 2026 10:36
@ooctipus
ooctipus force-pushed the zhengyuz/kitless-visual-color-randomization branch from 5f9d7f0 to 5fc1039 Compare August 20, 2026 21:36

@pbarejko pbarejko left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved from perspective of stale golden images.

@kellyguo11
kellyguo11 merged commit c300f62 into isaac-sim:develop Aug 21, 2026
74 of 77 checks passed
@github-project-automation github-project-automation Bot moved this from In progress to Done in Isaac Lab Aug 21, 2026
@ooctipus
ooctipus deleted the zhengyuz/kitless-visual-color-randomization branch August 21, 2026 06:33
@ooctipus ooctipus mentioned this pull request Aug 21, 2026
1 task done
kellyguo11 added a commit that referenced this pull request Aug 21, 2026
…7240)

## Summary

Cherry-picks the following merged PRs from `develop` onto
`release/3.0.0`, preserving each as an individual commit with `-x`
provenance:

- #7218 — Flesh out the Manus glove workflow and pin the Isaac Teleop
build branch
- #7231 — Move the migration guide
- #6299 — Add heterogeneous visual materials with GPU attribute
randomization
- #7237 — Refresh Isaac Lab documentation

The commits are applied in their chronological `develop` order. All four
cherry-picks completed without conflicts.

## Validation

- Verified all four backported commits have patch IDs identical to their
source squash commits and retain their `cherry picked from` footers.
- `git diff --check upstream/release/3.0.0..HEAD`
- Release-base changelog validation passed.
- Focused cross-backend tests: **45 passed**
  - Core kitless visual-material spawning: 4 passed
  - Visual-material event behavior: 3 passed
  - Core visual-material pipeline: 12 passed
  - Newton visual-shape events: 2 passed
  - Newton visual-material renderer: 5 passed
  - OVRTX visual-material synchronization (`--extra ov`): 12 passed
  - PhysX visual-material writer: 5 passed
  - Kit and Newton visualizer hooks: 2 passed
- `uv run isaaclab -f` passed all code, formatting, whitespace, RST,
YAML/TOML, license, and repository-hygiene hooks. Its changelog hook
reported unrelated release/develop baseline fragments
(`fix-usd-replicate-def-ancestors.rst` and
`vidurv-nested-fragment-writers.rst`) followed by the known Windows
CP1252 reporting error; the targeted release-base changelog check
passed.

### Bounded integration attempts

- `test_visual_material_scene.py` was retried with the declared
`isaacsim` project extra and did not complete within the five-minute
local bound; it produced no failure diagnostics.
- The Kuka golden-image rendering integration did not complete within
the local bound. CI remains the authoritative result for the full Isaac
Sim and GPU/rendering paths.

---------

Co-authored-by: rwiltz <[email protected]>
Co-authored-by: Mustafa H <[email protected]>
Co-authored-by: ooctipus <[email protected]>
aneangel added a commit to aneangel/IsaacLab that referenced this pull request Aug 21, 2026
Resolves golden-image conflicts in franka_cloth/franka_soft by taking
develop's images (from the heterogeneous visual materials change,
isaac-sim#6299), since our branch's images were captured against pre-isaac-sim#6299
code and don't include that feature. These will need to be
regenerated again against the merged code to reflect both changes.
StafaH added a commit that referenced this pull request Aug 21, 2026
# Description

Remove the `AppLauncher` startup from
`test_shadow_hand_camera_presets.py`. The suite only constructs
configuration objects, resolves presets, and validates configuration
combinations; it does not create a stage, environment, sensor, or
rendered frame. The renderer configuration classes are now importable
without launching Kit.

The other direct `AppLauncher` uses under `isaaclab_tasks/test` were
audited and retained because they exercise live environments, physics
authoring, rendering, cameras, determinism, controllers, or RL wrappers.
The `test_preset_cli.py` reference only inspects the `AppLauncher`
argument contract and does not instantiate it.

No assertions, parametrization, or coverage were removed.

## Timing

Local end-to-end pytest timing for this file:

- before: 9.03 seconds
- after: 3.36 seconds

In PR #6299, this file reported 26.83 seconds wall time for 0.20 seconds
of test execution, so the CI saving may be larger on cold workers.

## Type of change

- Bug fix (non-breaking change which fixes an issue)

## Validation

- `uv run --frozen python -m pytest -q
source/isaaclab_tasks/test/core/test_shadow_hand_camera_presets.py` (42
passed)
- `uv run isaaclab -f`

## Checklist

- [x] I have read and understood the contribution guidelines
- [x] I have run the pre-commit checks
- [x] My changes generate no new warnings
- [x] The existing 42 tests cover the unchanged behavior
- [x] I have added a `.skip` changelog fragment for `isaaclab_tasks`
- [x] My name is already present in `CONTRIBUTORS.md`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation infrastructure isaac-lab Related to Isaac Lab team

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants