• RuntimesUnity
  • Transparent objects do not render correctly when using AlphaTest

I want to use Spine objects with a Depth of Field (DoF) effect. For this purpose, it was necessary to write depth to the buffer, so I used AlphaTest as instructed in the documentation. However, I've encountered an issue where a strange edge appears around the image when AlphaTest is applied.

The settings are as follows.

If I use Transparent RenderQueue, Spine object is rendered as expected, but depth is not written to buffer.

How can I solve this?

    Related Discussions
    ...
    ysys a renommé le titre en Transparent objects do not render correctly when using AlphaTest le .

    ysys so I used AlphaTest as instructed in the documentation.

    How did you "use Alpha Test"? You need to use or write a shader which contains the respective discard operation (e.g. using clip(alpha - threshold) in the fragment shader. Does your used shader contain such a statement, or did you just modify the Render Queue Material setting?

    Thanks for the reply. I simply set the RenderQueue to AlphaTest. As for the shader, I used the Skeleton Lit shader from Spine URP.

    @ysys That's not sufficient. You need the respective clip() statement as well. You can either switch to a shader which uses ZWrite (writes to the Z buffer, also called depth buffer), or modify a copy of the desired shader and add the clip() statement and threshold parameter as described here recently:
    https://eu.esotericsoftware.com/forum/d/25471-unity-rendering-issue/2

    You can find a list of Spine shaders here, with info which write to the z buffer:
    https://esotericsoftware.com/spine-unity#Shaders

    Thank you!
    I solved the issue by adding "clip(tex.a * i.color.a - _Cutoff);" to fragment shader defined in Spine-SkeletonLit-ForwardPass-URP.hlsl.

    @ysys Awesome, glad to hear you could resolve your issue!