GPU优化

This commit is contained in:
SoulliesOfficial
2026-04-06 09:32:56 -04:00
parent 1bc9af280b
commit f4068baf4a
108 changed files with 2813 additions and 1073 deletions

View File

@@ -59,8 +59,10 @@ Shader "SLS/Postprocessing/AnimeBloom"
float2 uv = input.texcoord;
float4 texelSize = _BlitTexture_TexelSize;
// 扩散偏移量,随 BlurRadius 调整
float2 offset = texelSize.xy * _BlurRadius;
// 原生的 Kawase Offset 是 1.0(即 0.5 个对角像素距离),
// 这里加入 _BlurRadius 按比例扩大步幅,能够使用 3 次迭代跑出原版 6 次的扩散面积
float spreadOffset = 1.0 + _BlurRadius * 0.5;
float2 offset = texelSize.xy * spreadOffset;
half3 c0 = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv - offset).rgb;
half3 c1 = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv + float2(offset.x, -offset.y)).rgb;
@@ -71,26 +73,36 @@ Shader "SLS/Postprocessing/AnimeBloom"
return half4(color, 1.0);
}
// --- Pass 2: Upsample (Kawase 4-Tap + Blend) ---
// 升采样:高质量混合。
// 这里采用 Dual Kawase 的升采样逻辑,混合上一级纹理
TEXTURE2D(_BloomMipDown);
SAMPLER(sampler_BloomMipDown);
// --- Pass 2: Upsample (Kawase 4-Tap + Scatter) ---
half4 FragUpsample(Varyings input) : SV_Target
{
float2 uv = input.texcoord;
float4 texelSize = _BlitTexture_TexelSize;
float2 offset = texelSize.xy * _BlurRadius * 0.5; // 升采样时半径减半,为了更平滑
// 原生的 Kawase 升采样偏移是 0.5。
// 配合宽幅降采样,这里稍微放大一点点就可以获得非常柔顺的大面积泛光
float spreadOffset = 0.5 + _BlurRadius * 0.2;
float2 offset = texelSize.xy * spreadOffset;
// 4-Tap 采样高一级的纹理
// 4-Tap 从更低分辨率纹理 (Up[i+1]) 采样外围光晕
half3 c0 = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv - offset * float2(1, 1)).rgb;
half3 c1 = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv + offset * float2(1, -1)).rgb;
half3 c2 = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv - offset * float2(1, -1)).rgb;
half3 c3 = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv + offset * float2(1, 1)).rgb;
half3 blur = (c0 + c1 + c2 + c3) * 0.25;
half3 lowRes = (c0 + c1 + c2 + c3) * 0.25;
// 这一步在 C# 中是通过 Blit 叠加到上一级 RT 上的
// 所以这里直接输出 blur 结果,混合模式设为 Add 即可
return half4(blur, 1.0);
// 采样当前层级的高清纹理 (Down[i])
half3 highRes = SAMPLE_TEXTURE2D_X(_BloomMipDown, sampler_LinearClamp, uv).rgb;
// 【完全复刻 Unity 原生逻辑】: highRes + lowRes * scatter
// 这既保证了光晕向外漫射(低迭代扩散广),又保证了核心亮区的能量守恒!
float scatter = saturate(_BlurRadius);
half3 bloom = highRes + lowRes * scatter;
return half4(bloom, 1.0);
}
// --- Pass 3: Composite (最终合成) ---
@@ -143,7 +155,7 @@ Shader "SLS/Postprocessing/AnimeBloom"
Pass
{
Name "Bloom Upsample"
Blend One One // Additive Blend for upsampling accumulation
// 已在内部 Lerp无需外部 Additive Blend
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragUpsample