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

URP AssetBundle lighting corrupted #53

Open jmota-dev opened 2 years ago

jmota-dev commented 2 years ago

Hi,

I've been reading some threads in Unity Answers forums (Thread in Unity Answers Forum) and some issues here but I cannot fix the corrupted result of my lighting after using PrefabLightmapping scripts in a prefab built into an AssetBundle and uploaded to a server.

The thing is: I've set as "Custom" the "Lightmaps Modes" in "Shader stripping" and clicked on the "Import From Current Scene" button. After that, I set a root prefab containing all the meshes from that scene and click on "Baked Prefab Lightamps" just as you do in the README file. Once I do that, the prefab is shown properly, but if I build an AssetBundle with that prefab, download it from a server and instantiate that prefab into a different project (an identical copy of the project to avoid errors of having different lighting settings), the lights appear corrupted.

I have no idea from where the meshes come (I don't know if there's a way to check if the meshes were built in Probuilder or not).

I'm using: URP Unity 2020.3.27f1

This is one of the results.

Original: prefablightmapping

After instantiate from the AssetBundle: prefablightmapping_wrong

Any ideas about this?

Thanks!

Ayfel commented 2 years ago

It might have to do with URP although I think it should work. Can you try loading the bundle without going through the server first to test things out?

Also if you can send me a bundle and the project to reproduce it I could take a look

jmota-dev commented 2 years ago

I've just tried to load the AssetBundle from local and it happens the same.

You can take a look here: https://we.tl/t-6rH7jQAwKw

In the StreamingAssets folder, you can find the AssetBundle I'm using to do these tests. In the Scene "SampleScene" you can check the prefab I'm using and in the scene "PruebaLuces" you can use a script to load locally the AssetBundle from the StreamingAssets folder.

Thanks for your support!

Ayfel commented 2 years ago

I believe this is the issue btw https://forum.unity.com/threads/unity-5-3-objects-in-scenes-loaded-from-assetbundles-are-losing-their-static-flag.377771/

Still looking into it to see if there might be an easy fix

It also matches with what we observe as we load scenes from an assetbundle rather than prefabs directly

Ayfel commented 2 years ago

Further exploration seems to show that the meshes are being stored without the UV1 information (which is used for lightmaps), I need to look to see if there is a way to force that being stored when exporting the bundles. I'll let you know if I find out.

I believe its the way URP exports that it leaves the UV1 of meshes off the assetbundle for some reason

Alexbcn191189 commented 2 years ago

The same thing happens to me, have you found a solution?