Skip to content

Expose Lightmap Baking#1293

Open
GeneralProtectionFault wants to merge 1 commit into
Redot-Engine:masterfrom
GeneralProtectionFault:expose-lightmaps
Open

Expose Lightmap Baking#1293
GeneralProtectionFault wants to merge 1 commit into
Redot-Engine:masterfrom
GeneralProtectionFault:expose-lightmaps

Conversation

@GeneralProtectionFault

@GeneralProtectionFault GeneralProtectionFault commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

This is strictly copying the code from the following PR so we can get it in with the changes that have occurred since:
#8

Summary by CodeRabbit

  • New Features
    • Updated LightmapGI baking API/docs and scripting exposure to accept from_node and optional image_data_path.
    • Environment panorama baking for scene/custom-sky now uses 128×128 resolution.
  • Bug Fixes
    • Improved layered atlas save/reimport behavior, with more reliable results in both editor and non-editor baking.
  • Chores
    • Lightmapper build/feature flags now better restrict unsupported mobile platforms and make denoising behavior tool-build dependent (with a built-in fallback otherwise).

@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9ea86fda-d579-42b7-913d-3d2cd5cff031

📥 Commits

Reviewing files that changed from the base of the PR and between 5817262 and ac7cf93.

📒 Files selected for processing (7)
  • doc/classes/LightmapGI.xml
  • editor/scene/3d/lightmap_gi_editor_plugin.cpp
  • modules/lightmapper_rd/config.py
  • modules/lightmapper_rd/lightmapper_rd.cpp
  • modules/xatlas_unwrap/config.py
  • scene/3d/lightmap_gi.cpp
  • scene/3d/lightmap_gi.h
✅ Files skipped from review due to trivial changes (1)
  • doc/classes/LightmapGI.xml
🚧 Files skipped from review as they are similar to previous changes (6)
  • editor/scene/3d/lightmap_gi_editor_plugin.cpp
  • modules/lightmapper_rd/config.py
  • scene/3d/lightmap_gi.h
  • modules/lightmapper_rd/lightmapper_rd.cpp
  • modules/xatlas_unwrap/config.py
  • scene/3d/lightmap_gi.cpp

Walkthrough

Adds an internal _bake path and public LightmapGI::bake(from_node, image_data_path) API, changes atlas and panorama baking behavior, updates the editor plugin call site, and gates module build and OIDN denoiser code behind editor/tooling conditions.

Changes

LightmapGI bake API rework

Layer / File(s) Summary
Bake method declarations and documentation
scene/3d/lightmap_gi.h, doc/classes/LightmapGI.xml
Adds _dummy_bake_func_step and _bake declarations, and documents the new bake(from_node, image_data_path) method and its behavior.
Bake implementation and binding
scene/3d/lightmap_gi.cpp
Introduces the public bake(from_node, image_data_path) wrapper, exposes _bake(...) as the internal step-based implementation, updates the bound signature, and adds the includes used by the revised baking flow.
Atlas reimport and panorama baking
scene/3d/lightmap_gi.cpp
Splits atlas texture generation between editor-hint reimport flow and runtime direct save flow, and updates environment panorama baking to use 128x128 with temporary sky radiance adjustments outside the editor.
Editor plugin caller update
editor/scene/3d/lightmap_gi_editor_plugin.cpp
Updates LightmapGIEditorPlugin::_bake_select_file() to call _bake(...) instead of bake(...).

Lightmapper module build and TOOLS_ENABLED gating

Layer / File(s) Summary
Module build eligibility changes
modules/lightmapper_rd/config.py, modules/xatlas_unwrap/config.py
Updates can_build to use editor/module flags and to reject Android and iOS builds.
TOOLS_ENABLED gating in lightmapper_rd
modules/lightmapper_rd/lightmapper_rd.cpp
Wraps OIDN-related includes, _denoise_oidn, OIDN executable lookup, and denoise branching in TOOLS_ENABLED, and adds the non-tools shadowmask fallback path.

Sequence Diagram(s)

sequenceDiagram
  participant LightmapGIEditorPlugin
  participant LightmapGI
  participant ResourceLoader
  participant ResourceSaver
  LightmapGIEditorPlugin->>LightmapGI: _bake(from_node, image_data_path, bake_step)
  LightmapGI->>ResourceLoader: import(atlas_path)
  LightmapGI->>ResourceSaver: save(Texture2DArray, atlas_path)
  LightmapGI->>LightmapGIEditorPlugin: return BakeError
Loading

Estimated code review effort: 3 (Moderate) | ~25 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: making Lightmap baking publicly accessible.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 5

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
modules/lightmapper_rd/lightmapper_rd.cpp (1)

2104-2138: 🩺 Stability & Availability | 🔴 Critical | ⚡ Quick win

