Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Question Light's Culling Mask does not work with custom layers.

Discussion in 'Global Illumination' started by PenProd, Mar 8, 2023.

  1. PenProd

    PenProd

    Joined:
    Dec 17, 2022
    Posts:
    144
    Unity 2021.3.19f

    I'm working on a scene which uses little lighting, making it very dark. This is intentional. There is one object however (a door) that is a bit too dark, almost black. Just for this object, I want to add an extra light, but I don't want this extra light to influence the rest of the scene.

    So I created a layer "Extra Light" and changed the layer of the door to this layer.

    upload_2023-3-8_22-32-0.png

    This immediately causes to door to loose all lighting - which is as expected. I then create a (point) light and set the Culling Mask to "Extra Light".

    upload_2023-3-8_22-34-46.png

    Nothing happens. The door does not get lighted. I tried Realtime, I tried Baked mode and making the door static. No matter what I do, the door does not get lighted and stays black.

    In fact, even though the light's Culling Mask has been set to "Extra Light", it lights everything (except the door).

    So what am I doing wrong here?
     
    Last edited: Mar 8, 2023
  2. PenProd

    PenProd

    Joined:
    Dec 17, 2022
    Posts:
    144
    EDIT: Changed title from "Trying to light one object with one specific light. Does not work." to "Light's Culling Mask does not work with custom layers" since that is actually more accurate.

    So actually, the Culling Mask does not work with any newly created layer. If I use one of the predefined layers, it works. But for obvious reason, I want to use a custom layer. So my questions still stands. :)
     
  3. PenProd

    PenProd

    Joined:
    Dec 17, 2022
    Posts:
    144
    Ok, what actually happens is that the door simply disappears as soon as I put it on a custom layer. I thought the door became black but it actually disappears (it's standing in a very, very dark corner so I didn't notice it disappeared).
     
  4. PenProd

    PenProd

    Joined:
    Dec 17, 2022
    Posts:
    144
    Found it. In the renderer settings, newly added layers aren't added to any of the Layer Masks:

    upload_2023-3-9_11-53-20.png

    So enabling the layer in the Opaque Layer Mask made the door visible(and lit by the extra light).
     
  5. PenProd

    PenProd

    Joined:
    Dec 17, 2022
    Posts:
    144
    Oh, even though the door is now lit, the light still lights all objects, even though its Culling Mask is set to "Extra Light" only.
     
  6. Pema-Malling

    Pema-Malling

    Unity Technologies

    Joined:
    Jul 3, 2020
    Posts:
    213
    PenProd likes this.
  7. PenProd

    PenProd

    Joined:
    Dec 17, 2022
    Posts:
    144
    Thank you for your answer. Unfortunately, this does not work with baked lights. As soon as I set the light to "Baked", the "Rendering Layers" option disappears.
     
  8. PenProd

    PenProd

    Joined:
    Dec 17, 2022
    Posts:
    144
    Ok, since all of my above posts might be a bit confusion, I tried to put in a table what happens.

    I have a Point Light, with its Culling Mask set to "Extra Light". I alternated between Realtime and Baked mode
    I also have have a Static GameObject. The layer of this object alternates between "Extra Light" and "Default". The shader's lighting between "Lit" and "Baked Lit".

    I have put this in below table. Green means the object got lit, black means it didn't got lit. The check mark means that this is correct, an X means this is incorrect:

    upload_2023-3-11_17-29-23.png

    As you can see, when the light is set to Realtime mode, the results are always as they should. If I change its mode to "Baked", all results are incorrect.
     
    Last edited: Mar 11, 2023
  9. PenProd

    PenProd

    Joined:
    Dec 17, 2022
    Posts:
    144
    So is this a bug?
     
  10. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    528
    You can try using "Rendering Layers" (also called Light Layers or Decal Layers) instead of game object layers.

    Note: Baked Lit shader doesn't receive real-time lighting, only baked lighting from lightmaps after baking.
     
  11. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    528
    Maybe that's because the light baking doesn't support it and there's no rendering layers in the Meta pass (used during lightmap baking).
     
  12. PenProd

    PenProd

    Joined:
    Dec 17, 2022
    Posts:
    144
    Yes, I know, as can be seen in the table above. The problem is, with the point light's culling mask set to "Extra Light" and it's mode set to "Baked", it lights (bakes) exactly the opposite of what is should light (bake).
     
  13. Pema-Malling

    Pema-Malling

    Unity Technologies

    Joined:
    Jul 3, 2020
    Posts:
    213
    Sorry if I caused confusion before. The lightmapper does not respect culling masks - an unfortunately quite long-standing limitation. I wasn't sure if the one of the SRP's implemented some extra logic to work around this - not an expert in that area. It doesn't seem to be the case, though.