Ayfel / PrefabLightmapping

Script for saving lightmapping data to prefabs. Used through the Assets tab in Unity. Place your prefbas in the scene with this script at the root. Set up your lighting and in the editor go to Assets->Bake Prefab Lightmaps. After is processed you can now spawn your prefabs in different scenes and they will use the lightmapping from the original scene.
624 stars 89 forks source link

Double lighting #4

Closed rakkar1974 closed 4 years ago

rakkar1974 commented 4 years ago

If I have a static room with a static torch and use "Bake Prefab Lightmaps" this results in double lighting. First, the walls of the room display the baked lighting, indirect in subtractive and baked indirect mode, and both direct and indirect in shadowmask mode. Second, the torch casts light in the scene yet again, because Unity does not recognize this was a baked light and should not be rerendered. During the baking process Unity will save which lights were baked and which were not, so as to avoid this issue. This project doesn't do that. As a result, the project is not useful for prefabs that themselves include lights.

Ayfel commented 4 years ago

Can't you turn the light off in your prefab after baking?

rakkar1974 commented 4 years ago

It's not the same. Mixed lights for example bake indirect light but not direct light. You also would not have shadows you should have. It also means post-processing, Aura light, and other effects based on lights wouldn't work.

On Wed, Nov 20, 2019 at 10:35 AM Ayfel notifications@github.com wrote:

Can't you turn the light off in your prefab after baking?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Ayfel/PrefabLightmapping/issues/4?email_source=notifications&email_token=AHVNNPEJRN7MICX54K53CNTQUVKMLA5CNFSM4JPUPMRKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEESMMAA#issuecomment-556058112, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHVNNPBXCI7W6BN7XFGVEXLQUVKMLANCNFSM4JPUPMRA .

Ayfel commented 4 years ago

Yes I understand that, I might add that feature at some point, thanks for pointing that out. I had never encountered the issue before but it is obvious once you mention those cases.

Ayfel commented 4 years ago

@rakkar1974 I just committed a change adding support for that(lights as part of the prefabs), you shouldn't get anymore double lighting and I have checked things work well also in mixed modes. It is saving baked lightmaps in the prefabs, applying them at runtime and applying the proper light properties, like their mode and their type (at runtime as well).