16

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?

Shape to make a hole in The hole punching shape Hierarchy

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.

Alx
  • 651
  • 1
  • 9
  • 26
  • Hi Mads, did you ever happen to figure this one out? – Leniaal Oct 18 '19 at 15:05
  • @Leniaal Hi! I'm on Unity 2019.3 beta version now and the "usual" approach still doesn't work. I haven't seen any other working version either. :/ Although I haven't pursued this lately, I will have to solve it eventually. – Alx Oct 31 '19 at 15:29
  • 3
    I actually do solved this problem. You can find it here : [Stack overflow answer](https://stackoverflow.com/questions/57044672/is-it-possible-to-create-a-depthmask-effect-in-unitys-hdrp/64352913#64352913) – Sh3yn3 Oct 14 '20 at 12:21
  • Does this answer your question? [Is it possible to create a DepthMask effect in Unity's HDRP?](https://stackoverflow.com/questions/57044672/is-it-possible-to-create-a-depthmask-effect-in-unitys-hdrp) – Ruzihm Jan 14 '22 at 23:05

0 Answers0