The URP 2D Renderer lacks the Filtering Layer Mask option that the general URP Renderer provides.
I’m trying to create an effect using a stencil buffer and the ‘Render Objects’ Render feature with the URP 2D Renderer, but this seems to be impossible.
My setup includes two layers (Mask and SeeThrough) and two Render Features.
The first Render Feature writes to the stencil, and the second reads from it.
However, it’s critical to exclude both layers from the ‘Opaque Layer Masks’ in the URP Renderer - something that can’t be done with the 2D Renderer because it doesn’t support filtering by layer masks.
Hi, the URP 2D renderer doesn’t support Filtering Layer Mask as they may conflict with the Sorting Layers which is primarily used for rendering sprites.
May I ask what you are trying to achieve with the 2 render features? Is Sprite Mask an alternative you can use?
Thank you for your response. I have a system that generates stencil values both on a dynamic mesh and a dynamic texture mask. I use these stencil values to draw an outline effect (see Image 1 and Image 2).
Algorithm
Dynamic geometry writes to the stencil buffer (Image 3, top Render feature).
Apply the texture mask.
Render the outline only with a Render Feature while reading from the stencil buffer (Image 3, bottom Render feature).
This approach is only possible because I found a spot in the URP 2D renderer that generates the FilterSettings (Image 4, in the LayerUtility class => GetFilterSettings => filterSettings.layerMask = -1 & excludeMask).
Without this tweak, I would need to render the outline as-is along with a Render feature, which creates a messy result (Image 5).
Currently, the outline shader does not read from the stencil directly; it relies on the Render feature. I would prefer to keep the stencil logic out of the outline shader so that it can remain independent and easily replaceable.
Is there any hope that an “exclude” mask could be added? From what I can tell, there is no other option for me at this time.
I’ve also encountered this problem as well and would also like filtering to be possible.
I had to fork the 2D Renderer in order to add a Filter Layer Mask. It would be much better if this were available to everyone. For my case, I wanted filter out specific layer(s) from rendering in the main rendering pass. By excluding a layer from the main pass, I was then able to render objects using that layer with a Renderer Feature.
Here’s a more concrete example: I want to render a tilemap specially in a prepass with a tiny Render Texture, then blur the result in a Render Texture, then sample that Render Texture in the normal rendering pass… but whoops those tiles render again in the normal rendering pass as well, looks like that effect won’t work.
Without this feature, the workaround is nasty: the main camera exlcuding the target layer and a second camera targeting a the target layer, which is then output to a Render Texture. But this now has the overhead of a second camera which I could’ve avoided!
I also object to making the 2D Renderer fundamentally unlike other renderers. This makes them all occupy extra brain space.