(Actually, if there are something else drew before these two things, the result will be the same with the last picture.)
I have tried to google Stencil Buffer, Alpha Blending things, but NO good luck, seems the hardware do NOT allow the Stencil Buffer writing base on Alpha Channel?
I will be deeply appreciate your help if some Shader expert can tell me how to achieve my original goal with Shader — Clip a Sprite (or Particles) with Another Sprite? Or please just let me know the CG hardware do not allow this kind of work in Unity3D.
<<I have tried to google Stencil Buffer, Alpha Blending things, but NO good luck, seems the hardware do NOT allow the Stencil Buffer writing base on Alpha Channel?>>
You sholud use “discard” or “AlphaTest”
upd
For some reason it’s doesn’t work in DX11 and DX9 Deferred Lighting mode.
WOOOOOW…That’s brilliant !!! It’s work !!! (on Mac or iOS devices, “Discard” works, but “Alpha Test” is not working for my codes.)
Many many many deep appreciation !!!
In my situation, I am using 2D system of Unity3D, the codes are modified from the “Sprite-Default” offered by Unity3D 4.5.1 here: http://unity3d.com/unity/download/archive
I set them as “Sprite/Stencil Mask” and “Sprite/Stencil Draw In Mask”.
I don’t know, just remembered didn’t work last time I tried alpha as transparent.
Have you tried that and have good luck?
Since these codes are modified from official Sprite-Default, it seems always writing stencil buffer whether the alpha value is, except the discard function.
I’ve tried it again, as I said, it doesn’t work using any Alpha testing things, but except the “discard” command. Since any test still writing an alpha value with stencil ref value to buffers, so it became NON-PIXEL detail.
Hate to ask, but how can I use the above 2 shaders in unity? I basically want to use the shader to take a gradient sprite and place it over another solid color sprite.
Lol, no, no you misunderstood. I was asking how (step by step) to use your amazing shader in Unity. I am completely new to them. I was saying I HATE TO ASK HOW TO USE IT, because I know it is such a n00b question.
I am making a 2d game, and I could use this shader for multiple overlay effects
I tried to use this, because it sounds awesome - but when i apply each shader to a material, and put one on one sprite, and one on the other nothing happens - both of them render normally.
Hi, I’m new to Unity 2D development and I’d also really like to be able to clip sprites like this. I’ve taken your shaders, applied them to materials, and assigned those materials in the sprite renderer, but the sprites render normally. Is there something more I need to do?
This would be such a useful bit of functionality for making 2D animations. I hope eventually there is a built in way to handle it.
Hi, sorry for my Engleesh)
For all this to work, you need to add one line after 32 line in “Stencil Draw In Mask”. It is:
Pass Keep
Maybe it will help someone
If you change “Queue”=“Transparent+1” to “Queue”=“Transparent” in the Stencil Draw In Mask shader will do the trick. It will render the shader with all the other shaders in that queue. It does the trick on my computer, however i never wrote any shader before so just make sure it works on your target platform.