Quantcast
Channel: Unity: Custom shader not obeying alpha (transparency) - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Unity: Custom shader not obeying alpha (transparency)

$
0
0

This is a custom shader in Unity, it is a 3-colored gradient shader:

// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'Shader "CustomShaders/ThreeColorsGradientShader" {     Properties {         [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}         _ColorTop ("Top Color", Color) = (1,1,1,1)         _ColorMid ("Mid Color", Color) = (1,1,1,1)         _ColorBot ("Bot Color", Color) = (1,1,1,1)         _Middle ("Middle", Range(0.001, 0.999)) = 1     }     SubShader {         Tags {"Queue"="Transparent""IgnoreProjector"="True""RenderType"="Transparent"}         LOD 200         ZWrite Off         Pass {         CGPROGRAM         #pragma vertex vert           #pragma fragment frag         #include "UnityCG.cginc"         fixed4 _ColorTop;         fixed4 _ColorMid;         fixed4 _ColorBot;         float  _Middle;         struct v2f {             float4 pos : SV_POSITION;             float4 texcoord : TEXCOORD0;         };         v2f vert (appdata_full v) {             v2f o;             o.pos = UnityObjectToClipPos (v.vertex);             o.texcoord = v.texcoord;             return o;         }         fixed4 frag (v2f i) : COLOR {             fixed4 c = lerp(_ColorBot, _ColorMid, i.texcoord.y / _Middle) * step(i.texcoord.y, _Middle);             c += lerp(_ColorMid, _ColorTop, (i.texcoord.y - _Middle) / (1 - _Middle)) * (1 - step(i.texcoord.y, _Middle));             //c.a = 1;             return c;         }         ENDCG         }     } }

After assigning it to a material and used a material on a UIButton, it works as expected, but if i want to change the color alpha of the material (ie. make it transparent), it does NOT respond to those changes.

What's missing in the code?


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images