Unity version 2019.1.2f1 HDRP project.
I am trying to make a hole in a finished gameobject which has a material and shader don't want to interfere with, the point being this should work with any object it is done on. I found this approach somewhere else, but it does not seem to work for the HD Render Pipeline version. Basically two extra gameobjects/shapes are put where the hole is to be made, one object has a preparation pass, the other makes the hole.
Example shader:
Shader "Custom/HolePrepare" {
Properties{
}
SubShader{
Tags { "RenderType" = "Opaque" "Queue" = "Geometry+1"}
ColorMask 0
ZWrite off
Stencil {
Ref 1
Comp always
Pass replace
}
CGINCLUDE
struct appdata {
float4 vertex : POSITION;
};
struct v2f {
float4 pos : SV_POSITION;
};
v2f vert(appdata v) {
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
return o;
}
half4 frag(v2f i) : SV_Target {
return half4(1,1,0,1);
}
ENDCG
Pass {
Cull Front
ZTest Less
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
ENDCG
}
Pass {
Cull Back
ZTest Greater
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
ENDCG
}
}
}
and
Shader "Custom/Hole" {
Properties{
}
SubShader{
Tags{ "Queue" = "Geometry+10" }
ColorMask RGB
ZWrite On
Stencil {
Ref 1
Comp notequal
Pass Zero
}
Pass{}
}
}
I figure these values aren't theoretically correct, because that's not how the example code was, but since it wasn't working for HDRP I started playing around and see if I got anywhere. The Hole shader should have ColorMask RGB 0, however nothing happens except the hole object becomes invisible. This led me to believe I am not able to use the stencil buffer properly. I got to the point where I could mark the pixels that I wanted to erase, however I am not able to erase them. I want to be able to erase this part of the primary object(cheese) so that the background(floor in this case) is visible.
Is there any way to do this in the HDRP?
Note: I have also tried a render queue approach by script and shader in my HDRP project, without success, although the very same code worked on a standard unity project.