Skip to content

[BUG FIX] Correctly render assets that pair a base color with an emissive map. - #3088

Merged
duburcqa merged 1 commit into
Genesis-Embodied-AI:mainfrom
duburcqa:packed_rgba_emissive_rendering
Jul 22, 2026
Merged

[BUG FIX] Correctly render assets that pair a base color with an emissive map.#3088
duburcqa merged 1 commit into
Genesis-Embodied-AI:mainfrom
duburcqa:packed_rgba_emissive_rendering

Conversation

@duburcqa

Copy link
Copy Markdown
Collaborator

Description

  • get_rgba (the packed-RGBA albedo consumed by the rasterizer and batch renderer) now prefers the authored base-color texture on every surface (Glass/Metal/Plastic/BSDF), and falls back to the emissive texture only when the base color is absent or fully black. The selection is centralized in a single _resolve_albedo helper instead of being duplicated per surface, so Glass and Emission now share the base get_rgba. Per-environment (batched) textures resolve this fallback independently for each environment, pairing base and emissive batches by least common multiple to match how the RGBA combiner handles batch dimensions.
  • The shared trimesh-visual builder (surface_uvs_to_trimesh_visual) bakes a surface's emissive into the material, so emissive is composited additively on top of the base color across every rasterizer path (rigid and deformable alike) through the common from_trimesh conversion. It is added only when the base color is the packed albedo; emissive that get_rgba already packs as albedo (emission-only assets, a black base color, or an Emission surface) is not added a second time.
  • Fixed a double-applied emissive factor in mesh.frag (the factor was already folded into the sampled emissive value).
  • The single baked UV set now follows whichever texture actually samples it: the base color owns it only when it is an atlas that requires UVs, so a flat base color defers the UV set to an emissive atlas instead of baking an unused one.
  • KHR_materials_unlit assets, whose imagery is surfaced through emissive, no longer render as the default white base; the base is given a black factor so the emissive is resolved as the albedo.

Related Issue

Resolves #3046
Resolves #2935

Supersedes #3038 (original base-color precedence fix by @NoahLinckeScout), extending it to all surfaces, additive emissive compositing across renderers, and glTF UV-set / unlit handling.

Motivation and Context

Some assets author a base color alongside an emissive map (e.g. vehicles); others zero their base-color factor and store the visible imagery in emissive (e.g. HLOD terrain tiles). The packed RGBA previously gave emissive unconditional precedence, so ordinary assets lost their base color, and assets with a sparse near-black emissive rendered almost entirely black in the rasterizer and batch renderer (only the ray tracer, which applies emission separately, was correct). A naive flip to always prefer diffuse would instead break the zero-base-factor tiles. Preferring a non-black base color with an emissive fallback handles both cases, and the rasterizer now reproduces glTF's additive emissive rather than silently discarding it.

How Has This Been / Can This Be Tested?

  • tests/rendering/test_offscreen.py::test_emissive_composites_over_base_color_without_double_counting - renders one rasterizer scene with entities added through the public API and separated per entity by segmentation. A rigid GLB (base atlas + emissive atlas) and a deformable (FEM) entity with a base color and an emissive each keep their base color dominant while the emissive lifts the blue channel (covering both the rigid and non-rigid render paths); a black-base emissive surface renders at the same brightness as the equivalent plain-color surface (its emissive, already packed as albedo, is not counted twice). This covers the base-over-emissive selection and its black-base fallback end to end.
  • tests/parsers/test_mesh.py::test_glb_uv_set_and_unlit_albedo_resolution - parses a GLB with three materials and checks the baked UV set (a base atlas owns it; a flat base defers it to the emissive atlas) and that an unlit material resolves its imagery as the albedo rather than the white default.
  • tests/rendering/test_offscreen.py::test_flat_base_with_image_emissive_keeps_uvs - checks the built visual keeps the UVs for a flat base color with an image emissive (a uniform atlas has no cheap rendered observable, so the visual is checked directly).
  • tests/core/test_misc.py::test_packed_rgba_resolves_batched_fallback_per_environment - checks that per-environment (batched) textures resolve the fallback independently for each entry; asserted on the packed RGBA because only the batch renderer consumes them.

Both render and parser tests fail on main and pass with this change. Programmatic GLB asset generation lives in the module-local conftest.py fixtures.

The batch renderer (gs-madrona) has no emissive field in its material schema, so it renders base-color-only; it still benefits from the base-color fix and no longer turns black.

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.

@duburcqa
duburcqa requested a review from YilingQiao as a code owner July 22, 2026 07:52

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 333940aba9

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread genesis/utils/mesh.py
@duburcqa
duburcqa force-pushed the packed_rgba_emissive_rendering branch 2 times, most recently from 39a7d00 to 7c45e43 Compare July 22, 2026 08:14
@duburcqa

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7c45e4367b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread genesis/options/surfaces.py
Comment thread genesis/options/surfaces.py Outdated
@duburcqa
duburcqa force-pushed the packed_rgba_emissive_rendering branch from 40568be to c8955cb Compare July 22, 2026 09:34
@duburcqa

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: c8955cb848

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@duburcqa
duburcqa merged commit 7c90d87 into Genesis-Embodied-AI:main Jul 22, 2026
19 of 20 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

1 participant