I have some very specific layers that require exclusive lighting (UI is a good example, but there are others as well). The light layer cull mask doesn’t play well with this, as there are a maximum of 4 layers that can be culled from a given light.
The result is that I end up dramatically limiting additional layers. Which gets to be kind of a pain in the butt once you start working with a lot of physics and collision, since the physics layers use the same layers as the lighting setup.
Lights want absolutely minimal layers - so you can cull a maximum of 4.
Physics want a lot of layers - so you can set up specific, detailed interactions, or raycast very specific targets.
How do you guys go about solving this, am I missing something obvious?
You can try making visible object a parent of a physical objects (i.e. rigidbody) and then put them on different layers.
Children do not have to be on the same layer as their parent. So, reserve some Layers for Physics, and reserve some layers to Renderers.
Then follow the scheme where every Rigidbody is basically an empty gameobject with rigidbody component on one layer, and its colliders and meshes are children set to another layer. Rigidbody treats children as part of its own compound collider, so it should work without any issue.
I just gave up on culling lights with layers. But what @neginfinity recommends sounds more practical, although in my case it would make things too convoluted for my liking.
There is also nothing stopping you from culling via camera instead of layers. You can have multiple cameras in your scene, one that draws all your 3d stuff, and another that is hidden away outside of your level(sky, underground, who cares?). Then you can have your GUI outside with that hidden camera where the lights wouldn’t effect it(if done right).
For some physics related things, you can use alternative approaches depending on your needs. For example, rather than relying on the Layer Collision Matrix in the Physics settings, you can instruct individual colliders to ignore each other via a script. https://docs.unity3d.com/ScriptReference/Physics.IgnoreCollision.html
For this example, you no longer have to rely on the layers for physics purposes.
How do you set this up in practice ‘done right’? You like build a box around an area to prevent directional lighting or something?
Seems like this approach is probably the most applicable to most of my needs (UI lighting, special separate camera lighting) without requiring massive, massive amounts of workflow changes and commitment.
The easiest way in my thoughts is to have a single dedicated layer for the GUI, and any light that you actually want to light it up(if any). Cameras allow you to easily exclude rendering layers, much less complicated than the physics stuff, so you can simply put the GUI objects on this layer, and have your camera only render this layer. This shouldn’t affect your physics etc… at all, as long as your GUI objects are separate and not using physics.
Wait, is there such a thing? 4 maximum culled layer? I used to cull layers from light (to save performance, on mobile mostly) but never encountered such problem, not even warning …
In deferred there is a limit that is pretty low. Not sure if it is exactly 4, but sounds about right. I’ve encountered it too. You are probably using forward rendering, for which it works differently afaik.