You are missing a blending method, I don’t know how you can add it directly in the fragment shader but you can do it with shaderlab (cf : Unity - Manual: ShaderLab command: Blend). In general you just have to add it (
Blend SrcAlpha OneMinusSrcAlpha) wich is the basic alpha blending.
@Fuegan Thanks a lot for your answer! Although it seems there is a rendering order problem, instead of seeing the object behing my plane I see the color of the background of my camera. And what is funny is that it is the good result in the Scene Tab but not in the Game Tab.
between the SubShader and Blend lignes should resolve the problem.
The main part is “Queue”=“Transparent” wich is the order in the queue (Transparent are renderer after opaque objects).
The RenderType part is for Unity (it will be treated as a transparent object) I don’t know exactly what it does but I suppose it has to do with some optimisation.
IgnoreProjector is usually added to transparent shaders as projectors don’t work well with transparency. (But it is useless if you don’t use projectors).
PS : without tags unity sets the objects as “Queue”=“Geometry” which means if your background have a standard shader without transparency your plane should have still be rendered last so be sure your objects are not too close (as it can cause flickering).
Can anyone provide me with some guidance to get alpha working? I have my shader on a material, I apply the material to a sprite (say, a donut) and there is no alpha (the donut will look like a solid circle).
Thank you, yes. I do understand if I set that to 0.5 it will be half opacity for the entire material. However, the issue that I am having is I would like to ‘knock out’ the pieces that are transparent and show the pieces that are opaque. Does that make sense? Sorry, I am a complete shader noob and have been trying to figure out what I should be doing here. I really appreciate any help you can provide.
I have attached a screenshot of what I mean. For example the sprite on the left is a donut. And the sprite on the right should be too (it is the same sprite) however it is showing as a solid circle with my shader. How can I make my shader also have the hole in the middle?
There’s absolutely nothing in your shader making it a circle. I suspect your “donut” sprite is set to use a tight sprite mesh, which is generating a circular mesh, and that’s what you’re seeing when you use your shader.
If you want your shader to have the same alpha as your sprite, then you need to sample the sprite texture in your shader and use just the alpha. See the default sprite shader, and the cginc file that most of the actual useful shader code is in.
Copy the parts from the SpriteVert and SpriteFrag functions you need.
And maybe go through some beginner tutorials on shaders if you’re still having issues.