Harald schriebSorry, I forgot to mention a few things: you should set:
ZWrite On
ZTest Less
And also enable alpha cutoff by adding the following line (which discards pixels when alpha test fails), this seems to be missing in your shader above:
clip(yourTexture.a - _Cutoff);
With this combination, you should set Z-Spacing
to 0
to make sure that everything is rendered at the same depth.
I have just written a shader that does all this for you (and anyone who is interested), please find it attached below.
Using this shader you can set the Color
to a transparent black color and set Color Overlay
to 1
to get the desired transparent shadow effect. Note that when Color Overlay
is less than 1
, it will be visible that draw order is actually inverted for this ZTest setup.
After some testing, this shader will most likely be added to the official spine-unity packages. Then later, we could potentially add a Reverse Draw Order
parameter at SkeletonRenderer
to also draw everything in the correct order without any color overlay.
Thank you so much! I love Spine not only for it's a wonderful software, but also for such a responsible team!
After comparing you shader code with mine, I found out I've made a mistake of using
c.a = step(_CutOff, c.a);
instead of
clip(baseColor.a - _Cutoff);
which causes the alpha pixels are not really being clipped! :lol:
Now it's working perfectly after setting the _Cutoff value to almost 1! :nerd:
I still have a question about the 'Z-Spacing'. In my understanding, the 'Z-Spacing' makes the pieces of the spine to separate from each other in Z-Axis to get a correct render order.
However, when I set the 'Z-Spacing' to zero, the render order of shadow seems to get messed up:
If I set the value to -0.00001, the problem still occurs with a small probability:
The problem is gone when I set the 'Z-Spacing' to very small value like -0.001.
Is this problem occurs because I'm using a perspective main camera? I've set the camera transparency sort axis to z-axis in my project, but the problem still occurs:
I just want to get an expert reply from you! It's not a big problem for setting the 'Z-Spacing' to -0.001 does not mess up anything. 😃
Many thanks!