Shader "Unlit/LightArea" { Properties { _MainTex ("Texture", 2D) = "white" {} } SubShader { Tags { "RenderType" = "Transparent" "RenderPipeline" = "UniversalPipeline" } LOD 100 Pass { // Name "LightArea" Tags { "LightMode" = "LightArea" "UniversalMaterialType" = "SimpleLit" } // 开启混合 Blend SrcAlpha OneMinusSrcAlpha ZWrite Off ZTest Always Cull Off HLSLPROGRAM #pragma target 3.0 #pragma vertex vert #pragma fragment frag // make gpu instancing work #pragma multi_compile_instancing #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" // instancing #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/UnityInstancing.hlsl" struct appdata { float4 positionOS : POSITION; float2 uv : TEXCOORD0; // gpu instance id UNITY_VERTEX_INPUT_INSTANCE_ID }; struct v2f { float2 uv : TEXCOORD0; float4 positionHCS : 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.positionHCS = TransformObjectToHClip(v.positionOS.xyz); o.uv = TRANSFORM_TEX(v.uv, _MainTex); float instAlpha = UNITY_ACCESS_INSTANCED_PROP(props, _Alpha); o.passAlpha = instAlpha; return o; } half4 frag (v2f i) : SV_Target { // sample the texture half4 col = tex2D(_MainTex, i.uv); col *= i.passAlpha; return col; } ENDHLSL } } // Fallback "Universal Render Pipeline/Unlit" }