URP stencil volume disappears when no objects are inside it
19:47 06 Dec 2025

I am new to HLSL and I am trying something simple, but for some reason can't get it right.

I'm using URP with two Render Objects features:

  1. Write Stencil Volumes (layer: OcclusionVolume), which overrides material with my stencil-write shader
  2. Occludable Draws (layer: Occludable), which uses a stencil compare (NotEqual) to draw the Occludables.

The stencil-write shader uses ZTest Always, ZWrite Off, and ColorMask 0, so it should always write its full geometry into the stencil buffer.

But the issue is: the stencil volume only renders correctly when another object is inside it. If the sphere is empty, large parts of the stencil mask disappear, as if the draw call is clipped or skipped.

Here’s the stencil-write shader:

Shader "Hidden/OcclusionStencilWrite" 
SubShader {
Tags { "Queue"="Geometry-20" "RenderType"="Opaque" } 
Pass {
  ZTest Always
  ZWrite Off
  ColorMask 0
  Stencil { Ref 1 Comp Always Pass Replace }

  HLSLPROGRAM
  #pragma vertex vert
  #pragma fragment frag
  #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"

  struct A { float4 pos : POSITION; };
  struct V { float4 pos : SV_Position; };

  V vert(A v) {
    V o;
    o.pos = TransformObjectToHClip(v.pos.xyz);
    return o;
  }

  half4 frag(V i) : SV_Target { return 0; }
  ENDHLSL
 }
}
}

Why does the stencil volume stop drawing when nothing is inside it, and how can I force URP to always render it fully regardless of scene contents?

enter image description here enter image description here enter image description here

unity-game-engine shader hlsl urp