Stencil Operations

I want to perform stencil operations on the depth buffer to occlude specific object pixels.
I am able to do this with the scriptable render pipeline (LWRP) and URP.

Is this possible to achieve in the HDRP? How so? Are Stencil operations possible with Shader Graph?

Hello (Joey?),
I asked a similar question and though many have taken a look at it, no one has replied.
However, as of HDRP’s latest update, custom passes are enabled

https://github.com/alelievr/HDRP-Custom-Passes

I wondered if a custom pass would have the features needed for a stencil or depth pass shader, but without further comment from either Unity or someone who has done extensive experimentation - it is difficult to know.

i need it for urp
how you do it?

Hi, we currently don’t expose stencil control in HDRP, this is a work plan for future version

HDRP have only two user bit:
https://github.com/Unity-Technologies/Graphics/blob/master/com.unity.render-pipelines.high-definition/Runtime/RenderPipeline/HDStencilUsage.cs

[GenerateHLSL]
internal enum StencilUsage
{
Clear = 0,
// Note: first bit is free and can still be used by both phases.
// — Following bits are used before transparent rendering —
RequiresDeferredLighting = (1 << 1),
SubsurfaceScattering = (1 << 2), // SSS, Split Lighting
TraceReflectionRay = (1 << 3), // SSR or RTR
Decals = (1 << 4), // Use to tag when an Opaque Decal is render into DBuffer
ObjectMotionVector = (1 << 5), // Animated object (for motion blur, SSR, SSAO, TAA)
// — Stencil is cleared after opaque rendering has finished —
// — Following bits are used exclusively for what happens after opaque —
ExcludeFromTAA = (1 << 1), // Disable Temporal Antialiasing for certain objects
DistortionVectors = (1 << 2), // Distortion pass - reset after distortion pass, shared with SMAA
SMAA = (1 << 2), // Subpixel Morphological Antialiasing
AfterOpaqueReservedBits = 0x38, // Reserved for future usage

// — Following are user bits, we don’t touch them inside HDRP and is up to the user to handle them —
UserBit0 = (1 << 6),
UserBit1 = (1 << 7),
HDRPReservedBits = 255 & ~(UserBit0 | UserBit1),
}

This can be used when you are writing custom postprocess / custom pass manually.

You have an example of a custom pass that uses the stencil to select which part of the objects are affected by the see-through effect: https://github.com/alelievr/HDRP-Custom-Passes/blob/master/Assets/CustomPasses/SeeThrough/SeeThrough.cs

6369774--708996--87780070-37e49700-c82e-11ea-9d03-d5ce2a4410c6.gif

As @SebLagarde said, there will be a future version where you’ll be able to control stencil stuff in the custom pass UI but right now it’s only possible in a script.

So I took in hand this package and so far it looks very promising.

I wonder it this would be doable this way to “cut” a hole inside an object. Like instead of having the stencil appearing before everything, making it an invisible plane and disabling the render of every objects with a certain layer behind it, in order to have certain part of objects disappearing ?

Would that be possible to guide me on a way to achieve this using this package ?

EDIT :
I managed to find a way using also the custom pass : rendering - Is it possible to create a DepthMask effect in Unity's HDRP? - Stack Overflow