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.
  2. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Bug Culling Mask not Working correctly in URP 12.0 Unity 2021.2.0b

Discussion in 'Universal Render Pipeline' started by Eylstar, Aug 7, 2021.

  1. Eylstar

    Eylstar

    Joined:
    Sep 14, 2020
    Posts:
    1
    Hello, after some research, I think this problem has no answers

    In my Scene I have a Directional Light and I want it to Light only one type of objects, with the Layer "walls"
    But, when I select my Layer "Walls" in the culling mask option of the light, it still affects all the objects in my scene!

    "Nothing" light no objects, but despite the layer i choose, default, UI or walls, it still light everything...

    I have URP 12.0 with Unity 2021.2 beta

    The weird point is that Only the shadows seems to be updated by the layer i select..

    Is this indeed a bug or am i just stupid?
     
    morphtekstreaming likes this.
  2. Aesir2698

    Aesir2698

    Joined:
    Jan 10, 2019
    Posts:
    1
    same problem here , Culling mask seems like effected all layer when any of layer is toggled
    Unity 2021.3
     
  3. OhiraKyou

    OhiraKyou

    Joined:
    Mar 27, 2012
    Posts:
    255
    Light layer culling seems entirely broken in URP 12.1.6 in Unity 2021.3.2f1. Neither the usual light culling mask nor the new light layers work as expected.

    I have an environment directional light configured to not affect collectibles and a separate directional light to affect only collectibles. And, the layer specified on the collectible mesh renderers (both the object layer and new light layer) is set exclusively to the collectible layer in the respective system. The environment light still takes priority and affects the collectibles until it is disabled, presumably because it is considered the main light.

    I'm using the
    GetMainLight
    function (from Lighting.hlsl) in a Shader Graph custom function node to obtain main light information, including color and attenuation. Multiplying shadow attenuation by distance attenuation (which is affected by the culling mask) breaks lighting for collectibles until the environment light is disabled. Without multiplying shadow attenuation by distance attenuation, shadow attenuation seems cumulative across all directional lights, regardless of culling settings. Is there a solution that respects layer culling?

    Also see the following thread, which describes the same problem: GetMainLight in shader in URP does not respect light culling mask
     
    Last edited: Jun 9, 2022
    kei_kff likes this.
  4. Jonas-Mortensen

    Jonas-Mortensen

    Unity Technologies

    Joined:
    Jan 3, 2020
    Posts:
    75
    Hey all
    @Eylstar and @Aesir2698 I wasn't able to reproduce this in 2021.3.4f1. Are you still having the problem in the latest 2021LTS?

    @OhiraKyou The GetMainLight() function only fetches the light properties of the main light and will give the same result for any rendered mesh. In order to take the rendering layer of a specific mesh into account you will need to check it yourself. Something along the lines of:

    Code (HLSL):
    1. uint meshRenderingLayers = GetMeshRenderingLayer();
    2. Light mainLight = GetMainLight();
    3. if (IsMatchingLightLayer(mainLight.layerMask, meshRenderingLayers))
    4. {
    5.     //Do Something if the light layer matches the mesh rendering layer
    6. }
    You can see how this is done in URP here.

    We don't have documentation for these calls so there is really no way you could have known this. We're aware and working on improving the Shader API Documentation :)
     
    OhiraKyou and ali_mohebali like this.
  5. strich

    strich

    Joined:
    Aug 14, 2012
    Posts:
    309
  6. Jonas-Mortensen

    Jonas-Mortensen

    Unity Technologies

    Joined:
    Jan 3, 2020
    Posts:
    75
    @strich thanks for letting me know. That I definitely not great! Will look into it
     
  7. DanOtt

    DanOtt

    Joined:
    Nov 4, 2019
    Posts:
    9
    The issue reported by @Eylstar also happens in Unity 2021.3.8f1 and the latest 2021.3.10f1 in URP with deferred rendering.
    Light sources ignore the culling layers and enlighten all objects regardless their layers.
     
  8. SuketuSadariya

    SuketuSadariya

    Joined:
    Aug 18, 2021
    Posts:
    3
    Same i have directional light (mixed) ! and a simple env i dont want directional light to effect the environment to i kept envrionment on layer called env and turned off that layer on culling mask on directional light but its still receiving direct light when i bake
     
  9. RRBeechPhoto

    RRBeechPhoto

    Joined:
    May 19, 2021
    Posts:
    3
    Same Problem. I set the single, Baked, Shadow Casting, Point Light to light only "Walls" (backwall & arches) and "Stairs". Looks as expected no baked data. Screenshot (455).png

    As soon as lightmaps are made Everything is illuminated Except the "Stairs". Screenshot (454).png