Shader "Unlit/LightArea" { Properties { _MainTex ("Texture", 2D) = "white" {} _Alpha ("Alpha", Range(0, 1)) = 1 } SubShader { Tags { "RenderType" = "Transparent" "RenderPipeline" = "UniversalPipeline" } LOD 100 Pass { Name "LightArea" Tags { "LightMode" = "LightArea" } // 开启混合 Blend SrcAlpha One ZWrite Off ZTest Always Cull Off CGPROGRAM #pragma vertex vert #pragma fragment frag // make gpu instancing work #pragma multi_compile_instancing #include "UnityCG.cginc" struct appdata { float4 vertex : POSITION; float2 uv : TEXCOORD0; // gpu instance id UNITY_VERTEX_INPUT_INSTANCE_ID }; struct v2f { float2 uv : TEXCOORD0; float4 vertex : SV_POSITION; float passAlpha : COLOR1; }; sampler2D _MainTex; float4 _MainTex_ST; // gpu instance 数据 UNITY_INSTANCING_BUFFER_START(props) // alpha UNITY_DEFINE_INSTANCED_PROP(float, _Alpha) UNITY_INSTANCING_BUFFER_END(props) v2f vert (appdata v) { v2f o; // gpu instance id UNITY_SETUP_INSTANCE_ID(v); o.vertex = UnityObjectToClipPos(v.vertex); o.uv = TRANSFORM_TEX(v.uv, _MainTex); float instAlpha = UNITY_ACCESS_INSTANCED_PROP(props, _Alpha); o.passAlpha = instAlpha; return o; } fixed4 frag (v2f i) : SV_Target { // sample the texture fixed4 col = tex2D(_MainTex, i.uv); col *= i.passAlpha; return col; } ENDCG } } }