(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.