Giter Site home page Giter Site logo

Comments (15)

michaeloverton avatar michaeloverton commented on July 1, 2024

note: in the images, i made a typo - below the third image, it should say dragging PREFABS into scene gives correct lighting

from prefablightmapping.

Ayfel avatar Ayfel commented on July 1, 2024

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.

Ayfel avatar Ayfel commented on July 1, 2024

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.

michaeloverton avatar michaeloverton commented on July 1, 2024

Thanks for your response.

  1. The lighting issues happen with all prefabs. It does NOT happen with just some prefabs.
  2. I get the same results in the editor and both production and development builds.
  3. 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?)
  4. 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.

https://imgur.com/a/ZC4JKAC

Thank you so much for your help. I'm not a lighting expert - I am learning about this stuff as I go.

from prefablightmapping.

michaeloverton avatar michaeloverton commented on July 1, 2024

Also, I am using Unity 2019.4.13f1 if that helps...

from prefablightmapping.

Ayfel avatar Ayfel commented on July 1, 2024

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.

zcwaa22 avatar zcwaa22 commented on July 1, 2024

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.

michaeloverton avatar michaeloverton commented on July 1, 2024

@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 avatar zcwaa22 commented on July 1, 2024

@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.

Ayfel avatar Ayfel commented on July 1, 2024

Oh so its the Directional mode that was causing it for you? I'll need to test that out

from prefablightmapping.

michaeloverton avatar michaeloverton commented on July 1, 2024

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.

zcwaa22 avatar zcwaa22 commented on July 1, 2024

Hi @michaeloverton have you tried changing the directional mode in lightmapper settings- this is what fixed the issue for me

from prefablightmapping.

michaeloverton avatar michaeloverton commented on July 1, 2024

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.

michaeloverton avatar michaeloverton commented on July 1, 2024

@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.

Ayfel avatar Ayfel commented on July 1, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.