I need a shader that writes a constant depth value to the z-buffer for each pixel belonging to a simple quad. The idea is that I render a 2D background image first to fill the screen, then cut out various square holes in it using this shader I’m attempting to write and then finally render some 3D objects into the holes. I don’t know much about shaders but I’ve cobbled together something that works fine in the Unity editor on my Windows machine but doesn’t seem to write to the z-buffer on my Mac. Does anybody know why or have some suggestions to try? Thanks!
Shader "Custom/Erase Z-Buffer"
{
SubShader
{
Tags{ "Queue" = "Geometry-1" }
ZWrite On
ColorMask 0
ZTest Always
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct v2f
{
float4 position : POSITION;
};
struct fragOut
{
float depth : DEPTH;
};
v2f vert(appdata_base v)
{
v2f o;
o.position = UnityObjectToClipPos(v.vertex);
return o;
}
fragOut frag(in v2f i)
{
fragOut o;
o.depth = -100000;
return o;
}
ENDCG
}
}
}