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

Lightmaps are messed up in build #10

Closed Pawlik12 closed 4 years ago

Pawlik12 commented 4 years ago

https://imgur.com/a/qXn4AOo

We are using HDRP 2019.3.10f1

Here's how ligtmaps look in build and ran in unity editor. We're aware that there was same issue a while ago but the solution doesn't work for us. Do you have any idea why is it happening, and how to solve it?

Ayfel commented 4 years ago

That looks like when an object it's set static and batching makes a combined mesh messes with uvs. Is this windows platform? Is there a way you can isolate this issue and instantiate the prefab in an isolated scene to test that in a build? Play mode works I assume? Last resort you could send me a repo project and I can check it

Pawlik12 commented 4 years ago

Thank you for fast reply! So I used new models and saw few things:

  1. it bakes perfectly when there is just room and light in scene. (which obviously isn't possible to be used in game)
  2. "UV Overlap" displays that there is no overlap in scene with models before baking, but after baking there is a lot of overlapping stuff, and after putting prefab in different scene (it was only one in the other scene as I made a new one) there is again no overlap dispplayed
Pawlik12 commented 4 years ago

Also yes, this is windows build, and play mode works perfectly

Ayfel commented 4 years ago

Did you try to "generate lightmap uvs" from the fbx import settings? You can try there and see if it makes a difference. Also do you disable the static flag of the prefab objects after baking?

Pawlik12 commented 4 years ago

No, I don't disable it, and I used generate lightmap Uvs before, and there wasn't that much of a difference really

Ayfel commented 4 years ago

Disable the static flag, otherwise it will batch and mess up the uvs

Pawlik12 commented 4 years ago

Oh my god! Thank you! It fixes it! :D I'm so sorry for trouble, and again thank you!

Ayfel commented 4 years ago

Great 😊 no problem

Pawlik12 commented 4 years ago

Hi! Sorry I know that you closed the thread, but that's the only way I know how to contact you, hah. So my question is - do lightprobes work with lightmaps generated by your script? Or maybe should they work? Cause our first attempt made each light in scene realtime instead of baked for some reason (but that might be fault of my friend), Anyway - on every other attempt the lightprobes don't react oon our players

Ayfel commented 4 years ago

Lightprobes cannot be baked in prefabs due to on how they work in Unity. However there is a method to have a functionality similar to that that I am working on adding to the project in the near future

Pawlik12 commented 4 years ago

So,.. do you have any ideas how could we light our models? Lightmapped prefabs would help us a lot, cause our maps are modular anyway, and now we just have black models walking around (it's a multiplayer game so we can't really bake everything, not players deffinitelly)

Ayfel commented 4 years ago

Try using mixed lights, with shadowmask baking mode or similar. then your light will shine only on non-static objects not part of your prefab. To do this properly make sure to include the lights as part of the prefabs you bake