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.
618 stars 88 forks source link

How to merge LightingData assets for correct shading working? #69

Closed dimbodek closed 1 month ago

dimbodek commented 1 month ago

Hi, i use one scene for bake many prefabs separete because they do not depent from each other, so for saving time i bake each separete in same scene. So after each bake Lightmapper generate LightingData for last bake, and i've seen that without this date other prefabs not showing correct.

Ayfel commented 1 month ago

You can simply move your lightmapped textures after each bake, they don't need to be in the default folder unity puts them (which is why you are losing them I think), and that is all you need to be able to light your prefabs. So baking and moving the textures should be good for your usecase.

dimbodek commented 1 month ago

Beside textures unity also generates lightmapping data asset which some how also involve on shading visual and only one such asset can be applied to scene, so this is reason why i can bake separete prefabs.

dimbodek commented 1 month ago

Bakary do not generate such asset, i think it's just different lightning models, but unity does after each bake and such asset can be applied only to scene

Ayfel commented 1 month ago

The lightmap data asset is not used by this code at all, its only used by Unity "while" baking and in the settings. This script only references the lightmap textures when instantiating, etc. So simply moving them in your assets like I mentioned before should fix your issues.

dimbodek commented 1 month ago

unity uses lightmap data asset in play mode too, without it - shading looking another

Ayfel commented 1 month ago

This script (PrefabLightmapData.cs) doesn't, so I am not sure what your point is. I am going to close the thread as clearly there is not a bug or an issue and we are just discussing a point that is not relevant to the functionality of the code in this repo.

Here is the documentation so you can read about it https://docs.unity3d.com/Manual/LightmapSnapshot.html the only thing that the lightmap data asset has extra is information on probes, which are not supported in this script (although there is an alternative way we provide in LightProbeRuntime.cs to use them)

dimbodek commented 1 month ago

1 2 with assets and without, is shoud this plugin handle this in some way? you can see that light map asset affects on png lightmap and make it darker, in both screens same lightmap img, may be it's does gamma corection, i do not know

Ayfel commented 1 month ago

That looks like a real time light affecting the prefab or the scene environment lighting, etc.

dimbodek commented 1 month ago

yep, you are right, when remove this asset unity starts applyed mixed subtractive light(which i used for bake) like realtime directional, sorry i have't find normal docs about this lighting asset and i'am confusing what is it real does, now i see that it save information about mixed lights which was used for bake.

dimbodek commented 1 month ago

it's little bit distracted that when u use baked prefabs in another scene, unity applies mixed subtractive lights to them