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 don't apply correctly #36

Closed mcread29 closed 3 years ago

mcread29 commented 3 years ago

I'm using this script to have baked lighting on prefabs for procedural levels, and I have it working, but for some reason the lightmaps don't apply correctly until I move the object in the editor, and then use ctrl+z to move it back to it's original position.

Here's what they look like after instantiation BEFORE MOVE

And here's what they look like after moving then undoing the move in editor AFTER MOVE

I've tried including the prefabs in the scene small and out of the way but the issue still persists.

Ayfel commented 3 years ago

Are you in URP?

mcread29 commented 3 years ago

I'm using the HDRP

Ayfel commented 3 years ago

I see, there are some issues with URP and it seems now with HDRP, I need to investigate these but since these pipelines are not completely stable I am not sure what to expect. So does this happen when you instantiate by hand by drag and dropping the asset in the scene as well? how about if you instantiate in the scene where you initially baked them?

Ayfel commented 3 years ago

Another thing that you can try is to comment out the section in the code where shaders are reassigned

// You have to release shaders. Material[] mat = info.renderer.sharedMaterials; for (int j = 0; j < mat.Length; j++) { if (mat[j] != null && Shader.Find(mat[j].shader.name) != null) mat[j].shader = Shader.Find(mat[j].shader.name); }

This section might be conflicting with new shaders in these pipelines

mcread29 commented 3 years ago

It doesn't matter how or where I instantiate them, they'll appear that way until I move then and then use ctrl+z to undo the move.

I tried commenting out that section and it didn't seem to fix the issue.

Ayfel commented 3 years ago

I will try an HDRP project when I get a minute. Does this happen at runtime as well or only in the Editor?

mcread29 commented 3 years ago

Runtime as well. I tried it with my level generating at runtime as well as having the prefabs instantiated in their broken state.

mcread29 commented 3 years ago

@Ayfel I figured out what the issue was. I had previously had auto generate on the scene's lighting, so there were baked lightmaps for geometry that didn't exist, and clearing the baked data fixed the issue.

mcread29 commented 3 years ago

I was mistaken, the issue persists even after clearing the existing baked data in the scene.

Ayfel commented 3 years ago

I just did a sample project with HDRP and everything worked fine. So I am afraid its probably something in the setup of your project most likely image

This is in 2020.3.5f1 and HDRP

mcread29 commented 3 years ago

Figured out the issue. My artist had said they removed all probuilder meshes, but the ones that were causing issue WERE probuilder objects. After exporting the meshes and replacing them, works perfectly! Sorry to take up your time