一、准备一张黑白图片512x512像素
一、创建LambertAlpha.shader和LambertAlpha.mat
Shader "Custom/LambertAlpha" { Properties { _MainTex ("Base (RGB)", 2D) = "white" {} _TransVal ("Transparency Value", Range(0, 1)) = 0.5 } SubShader { Tags { "RenderType"="Opaque" } LOD 200 CGPROGRAM #pragma surface surf Lambert alpha sampler2D _MainTex; float _TransVal; struct Input { float2 uv_MainTex; }; void surf (Input IN, inout SurfaceOutput o) { half4 c = tex2D (_MainTex, IN.uv_MainTex); o.Albedo = c.rgb; o.Alpha = c.r * _TransVal;//Alpha = 红色通道值r * 转换值 } ENDCG } FallBack "Diffuse" }
二、向场景中添加Sphere、Plane,如图:
效果