I would like to add some stencil overrides using RenderObjects in Universal Render Pipeline.
Is there a way to setup PassFront or PassBack - instead of just Pass?
I would like to add some stencil overrides using RenderObjects in Universal Render Pipeline.
Is there a way to setup PassFront or PassBack - instead of just Pass?
Yes it is possible - but it takes a bit of work ![]()
You can update RenderStateData to have the operations you wish to add(or make your own, as it is used by other things), then in RenderObjectPass.SetStencilState, you can add the operations you want:
For instance to do the pass front, add stencilState.passOperationFront etc.
They will however not show up unless you add them to the UI, by updating StencilStateDataDrawer.
Additionally, keep in mind that updating Unity/URP could override your changes, so making a copy of the RenderObject feature and putting it into your project might be a solution as well.
Hope it helped. If there is anything unclear, feel free to ask ![]()
Thank you for the precious hint.
I am just wondering if it is possible to have a MonoBehaviour script with variables for filter and stencil settings in the scene and create RenderObjects and add it to the ScriptableRendererData in OnEnable.
This way it would not get destroyed in the course of updating urp.
But how to setup StencilStateData?
It has only the passOperation, neither passOperationFront nor passOperationBack fields.
How to limit the passOperation to front or back faces?
I would like to get an effect of PassFront or PassBack in the shader.
Or analogically - stencilCompareFunction - neither stencilCompareFront nor stencilCompareBack field is available.
How to limit the stencilCompareFunction to front or back faces and how to get an effect of CompFront or CompBack in the shader?
StencilStateData is just a settings class, basically. The actual operation happens in RenderObjectPass.SetStencilState.
For example stencilState.passOperationFront(Your IDE should show you the available fields).
Thank you.
But how to access RenderObjectsPass?
Anyway is there any advantage of editing StencilState over adding a stencil Colormask 0 material instead?
I have discovered that adding a stencil override incurs extra passes even if no material override is added, so possibly it makes no difference, and the best is to use a scripted shader with stencils encoded in case you need stencils.
Am I right or wrong?