SOLUTION TO PROBLEM CAN BE FOUND HERE:
How to have surface shader logic that only runs in deferred mode? - Unity Engine - Unity Discussions
I’m writing a custom shader which detects intersecting geometry by comparing the fragment depth to the scene depth like so:
// ...
Tags {
"Queue" = "Overlay"
"RenderType" = "Overlay"
"IgnoreProjector" = "True"
}
CGPROGRAM
#pragma surface surf Standard vertex:vert
#pragma target 3.0
// ...
void vert(inout appdata_full v, out Input o) {
UNITY_INITIALIZE_OUTPUT(Input, o);
COMPUTE_EYEDEPTH(o.eyeDepth);
}
void surf (Input i, inout SurfaceOutputStandard o) {
float depth = i.eyeDepth;
float sceneDepth = inearEyeDepth(SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture,UNITY_PROJ_COORD(i.screenPos)));
float depthBlend = clamp((sceneDepth - depth) / 0.1, 0, 1);
o.Emission = depthBlend;
}
It works great in Forward rendering (top) but breaks in Deferred mode (bottom):
I end up with black color and weird white artifacts near edges it seems.
Do I have to do something special for this to work in Deferred?
