[ad_1]
I’m utilizing HDRP and I wish to lengthen it with out truly modifying HDRP code or writting my very own SRP.
I’d prefer to:
- Render some objects with a customized shader
- Have these objects enhance a stencil worth
- Setup the stencil state for the following digital camera within the checklist in order that the primary scene solely renders once more when the stencil matches that worth
Here’s my pseudo-code:
utilizing System.Collections;
utilizing System.Collections.Generic;
utilizing UnityEngine;
utilizing UnityEngine.Rendering;
utilizing RenderPipeline = UnityEngine.Rendering.RenderPipelineManager;
public class MyRenderTest : MonoBehaviour
{
personal ushort m_StencilWorth = 0; // The scene is simply rendered if the stencil equals to this worth
void OnEnable()
{
RenderPipeline.beginContextRendering += OnBeginContextRendering;
RenderPipeline.startCameraRendering += OnBeginCameraRendering;
RenderPipeline.finishCameraRendering += OnEndCameraRendering;
}
void OnDisable()
{
RenderPipeline.finishCameraRendering -= OnEndCameraRendering;
RenderPipeline.startCameraRendering -= OnBeginCameraRendering;
RenderPipeline.beginContextRendering -= OnBeginContextRendering;
}
void OnBeginContextRendering(ScriptableRenderContext context, List<Camera> cameras)
{
m_StencilWorth = 0;
// Unity clears the primary stencil buffer earlier than this name, so no have to do it ourselves
}
void OnBeginCameraRendering(ScriptableRenderContext context, Camera digital camera)
{
SetStencilFunction(EQUAL, m_StencilWorth); // Only render when the stencil equals m_StencilWorth
SetStencilOperation(KEEP); // Keep the worth for the HDRP digital camera render
// After this, HDRP would render the digital camera solely the place the stencil operation is verified
}
void OnEndCameraRendering(ScriptableRenderContext context, Camera digital camera)
{
SetStencilOperation(INCREMENT);
DrawCustomObjects(); // Drawing the customized objects ought to increment the stencil worth
m_StencilWorth++;
}
}
I additionally considered hooking up Custom Passes however the issue is identical, I can not discover a approach to truly set the Stencil Test Function and Stencil Operation.
Is this doable?
[ad_2]