1.四个贴图混合
1 Shader "Custom/BlendTex_surface" { 2 Properties { 3 _RTexture("Red Channel Texture", 2D) = "" {} 4 _GTexture("Green Channel Texture", 2D) = "" {} 5 _BTexture("Blue Channel Texture", 2D) = "" {} 6 _ATexture("Alpha Channel Texture", 2D) = "" {} 7 _Mask("Mask(RG)",2D) = ""{} 8 } 9 SubShader { 10 Tags { "RenderType"="Opaque" } 11 LOD 200 12 13 CGPROGRAM 14 #pragma surface surf Lambert 15 #pragma target 4.0 16 17 sampler2D _RTexture; 18 sampler2D _GTexture; 19 sampler2D _BTexture; 20 sampler2D _ATexture; 21 22 sampler2D _Mask; 23 24 struct Input { 25 float2 uv_RTexture; 26 float2 uv_GTexture; 27 float2 uv_BTexture; 28 float2 uv_ATexture; 29 float2 uv_Mask; 30 }; 31 32 void surf (Input IN, inout SurfaceOutput o) { 33 float4 rTexData = tex2D(_RTexture, IN.uv_RTexture); 34 float4 gTexData = tex2D(_GTexture, IN.uv_GTexture); 35 float4 bTexData = tex2D(_BTexture, IN.uv_BTexture); 36 float4 aTexData = tex2D(_ATexture, IN.uv_ATexture); 37 float4 blendData = tex2D(_Mask, IN.uv_Mask); 38 39 float4 finalColor; 40 //根据blendData.g 将 RTexture 和 GTexture 混合 41 finalColor = lerp(rTexData, gTexData, blendData.g);//原本为g 42 //根据blendData.b 将 BTexture 混合 43 finalColor = lerp(finalColor, bTexData, blendData.b);//原本为b 44 //根据blendData.a 将 ATexture 混合 45 finalColor = lerp(finalColor, aTexData , blendData.a);//原本为a 46 finalColor = saturate(finalColor); 47 o.Albedo = finalColor.rgb; 48 o.Alpha = finalColor.a; 49 } 50 ENDCG 51 } 52 FallBack "Diffuse" 53 }