Comments (19)
I am not understanding quite right the setup. You have baked lighting or real-time GI? Are you in the built in renderer or another scriptable render pipeline? Are you saying parts of the prefab are correctly shown as baked an others not? Do try including the level you bake them in to see if that changes and let me know of the results and the above question pls. Thank you.
from prefablightmapping.
so I have a prefab A containing sub prefab B. I place A in an empty scene with script in the root object, have it only do blaked lighting with a directional light set to baked.
I bake the lighting and use the script. So far so good.
I go another scene that contains prefab B but lit with mixed dynamic GI (I was using to see the difference in order to reauthor the baked lighting to make it close to my existing realtime GI lighting) and either place prefab A in it or spawn it at runtime.
In the editor play, the lighting for everything looks correct. If I build the solution, prefab B looks like it gets its lightmap stripped everywhere, both in Prefab A and in the scene in which it is spawned. The last time I tried this, the whole prefab A actually looks like it is not correctly lit as well.
from prefablightmapping.
Including the level did not seem to help.
from prefablightmapping.
and it is built-in renderer*
from prefablightmapping.
I just tested a build of just this prefab A placed in that empty level, and the same behavior is happening so I don't think it is related to the dynamic GI.
from prefablightmapping.
I side-by-sided it with a build where the lighting wasn't built at all, and it does seem only the Standard shader is affected.. Other objects in the scene with different shaders are actually getting the lightmaps applied correctly.
from prefablightmapping.
I think I've narrowed it down to an existing realtime-only directional light (in addition to the baked-only realtime light) in both scenes. In the editor, these objects, even though they have baked lighting, are still receiving and calculating light from the realtime directional light. For some reason, only for builds, the Standard shader does not take realtime lighting if it has baked lightmaps. I can only imagine this inner prefab is using a shared material or something and it is applying this baked lightmap globally, which explains why the existing objects in the scene get affected.
I suppose I can just have it use the other shader if there isn't a workaround for that.
from prefablightmapping.
Switching to another shader that wraps Standard works. I don't know why, but at least I am unblocked
from prefablightmapping.
Im glad you have a workaround. It is quite a complex setup so I would love to understand the issue and see why it happens, if you could share a project that reproduced the issue I'd be happy to take a look
from prefablightmapping.
I'll try to repro in 2021.1 with a simple cube prefab
from prefablightmapping.
Thanks 2019 is fine too as it is LTS
from prefablightmapping.
So I narrowed this down further. It appears there was a bug in just 2019.X versions where detail albedo secondary masks for a material will get stripped in the build for standard shader if using baked lightmaps.
I tested the exact same scenario on a 2019.3 project and a 2021.X project with just a cube prefab and a new standard shader material using a built-in texture as the secondary detail albedo. It gets stripped in the builds for 2019.X but not in the 2021.X, so this issue must have been fixed somewhere along the way. This was making my object look much darker as if it was not getting lightmaps at all, but I confirmed it looked the same as the object without the detail map, which was slightly distinct from completely unlit.
So not an issue with this script it appears, just unity being unity.
from prefablightmapping.
I spoke too soon. It appears if I do a normal bake and load the scene with this prefab, the detail mask is kept in the built game. Only if I bake those lightmaps to this prefab does the detail map get dropped. Not really sure how the textures in the material are being modified by this script.
from prefablightmapping.
It's this section. There must have been some side effect to setting the shader in 2019.3 that they resolved in 2021...
// 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); }
Removing this fixes the issue in 2019.3
from prefablightmapping.
Idk if you want to wrap that in unity version preprocessors, as I'm not clear on what resetting the material shaders was doing. It claims it is releasing shaders, but idk how the pool of shaders the "Shader.Find(" pulls differs from the shader it was pointing to at load. For sure this code doesn't cause an issue in 2021, so I'm guessing the eff up was on Unity handling of the = operator for shader and not passing all the params of the material correctly when reloading the shader.
from prefablightmapping.
So it works fine when removing the section you pointed out?
from prefablightmapping.
Correct, but only on 2019.3. On 2021, it worked with and without reloading the shader.
from prefablightmapping.
Yeah confirmed, this is a Unity issue, the problem is that in some cases I encountered the shader reload is necessary so its not just wrapping it in a preprocessor directive that will fix it, I have to think on it a bit, maybe an option in the script.
I am going to leave this issue open as a reference as well for now and change the title for good measure.
from prefablightmapping.
One somewhat hacky workaround is to simply store off all of the material inputs and manually send them back into the shader after reloading it.
from prefablightmapping.
Related Issues (20)
- Light probes in Interior scenes HOT 1
- Baking lightning on a prefab overwrite other prefabs lightmaps HOT 2
- URP AssetBundle lighting corrupted HOT 5
- "IndexOutOfRangeException: Index was outside the bounds of the array." on MaterialPostprocessor. HOT 5
- As I bake new prefab the old lightmaps gets deleted even they are moved in separate folder
- About Android HOT 2
- Baked lighting is broken upon instantiating from Asset Bundle HOT 25
- Baked light probes
- Baked lighting doesn't work in the build version if Screen Space Shadows is enabled
- Lightmap breaks in the build on a single prefab HOT 1
- lightmaps in the build aren't mapped correctly HOT 2
- Not working on unity 2022.2.13 HOT 4
- I try to bake but it has already taken about 4 and half hours HOT 1
- Transparency in Build HOT 13
- Trying to set shader on a Material Variant HOT 3
- Lightmaps Too Bright on Android Bundle HOT 2
- Incorrect light maps being assigned on instantiation HOT 2
- Prefab only baking/loading one light HOT 1
- How to merge LightingData assets for correct shading working? HOT 10
- Normal maps not showing properly on instantiated prefab HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from prefablightmapping.