Comments (15)
note: in the images, i made a typo - below the third image, it should say dragging PREFABS into scene gives correct lighting
from prefablightmapping.
Can you share your lighting settings, what type of lights you use (mixed, baked, realtime, etc) and how this lighting is setup? Also what render pipeline you use and lighting settings of the scenes where you instantiate? It is strange that you get different results dragging vs instantiating, which would make me suspect something in that process but hard to say
from prefablightmapping.
Also you said sometimes the lighting is wrong but sometimes is fine, does it happen consistently with the same prefabs that the lighting is not working? Do you get the same result in a build vs the editor?
from prefablightmapping.
Thanks for your response.
- The lighting issues happen with all prefabs. It does NOT happen with just some prefabs.
- I get the same results in the editor and both production and development builds.
- In an attempt to fix the problem, I made ALL lights be baked. They are mostly baked point lights and some baked area lights. One weirdness I noticed is that sometimes even if I delete the prefab lighting data, and even though the point lights are set to "baked", I end up seeing light in the prefab (in this case, shouldn't the prefab be dark, because I have baked no light?)
- I'm using the standard render pipeline.
Could this be a side effect of the materials that are being used on the assets? I noticed on some assets, the material being used has Emission Global Illumination set to Realtime. Would this make a difference?
Another thing I notice is that the walls of my prefab rooms are actually 3D Planes (as opposed to solid boxes). Could this cause problems?
It is confusing to me because in the case where the lighting is bad, the lightmap is actually still applied, but the lightmap appears to be darkened. I know the lightmap is applied, because if it weren't the asset would simply be nearly black, right?
Here are some relevant images and descriptions.
Thank you so much for your help. I'm not a lighting expert - I am learning about this stuff as I go.
from prefablightmapping.
Also, I am using Unity 2019.4.13f1 if that helps...
from prefablightmapping.
It shouldn't be because of materials at all. It also looks like the prefab has lightmaps applied as all the shadows show there in the same way. An easy way to see this is to disable all lights in the scene and see if they have still light/shadows. It feels like there is some extra light when it looks fine that's why I was asking. Is there a way you could make a reproducible project for me to check or similar. I am not seeing anything obvious wrong here and the setup is basically the same I mostly use, Unity 2019 and Standard render pipeline with regular lighting settings. I recommend setting the Bake Lighting Mode to "Bake Indirect" instead though so it will bake everything. Let me know after you test that.
from prefablightmapping.
Hi @Ayfel and @michaeloverton Sorry to hijack this thread but I thought I'd share what I've found in relation to this issue.
I'm also creating a "infinite" space, a corridor that is instantiated as you move along it. My root "block" prefabs contain, walls and door and its these "block" prefabs which I first add the PrefabLighmapData script to, bake and then instantiate at runtime.
What I've been finding is that instantiated "blocks" which have a rotation of 0 on the Y axis look perfect but as soon as I instantiate them at 90, 180 or 270, or indeed change the transform's value of Y rotation while the engine is running the lightmaps get dark and blotchy.
I'm new to lighting so maybe this is an error on my part elsewhere but if not it might help shed some light on what's happening?
from prefablightmapping.
@zcwaa22 Oh, excellent observation! I haven't tested that. Does it happen when you manually place the prefabs into a new scene (by hand as opposed to script instantiation) and rotate them? Any ideas about this @Ayfel ? I will test this on my end soon.
from prefablightmapping.
@zcwaa22 Oh, excellent observation! I haven't tested that. Does it happen when you manually place the prefabs into a new scene (by hand as opposed to script instantiation) and rotate them? Any ideas about this @Ayfel ? I will test this on my end soon.
Yep. Both dragging a baked lightmapped prefab and rotating it when the scene isn't running and when the scene is running produces the same undesired result for me..
EDIT:>
Selecting "Direction Mode - Non-Directional" in Lightmapper Settings just fixed the issue for me - hope it does for you :)
from prefablightmapping.
Oh so its the Directional mode that was causing it for you? I'll need to test that out
from prefablightmapping.
I've confirmed that this is indeed the case for me as well. The issue is the worst when the rotation is 180 degrees, but it is also incorrect at 90 and 270.
This does make me think of a potential workaround, though - make separate prefabs with separate lightmaps for each rotation, and swap them in as necessary. This would really not be ideal, however...
Here is an example: https://imgur.com/a/hIJfNJp
from prefablightmapping.
Hi @michaeloverton have you tried changing the directional mode in lightmapper settings- this is what fixed the issue for me
from prefablightmapping.
That fixed it for me too! Thank you so much. So if I'm understanding things correctly, this is because:
When you bake a Directional lightmap, Unity generates two lightmap textures. One texture stores information about the intensity and color of the lighting received across the target surface. This is identical to the Non-Directional lightmap. The other texture stores the dominant light direction, along with a factor describing how much of the total light received comes from that dominant direction.
The "second texture" about the dominant light direction is what makes the lightmap incorrect upon rotation in our case. Makes sense.
Thank you so much, both of you. Will close the issue.
from prefablightmapping.
@Ayfel thanks again. It might be a good idea to put something in the FAQ about not using directional lightmaps if the prefabs will be rotated. Up to you, though, as I know you're probably busy.
from prefablightmapping.
Yes I agree, I want to explore the reason behind this because initially I had disabled directional lightmapping and defaulting everything to non-directional and later on re-enabled the option because everything seemed to work fine. I want to understand how Unity store this directional information.
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.