I am writing a, hopefully, simple shader which will allow me to do 2 things. The first is to layer several textures together using each texture’s own alpha as a mask. This part works. The second thing is to allow me to use an entirely separate texture for the geometry’s transparency. I have copy/pasted example code into my shader and it does not seem to respond to changes in alpha at all. When I change my base texture to something with an alpha, that alpha is outlined by an orange line in the unity editor. However I am not passing that texture’s alpha to the SurfaceOutputStandard object. Regardless, the geometry is never transparent, and changing the blending has no affect except when it’s “One One”.
All I need to wrap up this problem is to be able to use a 4th and separate texture’s alpha for the geometry’s transparency.
Shader "Custom/multimage"
{
Properties
{
_Color ("Base Color", Color) = (1,1,1,1)
_MainTex ("Base", 2D) = "white" {}
_2ndColor ("2nd Color", Color) = (1,1,1,1)
_Detail ("Detail", 2D) = "white"{}
_Detail2("Detail2", 2D) = "white"{}
_AlphaTex("Alpha Map", 2D) = "white"{}
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
}
SubShader
{
Tags{ "Queue" = "Transparent" "RenderType" = "Transparent" "IgnoreProjector" = "True" }
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows fragment frag
//#pragma fragment frag
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _MainTex;
sampler2D _Detail;
sampler2D _Detail2;
sampler2D _AlphaTex;
struct Input
{
float2 uv_MainTex;
float2 uv_Detail;
float2 uv_Detail2;
float2 uv_alpha;
};
half _Glossiness;
half _Metallic;
fixed4 _Color;
fixed4 _2ndColor;
fixed4 _AlphaMap;
void surf(Input IN, inout SurfaceOutputStandard o)
{
// Albedo comes from a texture tinted by color
fixed4 c0 = tex2D(_MainTex, IN.uv_MainTex) * _Color;
fixed4 c1 = tex2D(_Detail, IN.uv_Detail) * _2ndColor;
fixed4 c2 = tex2D(_Detail2, IN.uv_Detail2) * _2ndColor;
fixed4 a = tex2D(_AlphaTex, IN.uv_alpha);
//Each texture is blended with the base layer in turn
c0.rgb = c1.a * c1.rgb + (1 - c1.a) * c0.rgb;
c0.rgb = c2.a * c2.rgb + (1 - c2.a) * c0.rgb;
//final rgb output is all the layers blended with their respective transparencies
o.Albedo = c0.rgb;
// Metallic and smoothness come from slider variables
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
//The final alpha OUGHT to be the AlphaMap's alpha
o.Alpha = a.a;
}
ENDCG
}
FallBack "Diffuse"
}