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…
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?
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:
uint meshRenderingLayers = GetMeshRenderingLayer();
Light mainLight = GetMainLight();
if (IsMatchingLightLayer(mainLight.layerMask, meshRenderingLayers))
{
//Do Something if the light layer matches the mesh rendering layer
}
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
I just wasted 1.5 days chasing this down thinking that light layers was broken but in fact it appears that light culling masks still do something even though they are greyed out when light layers are enabled!
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.
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
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.
@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.
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.
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 . In addition the Ui Layer is still rendering on this camera despite UI not selected. :() (edit: Ok i just changed the display the screen overlay for the canvas renders to )
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
Dunno if fix your problem but for me, I just enabled “Light Layers” in URP Asset and create a “URP Global Settings Asset” to register the light layers. Also, need to hook it in the “Graphics” settings menu.