Need help getting alpha in a simple shader

Hi there,
I have this simple shader that is just a solid color but I’d also like it to have transparency.

Shader "Petes/Solid Color" {

	properties{
	_Color ("Solid Color",Color) = (0,0,0,0)	
	}
		subshader{
		Cull Off
		color [_Color]	
		pass{}
	}
}

Could someone help me add that in?
Thanks, I’m still pretty average at the whole shader thing…

Pete

I’m still stuck with this one, does anyone know how I could get the transparency working here?
I thought since I added the extra alpha section in here that it would allow me to use tranparency but it still doesnt work Color) = (0,0,0,0) :frowning:

also have a look to: Unity - Manual: ShaderLab command: Blend (usually you can use “Blend SrcAlpha OneMinusSrcAlpha”)

Hey thanks arioch82
The alpha is playing a part in the texture now but I it doesn’t seem to play nice zdepth wise. Some objects appear in front but it seems okay with other objects… I tried the ztest option and I’ve included ZWrite but it cant get it to look right.
Any ideas?

Shader "Petes/Solid Color" {

	properties{
	_Color ("Solid Color",color) = (0,0,0,0)	
	}
		subshader{
		Cull Off
		ZWrite On
		color [_Color]	
		pass{
				Blend SrcAlpha OneMinusSrcAlpha 
			}
		}
}

Thanks
Pete

Hi Pete,

I’m quite new to the shader programming (I’m approaching them for the first time just in these days), i know how to apply an alpha from a texture but not to a solid color from a float sorry

Try this;

Shader "Petes/Solid Color" 
{
	Properties
	{
		_Color ("Solid Color",color) = (0,0,0,0)	
	}
	Category
	{
	
		Tags {"Queue"="Transparent"}
		ZWrite Off
		Blend SrcAlpha OneMinusSrcAlpha 

		Subshader
		{
			color [_Color]	
			Pass {}
		}
	}
}

I took the liberty of changing the indentation it a bit :P.

The secret is the Tags {“Queue”=“Transparent”} line, which tells unity to draw the object in the transparent queue. This makes sure it is drawn with the other transparent objects, in back-to-front order.

cool thanks tomvds! That works great!

There’s no need to use quotes in the Tag unless you’re using a custom queue, and Category is only useful when you have multiple SubShaders.

Shader "Petes/Solid Transparent Color" {

Properties {
	_Color ("Solid Color (A = Opacity)", Color) = (0,0,0,1)	
}

Subshader {
	Tags {Queue = Transparent}
	ZWrite Off
	Blend SrcAlpha OneMinusSrcAlpha 
	
	Color [_Color]	
	Pass {}
}

}

More info about alpha blending / queues here, if you’re interested.

Thanks Jessy, that’s great!