0
Fixed

Depth Blend - Issues with Alpha clip

robert.briscoe 4 years ago • updated by imorriso 3 years ago 13

http://i.imgur.com/qL6LdeV.jpg

Just noticed this in game view, alpha clip seems to 'cut out' any depth blended stuff. I thought it might be due to it being a double sided material, so I swapped it for a single-sided alpha clip shader and it was still there.

Answer

Answer
Fixed
The cutout line is now added automatically on all alpha shaders in Beta 0.21, which seems to fix this issue!
Is both your camera and the project on forward rendering?
They might be related yeah. Briscoe - Are you using post FX? If yes, how does it look when disabled?
I am using colour correction, I disabled it but the issue is still there. If I disable depth blend on the water below, the issue goes away. It's only visible when the alpha clip shader overlaps the water.
robert, try adding this to the properties section of the shader manually and see if that fixes the issue. It fixed the issue I was having with Depth of Field image effect.

_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
Hi! Thanks for the tip!

Adding a "_Cutoff" value to my shader did indeed fix the issue!

Joachim - might be worth looking into this, perhaps adding it automatically to alpha clipped shaders. From what I understand it defines the value in which clipping should be considered transparent/opaque.
The magic of hidden quirks in Unity shader functionality strikes again
Not sure if this helps track down more issues like this, however in Unity's built in shaders (http://unity3d.com/unity/download/archive) there are two shaders flagged as hidden that might be related to why this works: "Hidden/Camera-DepthTexture" and "Hidden/Camera-DepthNormalTexture"

It makes me wonder if the camera generates the depth texture or depth normal texture using those shaders or something along those lines.
Answer
Fixed
The cutout line is now added automatically on all alpha shaders in Beta 0.21, which seems to fix this issue!
Just to help other people who might be running into a related issue, I was getting some similar issues even after the fix in this thread; it seemed like setting my shader to use Alpha Clip was stopping the depth buffer from writing correctly on objects using that shader... at least, for the purposes of depth blending (for occlusion it worked just fine). I tracked it down to the render type needing to be manually set to Opaque, instead of the automatic "Transparent Cutout". You can find the setting in Shader Forge under Blending, once you disable auto sort.

My understanding of what causes this is that since the forward rendering camera is using shader replacement to render the depth buffer, it's only applying it to shaders with a certain subset of tags, of which "transparent cutout" apparently doesn't apply.