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

Works in editor, but turns black in browser for WebGL #46

Open justinmelillo opened 2 years ago

justinmelillo commented 2 years ago

Hello! Love this script - it's perfect as we're assetbundling prefabs. One thing though, it seems to work when we load the asset bundle in editor, but when we load in our web app, the textures turn black. Any idea what could be causing that? Thanks!

Ayfel commented 2 years ago

Check the readme about the shader stripping etc as this is the most common cause for what you describe.

justinmelillo commented 2 years ago

I tried changing the shader stripping to custom but the issue persists...any other ideas or suggestions?

Ayfel commented 2 years ago

Can you share a picture of what it looks like? (to check if its a wrong application of the lightmap or something else) Also what Unity version, light mode and render pipeline are you using?

Also changing to Custom are you including all modes?

justinmelillo commented 2 years ago

image This is what it looks like in browser

image And this is what it looks like in editor

justinmelillo commented 2 years ago

Using Unity 2020.3.18f1

We have a core app using Unity3D (testing in editor) and the asset bundles we're building from a template file we created in a URP project, but we deleted the URP pipeline settings so everything is using standard shaders in the prefab.

These are the settings in our prefab assetbundle file: image

Our core app is set up to load the assetbundle prefabs over the web

Ayfel commented 2 years ago

Yes that definitely looks like the lightmaps are not being applied. Can you share a picture of your graphics settings under Project Settings? And also have you tried just putting that prefab by hand in a scene after play mode? That looks like the light is baked regularly and is not in play mode (I also notice that it looks like nested prefabs which don't work great, better to have a top prefab for this baking).

Also I recommend removing the static flag from the prefabs after having baked them, so they don't get distorted in play mode (because of mesh batching etc)

justinmelillo commented 2 years ago

Here are the graphics settings: image image

justinmelillo commented 2 years ago

And yeah this is in play mode: image

justinmelillo commented 2 years ago

I just tried moving the floor meshes directly under the root "Space" and re-baking. Then changed all meshes back to not-static, but having the same issue.

Ayfel commented 2 years ago

Are you baking directly from the menu of the Script or just normally?

justinmelillo commented 2 years ago

I just ran a test baking directly from the menu of the script...it's just Assets-Bake Prefab Lightmaps, right?

justinmelillo commented 2 years ago

Could it be something with WebGL needing lightmaps to be Non-Directional? Is there a way to specify that in your script settings?

justinmelillo commented 2 years ago

Also - idk if you're free but I'm on discord if it's easier to hop on a quick call / screenshare: https://discord.gg/Ad7hBzCqwV

Ayfel commented 2 years ago

Yes, can you show me the object with the script that is the prefab? I am looking for the lightmap information in the script. Also did you try making it not a nested prefab?

justinmelillo commented 2 years ago

Yep! The top level prefab "Space" has the script on it: image

And yes, I un-nested all of those planes (and the point light) to place them directly under Space

dong6344 commented 2 years ago

Did you solve this problem ? I have exactly same situation

Ayfel commented 2 years ago

I'll need to do a test myself, I will report back once I have checked webgl

Ayfel commented 2 years ago

Yep! The top level prefab "Space" has the script on it: image

And yes, I un-nested all of those planes (and the point light) to place them directly under Space

Did you try without assetbundles? Not that it should make a difference but just trying to gather info

Ayfel commented 2 years ago

I just tested in Unity 2020.3.5 with URP (and without) and in WebGL and it is working fine image

Ayfel commented 2 years ago

When using AssetBundles you need to be careful that the project that creates the assetbundle has the same settings for the lightmaps as the one that opens it, specially this image