Add Transparency to shader

Hi everyone,

I’ve a simple shader that combines two textures based on a “Blend” value.
Here’s the simple shader code:

Shader "Custom/Blend Textures" { 

Properties {
_Blend ("Blend", Range (0, 1) ) = 0.0
_MainTex ("Texture 1", 2D) = "" 
_Texture2 ("Texture 2", 2D) = ""
}

SubShader { 
Pass {
SetTexture[_MainTex]
SetTexture[_Texture2] { 
ConstantColor (0,0,0, [_Blend]) 
Combine texture Lerp(constant) previous
}
}
} 
}

I’d like to add another Slider that controls the material transparency (0 = full transparent, 1 = full opaque).

How can achieve this?
Many thanks in advance!

Alessio

These are so called fixed function shaders, not the most flexible: https://docs.unity3d.com/Manual/ShaderTut1.html

You can achieve what you want with a fragment shader instead: https://docs.unity3d.com/Manual/ShaderTut2.html or if you’re using the new render pipelines the shader graph.

Basically what you want to do is:

            fixed4 frag (v2f i) : SV_Target
            {
                fixed4 color1 = tex2D(_MainTex, i.texcoord);
                fixed4 color2 = tex2D(_MainTex, i.texcoord);

                fixed4 finalColor = lerp(color1, color2, _Blend);
                finalColor.a *= _MaterialTransparency;
                return finalColor;
            }