SSR based on custom depth stencil

Hi, I have been trying to exclude certain objects from SSR. I have been looking through the SSRTReflection shader file and found this interesting bit. I am new to shaders so I don’t quite know how to go about it, but I feel like there should be a way to use depth stencils to exclude objects from SSR. Any help would be greatly appreaciated. Thank you

// Used only if r.SSR.Stencil = 1
// This shader generate the stencil buffer according to if a pixel needs to
// compute SSR. If it doesn’t, it initializes the pixel’s color.
// This optimization use the stencil to test to prunes out the pixel
// that dones’t need to compute SSR, before pixel shader invocation are
// packed into front lines.
void ScreenSpaceReflectionsStencilPS(
float4 SvPosition : SV_POSITION
, out float4 OutColor : SV_Target0
, out float4 OutClosestHitDistance : SV_Target1
float2 UV = SvPosition.xy *;

FGBufferData GBuffer = GetGBufferDataFromSceneTextures(UV);

const float Roughness = GetRoughness(GBuffer);
const float RoughnessFade = GetRoughnessFade(Roughness);

#if !defined(TILE_COMPUTE_SSR)
if (RoughnessFade > 0.0 && GBuffer.ShadingModelID != 0)
// we are going to compute SSR for this pixel, so we discard this
// pixel shader invocation to not overwrite the stencil buffer and
// tehrefore execute ScreenSpaceReflectionsPS() for this pixel.

// we are not going to compute SSR for this pixel, so we clear the color
// since ScreenSpaceReflectionsPS() won't be executed in this pixel.
OutColor = 0;