godot icon indicating copy to clipboard operation
godot copied to clipboard

Expose runtime baking functionality in LightmapGI

Open RisingThumb opened this issue 1 year ago • 10 comments
trafficstars

This will resolve https://github.com/godotengine/godot/issues/59217 This partially resolves https://github.com/godotengine/godot-proposals/issues/8656 . It exposes bake() for scripting, however there isn't any cancelling or aborting yet. ~~Additionally it does not currently work for exported projects.~~ It also works for exported projects

Implementation notes:

  • As .exr files cannot be imported at runtime, I save as a .res. This is also because when the lightmapper is available in exported projects, we can use .res files, while we can't save .exr files
  • The radiance changes setting to Radiance 128, and then resetting back to what it was, is because the lightmaps were not generating correctly at runtime using the Scene/Custom Sky environment options. Setting it to 128 fixes this. I am not sure what is causing this, possibly something related to environment_bake_panorama or sky_bake_panorama. There is a related Size2i parameter for this radiance size, but setting that to 256 while using a radiance size of 256 doesn't fix this issue.
  • Is there a better way of converting from an image to a texturelayered?

RisingThumb avatar May 07 '24 19:05 RisingThumb

In which cases you will bake lightmap in runtime?

jcostello avatar May 08 '24 04:05 jcostello

In which cases you will bake lightmap in runtime?

In custom level editors built with godot

Also when reimporting levels in godot while the game is running. Here's me taking advantage of the fact that VoxelGI can be baked at runtime: https://twitter.com/passivestar_/status/1780433192211612039

passivestar avatar May 08 '24 09:05 passivestar

In which cases you will bake lightmap in runtime?

This opens up the opportunity for having a script that goes through all your maps/scenes and baking these lightmaps, rather than doing it in-editor, since the editor process is manual currently. So if you want a lot of high quality lightmaps for a lot of scenes, you can go away and do something else in the meantime. Additionally, it also opens it up for custom map makers in a similar way to Quake, where the lightmaps need to be baked(however this would require additional work for it to work in exports).

Note that bake() will still not work in exported projects, as lightmapping and automatic UV unwrapping (xatlas) functionality is only available in the editor to decrease binary size. bake() will only work in projects run from the editor, as well as the editor itself.

That said this is currently for runtime with the editor, not currently in exported builds(quoted from #59217 ), so it doesn't get us all the way there yet, but at least to the same state Godot 3.X was at which for projects like func_godot, is still very helpful

RisingThumb avatar May 08 '24 10:05 RisingThumb

I'm joining the topicstarter.

I'm creating an engine for a game based on Godot, but the maps are outside the resource file system. They are located in the next folder with the executable file. They are created in TrenchBroom (*.map-files). I use my own parser for these files. Not Quodot and not func_godot. To build them, I call the game executable file via the command line:

> game.exe --headless -- build path/to/file.map

Here a packed scene is created and saved to another external *.scn-file. The scene stores the geometry, light, physics and location of the player, monsters, game objects as well as the conditions for switching to another map. The map file does not embed textures, materials and internal details of game objects. Everything goes fine and after that the scene can be opened and played.

I really miss the ability to bake light in map building script.

nklbdev avatar May 13 '24 09:05 nklbdev

Please discuss the feature itself in the proposal, as comments on the pull request should only refer to the implementation.

Calinou avatar May 13 '24 16:05 Calinou

Hi, I tried compiling this fork and I was surprised to find that the exported project (at least the debug build, haven't checked release yet) actually can bake lightmaps into .res file format, however they don't look right. I assume it's due to slice counts. The first screenshot is a lightmap compiled from within the editor, and the second is from the game.

image image

(Temporarily disabled denoiser)

What leads me to believe this is an issue with slices is the fact that if I change the vertical slice count from 2 to 1, I get a rather similar broken lightmap to the one I got while baking in the game. image

As there aren't any import options for .res files, I'm not sure what the issue could be here. I want to contribute, I just can't figure out this problem. Do you have an idea by any chance @Calinou?

sourcelocation avatar Jul 23 '24 19:07 sourcelocation

Update: I got it working in the exported project here https://github.com/RisingThumb/godot/pull/1. This is my first ever contribution to the Godot's codebase, so probably a lot of things are wrong there. I need some assistance.

sourcelocation avatar Jul 25 '24 14:07 sourcelocation

Thanks @sourcelocation , I've merged your changes into this PR which make it possible to bake at runtime for exported projects into this PR. Also means it addresses the original issue more completely now, as it works for exported projects if module_lightmapper_rd_enabled and module_xatlas_unwrap_enabled are enabled 👍

RisingThumb avatar Jul 26 '24 21:07 RisingThumb

When can we expect this PR to be reviewed?

sourcelocation avatar Jul 28 '24 16:07 sourcelocation

When can we expect this PR to be reviewed?

4.3 is in feature freeze, so new features can only be merged in 4.4 at the earliest.

Also, there are merge conflicts that should be resolved. See Pull request workflow for instructions :slightly_smiling_face:

Calinou avatar Jul 28 '24 16:07 Calinou

@RisingThumb please confirm you have abandoned this PR

AThousandShips avatar Jul 31 '24 07:07 AThousandShips

Hi, I'm happy for this PR to be superseded by https://github.com/godotengine/godot/pull/94965

RisingThumb avatar Jul 31 '24 11:07 RisingThumb