Fix the non-TOOLS_ENABLED fallback in modules/lightmapper_rd/lightmapper_rd.cpp
modules/lightmapper_rd/SCsub adds this source unconditionally, and modules/lightmapper_rd/config.py allows the module in non-editor builds. In that path, the #else branch inside if (p_bake_shadowmask) is wrong: it calls _denoise(...) without unocclude_tex and uses light_accum_tex instead of shadowmask_tex, so export-template builds with this module enabled will fail here.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@modules/lightmapper_rd/lightmapper_rd.cpp` around lines 2104 - 2138, The
non-TOOLS_ENABLED fallback in the shadowmask denoise path is incorrect and will
break non-editor builds. In the `lightmapper_rd.cpp` bake flow, fix the `#else`
branch inside `if (p_bake_shadowmask)` so it uses the shadowmask textures and
the same `_denoise(...)` signature expected there, including the `unocclude_tex`
argument where required. Ensure the fallback mirrors the `denoiser ==
1`/built-in branches’ data flow for `shadowmask_tex` and `shadowmask_tex2`,
rather than reusing `light_accum_tex`.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@doc/classes/LightmapGI.xml`:
- Around line 18-29: Update the LightmapGI.bake documentation wording so it
matches the actual return type and behavior: the method returns a
LightmapGI.BakeError int, not images. In the description for bake, replace the
headless-editor note in a way that refers to the bake result/return value being
null or invalid rather than “the images returned,” and keep the wording
consistent with the bake() method’s existing return semantics.

In `@scene/3d/lightmap_gi.cpp`:
- Around line 870-872: The non-editor bake path in `Lightmapper::bake` is
reusing the wrong image set and skipping the supersampling downsample. Move the
`texture_image->resize(...)` supersampling downsample so it runs for runtime
bakes too, not only under `is_editor_hint()`, and update
`texs->create_from_images(...)` to use the per-texture subset of `images` that
was assembled for each `texture_image` instead of the full vector. Use the
existing slice grouping logic around `images`, `texture_count`, and
`slices_per_texture` so each `r_textures[i]` contains only its own slices and
matches `lightmapper->get_bake_mesh_texture_slice(i)`.
- Around line 884-887: The atlas reimport path in LightmapGI::bake/lightmap
update flow ignores the return value of ResourceLoader::import(atlas_path),
which can hide a failed reimport behind a cached ResourceLoader::load result.
Check the Error from ResourceLoader::import first in the same block that loads
the TextureLayered, and if it is not OK, fail early with
LightmapGI::BAKE_ERROR_CANT_CREATE_IMAGE before attempting to load the texture.
- Around line 845-869: The import-preservation check in the lightmap atlas
export path is ineffective because the existing .import file is never loaded
before updating the ConfigFile. In the atlas save flow inside the lightmap GI
bake logic, restore loading of config_path into the ConfigFile before calling
has_section_key and set_value so existing import settings are read first; then
keep the conditional update for compress/mode in the same block so
user-customized values are not overwritten.
- Around line 1289-1298: The ENVIRONMENT_MODE_CUSTOM_SKY handling in
lightmap_gi.cpp restores the sky radiance size unconditionally, unlike the
ENVIRONMENT_MODE_SCENE path that only restores when the value was actually
changed. Update the custom-sky branch in the same way: track whether
`environment_custom_sky->set_radiance_size(...)` was applied, and only call
`set_radiance_size(old_radiance_size)` when the size was modified so editor
bakes do not trigger unnecessary recomputation.

---

Outside diff comments:
In `@modules/lightmapper_rd/lightmapper_rd.cpp`:
- Around line 2104-2138: The non-TOOLS_ENABLED fallback in the shadowmask
denoise path is incorrect and will break non-editor builds. In the
`lightmapper_rd.cpp` bake flow, fix the `#else` branch inside `if
(p_bake_shadowmask)` so it uses the shadowmask textures and the same
`_denoise(...)` signature expected there, including the `unocclude_tex` argument
where required. Ensure the fallback mirrors the `denoiser == 1`/built-in
branches’ data flow for `shadowmask_tex` and `shadowmask_tex2`, rather than
reusing `light_accum_tex`.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 09f48f42-d011-4de3-8a22-76daf7835335

📥 Commits

Reviewing files that changed from the base of the PR and between 4f5b14a and 84bfb16.

📒 Files selected for processing (7)
  • doc/classes/LightmapGI.xml
  • editor/scene/3d/lightmap_gi_editor_plugin.cpp
  • modules/lightmapper_rd/config.py
  • modules/lightmapper_rd/lightmapper_rd.cpp
  • modules/xatlas_unwrap/config.py
  • scene/3d/lightmap_gi.cpp
  • scene/3d/lightmap_gi.h

Comment thread doc/classes/LightmapGI.xml
Comment thread scene/3d/lightmap_gi.cpp Outdated
Comment thread scene/3d/lightmap_gi.cpp
Comment thread scene/3d/lightmap_gi.cpp
Comment thread scene/3d/lightmap_gi.cpp
Comment thread modules/lightmapper_rd/lightmapper_rd.cpp Outdated
@GeneralProtectionFault GeneralProtectionFault force-pushed the expose-lightmaps branch 2 times, most recently from 41c920a to 5817262 Compare July 3, 2026 03:16
@GeneralProtectionFault

Copy link
Copy Markdown
Contributor Author

So looks like this is cleaned up, but I'm not sure what sourcelocation meant by this in the original PR:

module_lightmapper_rd_enabled build parameter has to be enabled for runtime baking to work
module_xatlas_unwrap_enabled, build parameter has to be enabled for runtime unwrapping to work

Those aren't valid flags for scons when I try to build it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants