- Home /
Making a cutout semi-transparent?
I'm looking for some help with transparency in shaders. I've got a bunch of trees in my game that use the cutout shader for their leaves texture. However, I need to make these leaves fade out to be semi-transparent at some point when they block the camera view, which I know is by definition not possible with the standard cutout shader since that only "cuts" between 0% and 100% transparency.
I've looked around and found this similar question, which has an answer that looks like it might be helpful, however I have zero experience in building custom shaders so I'm not sure how to implement this: http://forum.unity3d.com/threads/transparent-cutout-diffuse-with-alpha.113664/
Can anyone help me with some code samples on how to combine these effects into a shader like mentioned in the link, or maybe have some other ideas on how to handle this problem?
Any help is very much appreciated!
Answer by Girish-sruthkia · Apr 23, 2015 at 01:30 PM
http://docs.unity3d.com/Manual/SL-CullAndDepth.html use the 2nd shader it will solve your issue.
Thanks for thinking along! The shader you suggested does seem a step in the right direction (the semi-transparency works beautifully), but still has some problems. I've got multiple sets of leaves on different heights along the tree, and this shader doesn't seem to render any leaves with the same shader that are directly below its transparent part, making some really ugly cuts in the foliage.
To illustrate, this is how it looks with the standard cutout shader (which I'd like to be able to fade):
And this is what the transparent Zwrite shader makes of it:
Any ideas on how to get around this, or other suggestions?