From bd94302714781fcb7fa92f2ef523478e6c5a29ed Mon Sep 17 00:00:00 2001 From: bottlefish <781230111@qq.com> Date: Thu, 2 Jul 2026 17:56:33 +0800 Subject: [PATCH] =?UTF-8?q?fix(memory-shader):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E8=B0=83=E9=A2=91=E6=A8=A1=E7=B3=8A=E5=AF=BC=E8=87=B4=20alpha?= =?UTF-8?q?=20=E5=8F=98=E9=80=8F=E6=98=8E=E5=B9=B6=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E7=A7=BB=E5=8A=A8=E7=AB=AF=E9=87=87=E6=A0=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- .../Shader/Shader/MemoryTuningSprite.shader | 44 ++++++++++++------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/Assets/Shader/Shader/MemoryTuningSprite.shader b/Assets/Shader/Shader/MemoryTuningSprite.shader index e87eb250b..e14d2141d 100644 --- a/Assets/Shader/Shader/MemoryTuningSprite.shader +++ b/Assets/Shader/Shader/MemoryTuningSprite.shader @@ -114,7 +114,9 @@ Shader "AibisDream/MemoryTuningSprite" { half pixels = max(1.0, lerp(_PixelMax, _PixelMin, strength)); pixels = lerp(pixels, max(1.0, density), step(0.001, density)); - float2 aspectPixels = float2(pixels, max(1.0, pixels * _MainTex_TexelSize.z / _MainTex_TexelSize.w)); + float texW = max(1.0, _MainTex_TexelSize.z); + float texH = max(1.0, abs(_MainTex_TexelSize.w)); + float2 aspectPixels = float2(pixels, max(1.0, pixels * texW / texH)); return round((uv - 0.5) * aspectPixels) / aspectPixels + 0.5; } @@ -130,7 +132,8 @@ Shader "AibisDream/MemoryTuningSprite" return uv + side * wave * volFxStrength * edgeMask; } - half4 BlurSample(float2 uv, half strength) + // 仅模糊 RGB;alpha 由调用方取自中心采样,避免图集透明边被混进导致整图变透明(移动端常见)。 + half3 BlurRgb(float2 uv, half strength) { float angle = radians(111.0); float radial = distance(uv, 0.5) * 0.0026; @@ -138,16 +141,22 @@ Shader "AibisDream/MemoryTuningSprite" float2 stepDir = normalize(float2(sin(angle), cos(angle))); float2 stepUv = stepDir * stepSize; - half4 col = SampleSprite(uv) * 0.18; - col += SampleSprite(uv + stepUv * 1.0) * 0.15; - col += SampleSprite(uv - stepUv * 1.0) * 0.15; - col += SampleSprite(uv + stepUv * 2.0) * 0.12; - col += SampleSprite(uv - stepUv * 2.0) * 0.12; - col += SampleSprite(uv + stepUv * 3.0) * 0.09; - col += SampleSprite(uv - stepUv * 3.0) * 0.09; - col += SampleSprite(uv + stepUv * 4.0) * 0.05; - col += SampleSprite(uv - stepUv * 4.0) * 0.05; - return col; +#if defined(SHADER_API_MOBILE) + half3 rgb = SampleSprite(uv).rgb * 0.34; + rgb += SampleSprite(uv + stepUv).rgb * 0.33; + rgb += SampleSprite(uv - stepUv).rgb * 0.33; +#else + half3 rgb = SampleSprite(uv).rgb * 0.18; + rgb += SampleSprite(uv + stepUv).rgb * 0.15; + rgb += SampleSprite(uv - stepUv).rgb * 0.15; + rgb += SampleSprite(uv + stepUv * 2.0).rgb * 0.12; + rgb += SampleSprite(uv - stepUv * 2.0).rgb * 0.12; + rgb += SampleSprite(uv + stepUv * 3.0).rgb * 0.09; + rgb += SampleSprite(uv - stepUv * 3.0).rgb * 0.09; + rgb += SampleSprite(uv + stepUv * 4.0).rgb * 0.05; + rgb += SampleSprite(uv - stepUv * 4.0).rgb * 0.05; +#endif + return rgb; } half4 ChromaticSample(float2 uv, half4 source, half strength) @@ -164,7 +173,9 @@ Shader "AibisDream/MemoryTuningSprite" half3 splitRgb = (colA.rgb + colB.rgb) * 0.5865; half splitAlpha = max(max(colA.a, colB.a), source.a); half4 splitCol = half4(splitRgb, splitAlpha); - return lerp(source, splitCol, 0.85 * response); + half4 result = lerp(source, splitCol, 0.85 * response); + result.a = source.a; + return result; } half4 frag(Varyings input) : SV_Target @@ -187,9 +198,12 @@ Shader "AibisDream/MemoryTuningSprite" float2 pixelUv = PixelSnap(uv, pixelate, _PixelatePixelDensity); uv = lerp(uv, pixelUv, pixelate); - half4 col = lerp(SampleSprite(uv), BlurSample(uv, blur), blur); + half4 sharp = SampleSprite(uv); + half3 rgb = lerp(sharp.rgb, BlurRgb(uv, blur), blur); + half4 col = half4(rgb, sharp.a); col = ChromaticSample(uv, col, clarity); - col *= input.color; + col.a *= input.color.a; + col.rgb *= input.color.rgb; return col; } ENDHLSL