Shader "SGame/Particles/Alpha Blended" { Properties { [Enum(Off, 0, On, 1)] _ZWrite("深度写入", Float) = 0 [Enum(Off, 0, On, 2)] _ZTest ("深度测试", Float) = 2 _TintColor ("颜色", Color) = (0.5,0.5,0.5,0.5) _MainTex ("基础贴图(RGB: 颜色,A: Alpha)", 2D) = "white" {} [MaterialToggle]_CutOff ("透贴开关", Float) = 0 _CutOffAlpha ("透贴Alpha阈值", Range(0, 1)) = 0 [MaterialToggle]_GlowCustomData ("加亮CustomData", Float) = 0 _Glow("加亮", Range(0,10)) = 1 [Space(15)] [HideInInspector] _HorizontalLine ("地平面分割线", Float) = -5000 [HideInInspector] _HorizontalClip ("地平面切割", Float) = 0 [Enum(Double, 0, Front, 1, Back, 2)]_CullMode ("面剔除", Float) = 0 [Space(15)] [MaterialToggle] _DECAL ("自行贴地开关", Float) = 0 _DecalOffset("Z轴偏移,普通为0,需要Z缩放为-0.5", Float) = -0.5 } SubShader { Tags { "Queue"="Overlay" "RenderType" = "Transparent" "IgnoreProjector" = "True" "PreviewType" = "Plane" "PerformanceChecks" = "False" "RenderPipeline" = "UniversalPipeline" } Blend SrcAlpha OneMinusSrcAlpha, SrcAlpha OneMinusSrcAlpha Cull [_CullMode] Lighting Off ZWrite [_ZWrite] ZTest[_ZTest] HLSLINCLUDE #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/core.hlsl" #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl" #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareOpaqueTexture.hlsl" #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Input.hlsl" #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" #pragma multi_compile __ _CUTOFF_ON #pragma multi_compile __ _DECAL_ON TEXTURE2D(_MainTex); SAMPLER(sampler_MainTex); CBUFFER_START(UnityPerMaterial) float4 _MainTex_ST; half4 _TintColor; half _Glow; half _CutOffAlpha; half _HorizontalClip; half _HorizontalLine; half _GlowCustomData; half _DecalOffset; CBUFFER_END struct Attributes { float4 vertex : POSITION; half4 color : COLOR; float2 texcoord : TEXCOORD0; float4 texcoord2 : TEXCOORD1; float4 texcoord3 : TEXCOORD2; UNITY_VERTEX_INPUT_INSTANCE_ID }; struct Varyings { float4 vertex : SV_POSITION; half4 color : COLOR; float2 texcoord : TEXCOORD0; half3 worldPos : TEXCOORD1; float texCustomData : FLOAT; #if defined(_DECAL_ON) float4 viewRayOS : TEXCOORD11; float3 camPosOS : TEXCOORD12; float4 screenUV : TEXCOORD13; #endif UNITY_VERTEX_INPUT_INSTANCE_ID UNITY_VERTEX_OUTPUT_STEREO }; inline Varyings vert (Attributes v) { Varyings o = (Varyings)0; UNITY_SETUP_INSTANCE_ID(v); UNITY_TRANSFER_INSTANCE_ID(v, o); UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o); VertexPositionInputs vertexInput = GetVertexPositionInputs(v.vertex.xyz); o.vertex = vertexInput.positionCS; o.worldPos.xyz = vertexInput.positionWS; o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex); o.texCustomData = v.texcoord3.y; o.color = v.color; //DECAL #if defined(_DECAL_ON) float4 positionVS = mul(UNITY_MATRIX_MV, v.vertex); float3 viewRayVS = positionVS.xyz; o.viewRayOS.w = positionVS.z; float4x4 ViewToObjectMatrix = mul(GetWorldToObjectMatrix(), UNITY_MATRIX_I_V); o.viewRayOS.xyz = mul((float3x3)ViewToObjectMatrix, -viewRayVS).xyz; o.camPosOS = ViewToObjectMatrix._m03_m13_m23; o.screenUV = ComputeScreenPos(o.vertex); #endif return o; } inline half4 frag (Varyings i) : SV_Target { UNITY_SETUP_INSTANCE_ID(i); UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i); #if defined(_DECAL_ON) i.viewRayOS.xyz *= rcp(i.viewRayOS.w); float2 uv = i.screenUV.xy / i.screenUV.w; float rawDepth = SAMPLE_DEPTH_TEXTURE_LOD(_CameraDepthTexture, sampler_CameraDepthTexture, uv, 0); float depth = LinearEyeDepth(rawDepth, _ZBufferParams); float3 positionOS = i.camPosOS + i.viewRayOS.xyz * depth + float3(0, 0, _DecalOffset); clip(float3(0.5, 0.5, 0.5) - abs(positionOS.xyz)); i.texcoord = TRANSFORM_TEX( positionOS.xz + float2(0.5, 0.5) , _MainTex); // _GlowCustomData = 0; #endif half4 col = i.color * _TintColor * SAMPLE_TEXTURE2D(_MainTex, sampler_MainTex, i.texcoord); half a = col.a; half glowOffset = _GlowCustomData * i.texCustomData * _Glow + (1 - _GlowCustomData) * _Glow; #if !defined(_DECAL_ON) col *= glowOffset; #endif #if defined(_CUTOFF_ON) clip(col.a - _CutOffAlpha); #endif a = step(_HorizontalLine, i.worldPos.y) * a * _HorizontalClip + a * (1 - _HorizontalClip); return half4(col.rgb * col.a, clamp(a, 0, 1)); } ENDHLSL Pass { Tags { "LightMode" = "UniversalForward" } HLSLPROGRAM #pragma vertex vert #pragma fragment frag ENDHLSL } Pass { //剔除不受 扭曲影响Pass,默认用脚本Disable掉 Tags { "LightMode" = "ScreenDistortion" } HLSLPROGRAM #pragma vertex vert #pragma fragment frag ENDHLSL } } FallBack Off }