I'm learning how to use transparent surfaces.

I am using a texture with black background, but any change in transparency is not showing, what I am doing wrong?

Here is my shader code:

Properties {
    _MainTex ("Base (RGB) Transparent (A)", 2D) = "white" {}
    _MaskTex ("Mask (RGB) Transparent (B)", 2D) = "black" {}
    _ColorRed ("Red Color", Color) = (1,1,1,1)
    _ColorGreen ("Green Color", Color) = (1,1,1,1)
    _ColorBlue ("Blue Color", Color) = (1,1,1,1)
SubShader {
    Tags {"Queue" = "Transparent" "RenderType"="Transparent" }
    LOD 200

    #pragma surface surf Lambert alpha:fade
    #pragma target 3.0

    sampler2D _MainTex;
    sampler2D _MaskTex;
    half4 _ColorRed;
    half4 _ColorGreen;
    half4 _ColorBlue;

    struct Input {
        float2 uv_MainTex;

    void surf (Input IN, inout SurfaceOutput o) {
        half4 main = tex2D (_MainTex, IN.uv_MainTex);
        half4 mask = tex2D (_MaskTex, IN.uv_MainTex);

        half3 cr = main.rgb * _ColorRed;
        half3 cg = main.rgb * _ColorGreen;
        half3 cb = main.rgb * _ColorBlue;

        half r = mask.r;
        half g = mask.g;
        half b = mask.b;

        half minv = min(r + g + b, 1);

        half3 cf = lerp(lerp(cr, cg, g*(r+g)), cb, b*(r+g+b));
        half3 c = lerp(main.rgb, cf, minv);

        o.Albedo = c.rgb;
        o.Alpha = main.a;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.