Skip to content

Expose LightmapGI.bake to scripting.#116429

Open
lyuma wants to merge 1 commit intogodotengine:masterfrom
V-Sekai:expose_bake_lightmap
Open

Expose LightmapGI.bake to scripting.#116429
lyuma wants to merge 1 commit intogodotengine:masterfrom
V-Sekai:expose_bake_lightmap

Conversation

@lyuma
Copy link
Contributor

@lyuma lyuma commented Feb 18, 2026

Closes godotengine/godot-proposals#8656
I had to expose a wrapper function to convert Callable to pair of (static bool()(...), void).

Also provides the feature needed for a custom lightmap manager addon / script to implement godotengine/godot-proposals#10323 (which I think is best done as an addon due to being workflow specific).

@lyuma lyuma force-pushed the expose_bake_lightmap branch 2 times, most recently from 439756b to b8910af Compare February 18, 2026 11:50
@lyuma lyuma force-pushed the expose_bake_lightmap branch from b8910af to a5f65cd Compare February 18, 2026 11:52
@passivestar
Copy link
Contributor

Tested, works mostly as expected in editor

But nothing gets printed out of the callable:

@tool
extends Button
class_name BakeLightmap

@export var lightmap: LightmapGI

@export_tool_button("Bake Lightmap", "LightmapGI")
var bake_lightmap_action = bake_lightmap

func _pressed() -> void:
	bake_lightmap()

func bake_lightmap() -> void:
	if lightmap:
		lightmap.bake(owner, "", func(progress: float) -> bool:
			print(progress)
			return false
		)

Also doesn't work at runtime. At runtime I tried saving to user:// and a bunch of other things but I'm getting a silent crash every time. Would be huge if it worked at runtime

@Calinou
Copy link
Member

Calinou commented Feb 21, 2026

Would be huge if it worked at runtime

Note that runtime baking will have the same constraints as #94965 (review), that is:

  • No saving to EXR format, as the TinyEXr library is only enabled in editor builds for binary size reasons. Only binary .res can be used as a format, as it supports HDR precision (while PNG and WebP in Godot don't). This makes for pretty large lightmap files on disk.
  • No way to have a progress bar; it's blocking.

@timklge
Copy link

timklge commented Feb 21, 2026

I had been following the previous PRs for runtime baking in exported projects and am still very much interested in this feature, thanks for bringing it up again. I'd like to use it in a game that features a map editor.

@Calinou To my understanding, this PR has already been merged that enables tiny_exr in exports.

I've tried to salvage the previously abandoned PR and merged it with this PR. The previous abandoned PR had working baking in export builds, but with all baked textures embedded as resources in the LightmapGIData, which resulted in huge files. I am not sure what is the best approach to use external resources with saved EXR files, since importing the EXR files through ResourceLoader is not possible in exported projects.

I've added new properties to LightmapGIData (light_texture_slice_counts, light_texture_img_paths) that are used to store the filenames of the referenced EXR files; when loading the LightmapGIData resource, the engine then attempts to load the linked EXR images. This appears to be working well in a test project:

bake.mp4

Changeset: master...timklge:godot:runtime_bake_lightmap
Test project: https://github.com/timklge/runtime_lightmap_bake_test

Built with scons platform=linuxbsd target=template_release tinyexr_export_templates=yes module_lightmapper_rd_enabled=yes production=yes lto=full.

EXR file + LightmapGIData resource are ~ 900 KB, embedded resource with the previous PR would have been ~ 6 MB for this tiny lightmap.

Would this be a viable approach? I'm not experienced with the engine code, there's probably some way to link the external resources without the importer at runtime.

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.

Expose method LightmapGI.bake() in editor and exported projects

5 participants