├── DepthMask.shader └── Readme.md /DepthMask.shader: -------------------------------------------------------------------------------- 1 | // "Invisible" Unity Occlusion Shader. Useful for AR, Masking, etc 2 | // Mark Johns / Doomlaser - https://twitter.com/Doomlaser 3 | 4 | Shader "DepthMask" 5 | { 6 | Properties 7 | { 8 | } 9 | SubShader 10 | { 11 | Tags 12 | { 13 | "RenderType" = "Opaque" 14 | "Queue" = "Geometry-1" 15 | } 16 | Pass 17 | { 18 | ColorMask 0 19 | 20 | CGPROGRAM 21 | #pragma vertex vert 22 | #pragma fragment frag 23 | 24 | #include "UnityCG.cginc" 25 | 26 | struct v2f 27 | { 28 | float4 pos : SV_POSITION; 29 | }; 30 | 31 | v2f vert(appdata_base v) 32 | { 33 | v2f o; 34 | o.pos = UnityObjectToClipPos(v.vertex); 35 | return o; 36 | } 37 | 38 | half4 frag(v2f i) : COLOR 39 | { 40 | return float4(1,1,1,1); 41 | } 42 | ENDCG 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | # Unity Depth Mask Shader 2 | 3 | This simple shader attached to a material is incredibly useful in @unity3d. Anything behind a mesh with it applied will be rendered invisible to your camera. 4 | 5 | Combine with multiple cameras for cool masking tricks. Useful for creating fake holes in geometry, UI and AR applications. 6 | 7 | ## Getting Started 8 | 9 | Download the shader and put it in your project's Assets/shaders directory. Make a material in Unity and set its shader to DepthMask, and experiment. 10 | 11 | Good luck! 12 | 13 | [@Doomlaser](https://twitter.com/Doomlaser) 14 | --------------------------------------------------------------------------------