I have almost finished an outline effect which I would like to only be visible when the object is occluded.
As you can see its almost there, the issue is with how I am sampling the _CameraDepthTexture per object. I am sure its something simple.
Thanks!
Shader "Hidden/LM/Effects/GlowableMask"
{
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 100
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
};
struct v2f
{
float4 vertex : SV_POSITION;
float4 screenPos : TEXCOORD2;
};
v2f vert (appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.screenPos = ComputeScreenPos(o.vertex);
return o;
}
fixed4 _GlowColor;
sampler2D _CameraDepthTexture;
fixed4 frag(v2f i) : SV_Target
{
float existingDepth01 = tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(i.screenPos)).r;
float existingDepthLinear = LinearEyeDepth(existingDepth01);
_GlowColor.a = 1;
if (i.screenPos.w <= existingDepthLinear)
{
_GlowColor = fixed4(0, 0, 0, 0);
}
return _GlowColor;
}
ENDCG
}
}
}