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.
655 stars 91 forks source link

Lightmap working fine first time, but not applying on subsequent #39

Open LethalHonor opened 3 years ago

LethalHonor commented 3 years ago

Hello there.

I have a problem with baking a prefab and I don't know how to proceed.

I have added the script to a prefab with some models and terrains. When the baking process is over, you can see the effect on the terrain: the objects cast shadows in the terrain.

LHE - 01 - Baked shadows work perfectly

But if I remove the prefab from the scene and add it again, it should show the same lightmapping as before, but in this case, they are removed: LHE - 02 - Removed and added again - Not showing baked shadows

If I play the game and instantiate that prefab in another scene (the purpose of the asset), the shadows are gone too. LHE - 03 - Instantiated in realtime in another scene - Not showing baked shadows

What am I doing wrong? Thanks a lot for your time!!!

Ayfel commented 3 years ago

Does it bake other shadows? I see some shadows in that asset and some others that are missing. What are your lighting settings?

LethalHonor commented 3 years ago

Hello there!

Not, it doesn't bake any shadows at all. The shadows you see are black sprites we use to simulate shadows. For example, this is the scene with no light baking: LHE - 04 - Black sprites shadows - No baked

This is after Asset - Bake prefab lightmap: LHE - 04-2 - Baked map

Then, if I remove the prefab from the scene and add it again, it should reload the lightmap info from the script but... it doesn't. LHE - 04-3 - Removed and added again - Not baked lights

The PrefabLightmapData script in the prefab is filled and fine, but It seems not to apply the lightmap info when added to the scene or instantiated in-game: LHE - 04-4 - The info is fine

More info:

Additional info for other scenes:

In other scenes, the lightmap script works for some lights, but it doesn't work (all lights are set exactly the same). Or maybe the problem is a misplacement?

For example: For an indoors scene If I bake the lights, I get this result: LHE - 06 - Closed scene - Baked light

But when I remove the prefab and add it again to the same scene (or instantiate in-game in real-time), I see this: LHE - 06 - Closed scene - Removed and then deleted - Not working some lights

It looks like it has something to do with not getting the information right when it comes to loading the lightmap info...

These are the lighting settings for this scene: LHE - 07 - Indoors scene - Lighting settings

Any ideas on how to proceed??

Thanks a lot!

Ayfel commented 3 years ago

First I recommend including the light in the prefab, just in case you don't already as the script should keep track of the lights in order to apply the mixed ones in the proper way. This is an issue of mixed lights mainly. Let me know if that solves your issue, otherwise we can look at it in a bit more detail and try to replicate the issue.

Another question for reference, what renderer pipeline are you using?