Shader "Sukuna/DismantleSlash_Advanced" { Properties { [Header(Colors)] [HDR] _MainColor("Core Color (Black/Dark)", Color) = (0, 0, 0, 1) [HDR] _EdgeColor("Edge Glow Color", Color) = (10, 0, 0, 1) // Tăng cường độ mặc định _EdgeWidth("Edge Width", Range(0, 1)) = 0.3 [Header(Distortion Settings)] _DistortionStrength("Distortion Strength", Range(0, 2)) = 0.5 _DistortionWidth("Distortion Area Width", Range(0, 2)) = 1.0 _DistortionMap("Distortion Noise Map", 2D) = "bump" {} [Header(Animation)] _Dissolve("Dissolve", Range(0, 1)) = 0 } SubShader { Tags { "RenderType"="Transparent" "Queue"="Transparent" "RenderPipeline" = "UniversalPipeline" } LOD 100 Pass { Name "SlashPass" ZWrite Off Cull 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; }; struct Varyings { float4 positionCS : SV_POSITION; float2 uv : TEXCOORD0; float4 screenPos : TEXCOORD1; }; float4 _MainColor; float4 _EdgeColor; float _EdgeWidth; float _DistortionStrength; float _DistortionWidth; float _Dissolve; sampler2D _DistortionMap; Varyings vert(Attributes input) { Varyings output; output.positionCS = TransformObjectToHClip(input.positionOS.xyz); output.uv = input.uv; output.screenPos = ComputeScreenPos(output.positionCS); return output; } half4 frag(Varyings input) : SV_Target { float x = input.uv.x; float y = input.uv.y; // Shape Mask (Hình nhát chém từ UV) float lengthMask = 1.0 - pow(abs(x * 2.0 - 1.0), 4.0); float widthMask = 1.0 - abs(y * 2.0 - 1.0); float shape = saturate(widthMask * lengthMask); // Dissolve Mask float alphaMask = saturate(shape - _Dissolve); if (alphaMask <= 0) discard; // --- DISTORTION CALCULATION --- // Tạo một mask riêng cho Distortion, rộng hơn vệt chém chính float distortionMask = saturate(widthMask * lengthMask * _DistortionWidth); float2 noise = tex2D(_DistortionMap, input.uv * 2.0).rg * 2.0 - 1.0; float2 screenUV = input.screenPos.xy / input.screenPos.w; // Chỉ làm cong vùng xung quanh, giảm dần về 0 ở trung tâm vệt chém (để lõi không bị méo) // Chúng ta dùng (1 - edgeMask) để Distortion mạnh ở rìa và yếu ở giữa float centerProtection = 1.0 - smoothstep(0.8, 1.0, shape); float2 distortedScreenUV = screenUV + noise * _DistortionStrength * 0.05 * distortionMask * centerProtection; float3 background = SampleSceneColor(distortedScreenUV); // --- COLOR CALCULATION --- // Đen ở giữa, Đỏ ở viền float edgeLerp = smoothstep(1.0 - _EdgeWidth, 1.0, shape); float4 finalColor = lerp(_MainColor, _EdgeColor, edgeLerp); // Trộn với background finalColor.rgb = lerp(background, finalColor.rgb, alphaMask); finalColor.a = alphaMask; return finalColor; } ENDHLSL } } }