Shader "Sukuna/DistortionTrail" { Properties { _DistortionStrength("Distortion Strength", Range(0, 1)) = 0.5 _DistortionMap("Distortion Map", 2D) = "bump" {} _WidthMask("Width Mask", Range(0, 1)) = 0.5 } SubShader { Tags { "RenderType"="Transparent" "Queue"="Transparent" "RenderPipeline" = "UniversalPipeline" } LOD 100 Pass { ZWrite Off Blend SrcAlpha OneMinusSrcAlpha HLSLPROGRAM #pragma vertex vert #pragma fragment frag #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareOpaqueTexture.hlsl" struct Attributes { float4 positionOS : POSITION; float2 uv : TEXCOORD0; float4 color : COLOR; // Sử dụng để lấy Alpha từ Trail Renderer }; struct Varyings { float4 positionCS : SV_POSITION; float2 uv : TEXCOORD0; float4 screenPos : TEXCOORD1; float4 color : COLOR; }; float _DistortionStrength; sampler2D _DistortionMap; float _WidthMask; Varyings vert(Attributes input) { Varyings output; output.positionCS = TransformObjectToHClip(input.positionOS.xyz); output.uv = input.uv; output.screenPos = ComputeScreenPos(output.positionCS); output.color = input.color; return output; } half4 frag(Varyings input) : SV_Target { // Mask cho trail: mờ ở 2 cạnh và mờ dần theo chiều dài float mask = (1.0 - abs(input.uv.y - 0.5) * 2.0) * input.uv.x * input.color.a; float2 noise = tex2D(_DistortionMap, input.uv * 2.0 + _Time.y).rg * 2.0 - 1.0; float2 screenUV = input.screenPos.xy / input.screenPos.w; float2 distortedUV = screenUV + noise * _DistortionStrength * 0.1 * mask; float3 background = SampleSceneColor(distortedUV); return float4(background, mask); } ENDHLSL } } }