Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Light3D bake mode that also bakes direct light for dynamic objects, and disables all real-time lighting computations #8040

Open
zomby138 opened this issue Oct 8, 2023 · 8 comments

Comments

@zomby138
Copy link

zomby138 commented Oct 8, 2023

Describe the project you are working on

Retro FPS with a lot of baked light, where performance is important.

Describe the problem or limitation you are having in your project

It's not currently possible to make a light that is fully baked. No matter what you do, the direct light is still calculated in real time on dynamic objects. The direct light can be baked onto the lightmaps, but not onto the probes. With shadows on, this light is very expensive, and even with shadows off, it costs more performance than it needs to.

Sometimes you want to use a light to make a room a little lighter, like a local ambient light. For this it is very useful to be able to make a light that is 100% baked.

Also, some older games did all of their lighting via something like probes, and we should be able to make games that emulate that retro style.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

You could add a thousand fully baked lights to a scene without it costing any runtime performance whatsoever (because the overhead from using lightmaps and probes is constant, no matter how many, or few lights you have in your scene.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

There would be one more option in the "Bake Mode" drop down for a light. It could be called "Fully Baked", "Baked Direct", "Baked Only" or something.

A light with this setting would bake it's direct light into the like probes, in addition to the lightmap. Then at runtime the light node does absolutely nothing whatsoever. No being added to any clusteres, no calls to "void light()" in the shader of dynamic objects or anything.

If this enhancement will not be used often, can it be worked around with a few lines of script?

I don't think there is any way to work around this. If there it, I would be happy to do it.

Is there a reason why this should be core and not an add-on in the asset library?

It's core in other engines.

@Calinou Calinou changed the title The option for fully baked lights Add a Light3D bake mode that also bakes direct light for dynamic objects, and disables all real-time lighting computations Oct 9, 2023
@Calinou
Copy link
Member

Calinou commented Oct 9, 2023

Reposting my comment from godotengine/godot#73289 for posterity:


I have a proof of concept: https://github.com/Calinou/godot/tree/light3d-add-static-baked-mode

Testing project: test_light3d_baked_static_mode.zip

It has some issues:

  • It crashes when you use Scene > Reload Saved Scene due to the culling code having some "uneven" cases with lights sometimes being paired, sometimes not. The goal here is to have the Static Baked lights never added to the list of instances to render. Only the lightmapper (and perhaps the VoxelGI baker in the future) should bother about these nodes.
  • Toggling visibility of a Static Baked light breaks lightmap rendering, likely due to an error in my culling code changes.
  • Lightmap probes don't take direct light into account for these Static Baked lights yet.

However, I was able to get a successful bake with lightmaps having the Static Baked lights present, yet dynamic objects not being lit by these lights in real-time at all.

Light3D bake modes from left to right: Disabled, Static, Dynamic, Static Baked. The white box is a static (baked) object, while the cyan torus is a dynamic object.

image

I'd appreciate help on this area as I'm not sure how to modify the lightmap probe baking code to get it to bake direct light for lights that use the Static Baked bake mode (and only those lights).

@jcostello
Copy link

@Calinou maybe Dario can help you since he worked in the implementation of the indirect light for probes

@zomby138
Copy link
Author

@Calinou I'd like to get your branch running. I built the code. How do I set a light to be the new Static Baked mode?

@Calinou
Copy link
Member

Calinou commented Feb 22, 2024

@Calinou I'd like to get your branch running. I built the code. How do I set a light to be the new Static Baked mode?

There's a Bake Mode property (or GI Mode, I forgot) in the Light3D inspector. Note that the branch isn't in a fully functional state yet, so you'll need to modify to be able to use it in production.

@zomby138
Copy link
Author

image

These are the options for Bake Mode, just the same as in the trunk.

image

light_3d.cpp line 380 from your branch.

I don't want to use the branch for production. I want to help you get it working and have it merged into the trunk. I am a professional mathematician and I can take a look at the spherical harmonics stuff.

@Calinou
Copy link
Member

Calinou commented Feb 22, 2024

@zomby138 I've force-pushed an update to the branch that rebases it against master and fixes the property hint in Light3D.

@bertodelrio256
Copy link

bertodelrio256 commented Dec 10, 2024

Id like to add that it would also be nice to have a GI mode which allows a dynamic mesh to contribute to the lightmap "cast shadows, bounce light, etc.." but does not use the lightmap texture and uses the baked light probes. an example would be tree foliage, where I dont have enough lightmap density to cover an entire forest, but would like the leaves to cast shadows into the lightmap and just use probes for lighting. this might be a separate topic from this proposal though.

@Calinou
Copy link
Member

Calinou commented Dec 10, 2024

Id like to add that it would also be nice to have a GI mode which allows a dynamic mesh to contribute to the lightmap "cast shadows, bounce light, etc.." but does not use the lightmap texture and uses the baked light probes. an example would be tree foliage, where I dont have enough lightmap density to cover an entire forest, but would like the leaves to cast shadows into the lightmap and just use probes for lighting. this might be a separate topic from this proposal though.

This is being tracked in godotengine/godot#96538.

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

No branches or pull requests

4 participants