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

Lightmaps not working for android AR Foundation #43

Open jaspervandenbarg opened 2 years ago

jaspervandenbarg commented 2 years ago

I am using this asset so I can instantiate different baked prefabs in AR during runtime. When I bake and instantiate the prefabs in the Unity editor everything works but when I build the project and test it on my android device the lightmaps seem to be broken and in the wrong places.

See example of a lab you can walk through in AR, the first image is instantiated in play mode in the editor and the second is instantiated on the device: image Screenshot_20210916-163719_CityGame

I am using URP and Unity 2020.2.6f1 (also tried in Unity 2021.1.21f1).

Ik bake my assets using the 'bake prefab lightmap' Set my meshes to static (static batching off). I read through the other issues and tried those aproaches aswell:

have lightmaps for prefabs instead of scenes is really important for our project because it saves a lot of prossessing power and the scene used for AR is also used for other things (both the (AR) camera and objects are instantiated ar runtime depending on what the scene is used for at that time.

Ayfel commented 2 years ago

Can you try including the prefab already in the scene, not instantiating? And see if that way the map works, if it does then we can go form there to figure it out. Try also setting the lightmap setting to Non-Directional and see what you get

jaspervandenbarg commented 2 years ago

Thank you for the fast response.

Having the prefab already loaded in the scene is not really an option for me because the scene instatiates objects depending on which objects you select to load AR during runtime, this selection happens before loading the scene itself. In the current state of the project there are already 20+ objects to choose from and that amount is still growing.

I tried your suggestion non the less and the issue seems to be resolved and the lightmap is being applied correctly. What I tried was having the lab already loaded and active in the AR scene in the build. But as state above this is not really an option for me.

I have not tested it with the object loaded but inactive and activating when needed. But again that also isn't really an option for me.

Right now I have to go somewhere and don't have any more time for testing and resping. I will be back in a couple of hours.

Ayfel commented 2 years ago

Yes this issue was seen by another user before and I believe has to do with URP, what he did (and it was also an AR app) was to have the objects in the scene at very small scale, which might not be viable for your case. But at least we found that behaviour. You could try just having inactive objects in the scene even, just turn them off at awake and not use them, if that makes sense. Having them in the scene should make any instantiated one work as well

jaspervandenbarg commented 2 years ago

Is it known what causes this behaviour with URP? Maybe we can find a solution then to make it work as intended.

I wanted to try test having the object inactive in the scene and instantiating the object a second time using the system we where already using but the lighting (real life) seems to be to dark now for the AR engine to detect anything and orientate itself. I wil try again after the weekend and now that I know the behaviour I will try and find what causes it so we will be able to fix this issue hopefully.

adavies25 commented 2 years ago

Hi, Were you able to find a solution to this problem? Lightmaps apply fine in the editor but are seeing badly offset/scaled lightmaps on devices with URP and AR Foundation in Unity 2020.3.27f1.