Skip to content

Instantly share code, notes, and snippets.

@thelucre
Created October 16, 2018 21:13
Show Gist options
  • Save thelucre/dc4d2a084cb83df27e2e625e867ed10c to your computer and use it in GitHub Desktop.
Save thelucre/dc4d2a084cb83df27e2e625e867ed10c to your computer and use it in GitHub Desktop.
// Virtual occlusion, hide objects behind, without being visible to the user
// Useful with AR Utils: https://github.com/jonas-johansson/ARCoreUtils
// Shader src: https://forum.unity.com/threads/clipping-objects-behind-a-higher-plane.492147/#post-3205094
Shader "Custom/ARStencilOcclusion" {
SubShader {
Tags { "Queue" = "Background-1" }
Pass {
ColorMask 0
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
};
struct v2f
{
float4 vertex : SV_POSITION;
float size : PSIZE;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.size = 30;
return o;
}
fixed4 frag (v2f i) : SV_Target
{
return fixed4(1, 1, 1, 1);
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment