fix(memory-shader): 修复调频模糊导致 alpha 变透明并优化移动端采样
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user