Question by
garanon · Oct 26, 2015 at 08:07 AM ·
shaderstransparent shader
Trouble making my texture transparent
I'm having trouble creating transparency on my sprite. The image is an unlit 2D sprite, and I'm simply trying to make it both black and white and transparent.
I'm used to HLSL and GLSL and from my knowledge all I should need to do to make it transparent is return a colour with an alpha value below 1.0, but it isn't working for me.
In my pixel/fragment shader, I have the following:
fixed4 frag (v2f i) : SV_Target
{
// sample the texture
fixed4 col = tex2D(_MainTex, i.uv);
//make it black and white, this works
float average = 0.30 * col.x + 0.59 * col.y + 0.11 * col.z ;
col.x = col.y = col.z = average ;
//make it transparent
col.w = 0.5;
return col;
}
However this hasn't worked for me.
I've also tried to manipulate the material from C# too to see if I can find a way around it, but this also didn't work:
[...]
Image.material = m_Material;
Image.material.color = new Color(1, 1, 1, 0.5f);
Both of these attempts failed to create transparency in my sprite.
Could anybody help me sort this out? Cheers
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612042748im_/https://answers.unity.com/themes/thub/images/avi.jpg)