godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.07k stars 69 forks source link

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

Open zomby138 opened 9 months ago

zomby138 commented 9 months ago

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 commented 9 months ago

Reposting my comment from https://github.com/godotengine/godot/issues/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:

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 commented 9 months ago

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

zomby138 commented 4 months ago

@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 commented 4 months ago

@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 commented 4 months ago

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 commented 4 months ago

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