Search Unity

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?
     
    maxkcy and morphtekstreaming like 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:
    259
    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
    maxkcy and kei_kff like this.
  4. Jonas-Mortensen

    Jonas-Mortensen

    Unity Technologies

    Joined:
    Jan 3, 2020
    Posts:
    110
    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:
    374
    harlandpj likes this.
  6. Jonas-Mortensen

    Jonas-Mortensen

    Unity Technologies

    Joined:
    Jan 3, 2020
    Posts:
    110
    @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.
     
    Hozgen90, harlandpj and maxkcy like this.
  8. SuketuSadariya

    SuketuSadariya

    Joined:
    Aug 18, 2021
    Posts:
    2
    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
     
  10. Disastorm

    Disastorm

    Joined:
    Jun 16, 2013
    Posts:
    132
    This is still happening in 2022.2.1f1.
    Using URP and forward+, havn't checked other modes.
     
    maxkcy likes this.
  11. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,048
    If there is a bug and it happens in a blank project make a bug report
     
  12. DEEnvironment

    DEEnvironment

    Joined:
    Dec 30, 2018
    Posts:
    437
    Not certain if relate try unchecking the UI layer
     
  13. Disastorm

    Disastorm

    Joined:
    Jun 16, 2013
    Posts:
    132
    @Jonas-Mortensen Culling mask and Render Layers not working properly in 2022.2.1 for URP.

    I tested it in a new project.
    These are the results.
    Render Layers only works properly in Deferred rendering, it does not work in Forward or Forward+.
    Light Culling Mask only works properly in Forward, it does not work properly in Forward+ or Deferred.

    So effectively:
    Forward: selective lighting can only be done with Culling Masks
    Deferred: selective lighting can only be done with Render Layers.
    Forward+: selective lighting can not be done in any way.

    Also note that this issue doesn't apply to Directional Light.
     
    Last edited: Dec 27, 2022
  14. strich

    strich

    Joined:
    Aug 14, 2012
    Posts:
    374
    Have you managed to send that new project as a bug report for them yet? I think that's what's slowing things down.
     
  15. fendercodes

    fendercodes

    Joined:
    Feb 4, 2019
    Posts:
    192
    Yep. Same issue here.
     
  16. SourceMobai

    SourceMobai

    Joined:
    Aug 17, 2021
    Posts:
    1
    Same issue here, using 2021.3.5.
     
  17. fendercodes

    fendercodes

    Joined:
    Feb 4, 2019
    Posts:
    192
    This seems to now be fixed in 2022.2.4f1.
     
    strich likes this.
  18. Disastorm

    Disastorm

    Joined:
    Jun 16, 2013
    Posts:
    132
    Culling Mask still doesn't work in Forward+ in 2022.2.4f1, however Render Layers does work now, so at least we do have a selective lighting solution in Forward+ now.

    *edit the "everything" option in a light component's render layers doesn't work. However, selecting layers individually, unless you select all of the layers, does work. If you select all of the layers it automatically switches to "everything" and stops working again.
     
    Last edited: Jan 29, 2023
    fendercodes likes this.
  19. maxkcy

    maxkcy

    Joined:
    Oct 11, 2021
    Posts:
    62
    After upgrading my editor from Unity 2021.3.11f1 to 2023.1.0b5, I still have the same exact problem.
    For a short while it was rendering correctly, then the editor suddenly gave an error of missing a camera component, which didn't make sense, so since nothing was changed in the editor, without any new saves. I closed it and restarted. Then the same problem as before.

    TLDR;
    The problem where the camera doesn't render without the default layer selected still persists in Unity 2023.1.0b5.
    Hack: I created a "MyDefault" layer and moved all the default layer GameObjects onto this, then I selected the default layer and the "LayerToRender." (Untested throughly, as of yet for any future errors, in fact the first time I did this, the new MyDefault layer needed to be selected to see my other layers o_O. In addition the Ui Layer is still rendering on this camera despite UI not selected. :(:mad:) (edit: Ok i just changed the display the screen overlay for the canvas renders to :rolleyes:)

    More problems: after setting global light (URP) to MyDefault layer, it didn't render my LayerToRender. Please fix.

    How to reproduce. Set culling mask in the camera to only to a single layer that isn't default, and notice that it cant be rendered without default selected.



    EDIT: WAIT... it appears that dublicating the global light to LayerToRender allowed this layer to show. However I've got an error on the console:
    because there shouldn't be a global light for a 2nd layer in the first place o_O
     
    Last edited: Feb 28, 2023
  20. sorialexandre

    sorialexandre

    Joined:
    Nov 16, 2014
    Posts:
    2
    Nanita likes this.
  21. lukeiy

    lukeiy

    Joined:
    May 15, 2022
    Posts:
    6
    This appears to still be a bug in forward+ rendering in 2022.3.4f1
     
    dyamanoha_ likes this.
  22. dyamanoha_

    dyamanoha_

    Joined:
    Mar 17, 2013
    Posts:
    87
    Still an issue on 2023.1.18f1
     
  23. life4god

    life4god

    Joined:
    Nov 27, 2014
    Posts:
    2
    Greetings, I'm currently using 2022.3.20f1, and under Forward+ the light layers still seem to be ignored. However, with the rendering path set to "Forward" they work. Outside of coding, I'm a rookie when it comes to the graphic settings and lighting, but it seems to me that Unity has completely complicated this entire process since Unity 5. I started using unity back in 4.3, and have marveled at the progression Unity3D has gone thru. Unfortunately it hasn't been a smooth journey. Anyways, wanted to share what I'm seeing, works with Forward, confirming that it does not work with Forward+. Love the DOTS technology, just wish something as simple as lighting a scene wasn't so damn complicated.