Cant get Alpha Channel to Work with Custom Shader

Hey Guys

Im pretty new to Unity and still learning, so be gentle.
Im currenty working through the brilliant hex map tutorial by Catlike Coding.

In part 1 we create our custom shader.
Since Im planning to do something slightly different with my game I want to introduce transparency to my shader.

After trying to learn more about shaders with this tutorial, I have reduced my shader to this which still does the job:

Shader "Custom/VertexColors" {
    SubShader{
        Tags{ "RenderType" = "Opaque" }

        CGPROGRAM
        #pragma surface surf Standard fullforwardshadows
        #pragma target 3.0

        struct Input {
            float4 color : COLOR;
        };

        void surf(Input IN, inout SurfaceOutputStandard o)
        {
            o.Albedo = IN.color;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

I now want to add transparency to my shader.
As I understand it if I want to change all cells to just be 50% transparent this should work:

Shader "Custom/VertexColors" {
    SubShader{
        Tags{ "RenderType" = "Transparent" }

        CGPROGRAM
        #pragma surface surf Standard fullforwardshadows
        #pragma target 3.0

        struct Input {
            float4 color : COLOR;
        };

        void surf(Input IN, inout SurfaceOutputStandard o)
        {
            o.Albedo = IN.color;
            o.Alpha = 0.5;
        }
        ENDCG
    }
    FallBack "Diffuse"
}

But of course, this doesnt change anything.
I have been working on this for hours now.
Really looking forward to your help.

Lucas

1 Answer

1

Shader “Custom/VertexColors” {
SubShader{
Tags{ “RenderType” = “Transparent” }

         CGPROGRAM
         #pragma surface surf Standard fullforwardshadows alpha
         #pragma target 3.0
 
         struct Input {
             float4 color : COLOR;
         };
 
         void surf(Input IN, inout SurfaceOutputStandard o)
         {
             o.Albedo = IN.color;
             o.Alpha = 0.5;
         }
         ENDCG
     }
     FallBack "Diffuse"
 }

You have to actually enable blending for transparency to happen in a shader. In your case, because you are using a surface shader, you can simply add the ‘alpha’ keyword to the surface declaration.

Thank you for you help. I already tried this and my mesh just disappears. But since I assumed your solution has to be correct, I just realized when I place an object behind the tiles, it seems to work. [82266-1.jpg|82266]. What do I have to change so that the tiles always render? I mean I also want them to render against the background. best regards Lucas