Hey,
I’m trying to use the camera depthTexture to have a thin border around objects to use as a mask for another texture. it’s working well however the result is very different from my editor to my game view as you can see in the attached image.
The depth texture works in game view too because if I crank the values it starts to show, it’s just very different from the editor view. I’m thinking it has to do with my - IN.screenPos.z operation because before that it’s all the same.
here’s my shader code, someone has an idea?
SubShader{
Tags { "Queue"="Transparent" "RenderType"="Transparent" }
Cull Off
ZWrite Off
ZTest LEqual
CGPROGRAM
#pragma surface surf Lambert
#pragma target 3.0
#include "UnityCG.cginc"
sampler2D _CameraDepthTexture;
float _Depth;
float _FoamSize;
float _FoamFade;
struct Input
{
float4 screenPos;
};
void surf (Input IN, inout SurfaceOutput o)
{
half sceneZ = LinearEyeDepth(tex2Dproj(_CameraDepthTexture, UNITY_PROJ_COORD(IN.screenPos)).r);
fixed borderMask = sceneZ - IN.screenPos.z;
fixed finalMask = saturate(pow(borderMask,_FoamFade));
o.Emission = finalMask;
o.Alpha = 1.0;
}
ENDCG
}
Thanks!