Add alpha to shader in Unity3D

两盒软妹~` 提交于 2019-12-05 19:05:19

Add this line to your Properties

_Color ("Color Tint", Color) = (1,1,1,1)

then add this line right below float _Width;

half4 _Color;

Update your struct v2f and add a colour variable in it.

struct v2f
{
    float4 vertex : POSITION;
    float2 texcoord : TEXCOORD0;
    half4 color : COLOR;
};

then you can use it in your v2f vert like this:

o.color = _Color

OR if you only want to play with rgb and alpha seperatly

o.color.rgb = _Color.rgb
o.color.a = _Color.a

OR

o.color.r = _Color.r
o.color.g = _Color.g
o.color.b = _Color.b
o.color.a = _Color.a

after that you can return the color value in your half4 frag (v2f IN) : COLOR method

// do something with your color if you want
// you can also play with alpha here
return IN.color;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!