- Home /
Shader for 2D Sprite "Always Rendered on Top" Problem
I was advised to start a new question by @BaraKrossteig, so here it is.
Original Post: http://answers.unity3d.com/questions/1162194/2d-sprite-transparency-rendering-problem-with-illu.html#comment-1162753
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
The following is the illustration that I will be using as reference for the explanation:
http://postimg.org/image/7orvk44v3/
Here are some pointers to the illustration:
The leaf is the sprite
Polygonal shape encasing the leaf is how Unity renders transparent sprites
What happened:
I have a Sprite, just like the leaf, at the bottom of another GameObject. However, the Sprite was rendered on top. When the sprite is rendered on top this way, it also renders what was in the encasing polygon, which is the Unity blue background. The result is as follows:
http://postimg.org/image/lmntixlld/
In case it is hard to recognize from the image, the layers of yellowish brown colors is the GameObject that is on top of the Sprite. So what probably happened here is that:
1) the Sprite is at the bottom
2) it renders the Sprite
3) the transparent area renders the Unity blue background
4) the Sprite is brought to the top of all GameObjects along with the Unity blue background
(I am sorry that I cannot display too much of the content of the game.)
Regardless, my guess is that it is a shader problem, so it will help me greatly if someone who is good at shaders can take a guess on what I did wrong for my shader. I did write my own shader with limited knowledge so I might have missed out some crucial settings in the script or something.
Thanks in advance!
TL;DR: Sprite is rendered on top of all GameObjects along with the Unity Background in the Sprite Mesh. I do not want it to be on top all the time as the sprites will cover the UI elements. Most likely Shader problem. Shader help please.
Additional Research Items:
http://forum.unity3d.com/threads/spritesharp-sprite-mesh-optimizer.327997/
The Tree example in this link illustrates how Unity renders sprites with transparency