This commit is contained in:
SoulliesOfficial
2026-01-03 18:19:39 -05:00
parent 3bcd7c1cf8
commit 33b1795c1f
7387 changed files with 2762819 additions and 716926 deletions

View File

@@ -0,0 +1,109 @@
Shader "SLS/Postprocessing/AnimeACES"
{
SubShader
{
Tags
{
"RenderType" = "Opaque"
"RenderPipeline" = "UniversalPipeline"
}
ZWrite Off
Cull Off
ZTest Always
Pass
{
Name "Anime ACES Tonemapping"
Blend Off // 强制覆盖
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment Frag
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
// --- 参数定义 ---
float4 _TonemapParams;
// x: Exposure
// y: Contrast
// z: Saturation
// w: Hue Preservation (新增:色彩保留强度 0-1)
float4 _ACESCoeffs;
// x: A, y: B, z: C, w: D
float _ACES_E; // E
float4 _ColorFilter;
// Narkowicz ACES 曲线
float3 ACESCurve(float3 x)
{
float a = _ACESCoeffs.x;
float b = _ACESCoeffs.y;
float c = _ACESCoeffs.z;
float d = _ACESCoeffs.w;
float e = _ACES_E;
return saturate((x * (a * x + b)) / (x * (c * x + d) + e));
}
// 标量版本
float ACESCurve(float x)
{
float a = _ACESCoeffs.x;
float b = _ACESCoeffs.y;
float c = _ACESCoeffs.z;
float d = _ACESCoeffs.w;
float e = _ACES_E;
return saturate((x * (a * x + b)) / (x * (c * x + d) + e));
}
half4 Frag(Varyings input) : SV_Target
{
float2 uv = input.texcoord;
half4 sceneColor = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv);
half3 color = sceneColor.rgb;
// 1. Exposure (曝光)
color *= _TonemapParams.x;
// 2. Contrast (对比度) - 【核心修正】
// Pivot 从 0.5 改为 0.18 (Linear Middle Gray)
// 这样增加对比度会压暗阴影,而不是提亮阴影
float midGray = 0.18;
color = (color - midGray) * _TonemapParams.y + midGray;
color = max(0, color);
// 3. ACES Tonemapping with Hue Preservation (色彩保留) - 【核心修正】
float huePreserve = _TonemapParams.w;
// A. 标准 ACES (会吃色RGB 通道独立压缩)
float3 acesFit = ACESCurve(color);
// B. 亮度 ACES (不吃色,只压缩亮度)
float lum = Luminance(color);
float lumTonemapped = ACESCurve(lum);
// 重建颜色:保持原色相,只改变亮度
float3 colorPreserved = color * (lumTonemapped / max(lum, 1e-4));
// 混合两者:二次元通常希望皮肤保色(B),但场景光影有电影感(A)
// 建议 Hue Preservation 设为 0.5 左右
color = lerp(acesFit, colorPreserved, huePreserve);
// 4. Saturation (饱和度)
// 重新计算亮度进行饱和度调整
float finalLum = Luminance(color);
color = lerp(finalLum.xxx, color, _TonemapParams.z);
// 5. Color Filter
color *= _ColorFilter.rgb;
return half4(color, sceneColor.a);
}
ENDHLSL
}
}
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: d66798f4c56ff9d43bf821e0cd4f4b95
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,163 @@
Shader "SLS/Postprocessing/AnimeBloom"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
}
HLSLINCLUDE
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
// --- 参数定义 ---
float4 _BloomParams; // x: Intensity, y: Threshold, z: SoftKnee, w: Clamp
float4 _BloomTint; // 泛光染色
float _BlurRadius; // 模糊扩散半径 (控制光晕大小的关键)
// 纹理
TEXTURE2D(_BloomTex);
SAMPLER(sampler_BloomTex);
// --- 辅助函数Prefilter (提取高亮) ---
half3 Prefilter(half3 color)
{
float threshold = _BloomParams.y;
float softKnee = _BloomParams.z;
float clampVal = _BloomParams.w;
// 1. 限制最大亮度 (防闪烁/萤火虫噪点)
color = min(color, clampVal);
// 2. 阈值计算 (使用 Soft Knee 曲线让过渡更自然)
// 标准公式:(Brightness - Threshold) / max(Brightness, 0.0001)
// 这里使用一个更平滑的曲线版本,防止高光边缘切变太硬
float brightness = Max3(color.r, color.g, color.b);
float soft = brightness - threshold + softKnee;
soft = clamp(soft, 0, 2 * softKnee);
soft = soft * soft / (4 * softKnee + 1e-4);
float contribution = max(soft, brightness - threshold);
contribution /= max(brightness, 1e-4);
return color * contribution;
}
// --- Pass 0: Prefilter ---
half4 FragPrefilter(Varyings input) : SV_Target
{
// 采样原图
half4 color = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, input.texcoord);
// 提取高亮
half3 bloom = Prefilter(color.rgb);
return half4(bloom, 1.0);
}
// --- Pass 1: Downsample (Kawase 4-Tap) ---
// 降采样:取 4 个对角像素的平均值,范围随分辨率降低而扩大
half4 FragDownsample(Varyings input) : SV_Target
{
float2 uv = input.texcoord;
float4 texelSize = _BlitTexture_TexelSize;
// 扩散偏移量,随 BlurRadius 调整
float2 offset = texelSize.xy * _BlurRadius;
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;
half3 c2 = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv - float2(offset.x, -offset.y)).rgb;
half3 c3 = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv + offset).rgb;
half3 color = (c0 + c1 + c2 + c3) * 0.25;
return half4(color, 1.0);
}
// --- Pass 2: Upsample (Kawase 4-Tap + Blend) ---
// 升采样:高质量混合。
// 这里采用 Dual Kawase 的升采样逻辑,混合上一级纹理
half4 FragUpsample(Varyings input) : SV_Target
{
float2 uv = input.texcoord;
float4 texelSize = _BlitTexture_TexelSize;
float2 offset = texelSize.xy * _BlurRadius * 0.5; // 升采样时半径减半,为了更平滑
// 4-Tap 采样高一级的纹理
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;
// 这一步在 C# 中是通过 Blit 叠加到上一级 RT 上的
// 所以这里直接输出 blur 结果,混合模式设为 Add 即可
return half4(blur, 1.0);
}
// --- Pass 3: Composite (最终合成) ---
half4 FragComposite(Varyings input) : SV_Target
{
float2 uv = input.texcoord;
// 原始画面
half4 baseColor = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv);
// 泛光结果 (经过多次升采样后的最终纹理)
half3 bloom = SAMPLE_TEXTURE2D(_BloomTex, sampler_BloomTex, uv).rgb;
// 应用强度和染色
bloom *= _BloomParams.x * _BloomTint.rgb;
// 叠加 (Additive)
// 也可以尝试 Screen 混合模式让光变得更柔和,但 Additive 最符合物理发光
return half4(baseColor.rgb + bloom, baseColor.a);
}
ENDHLSL
SubShader
{
Tags { "RenderType"="Opaque" "RenderPipeline"="UniversalPipeline" }
ZWrite Off Cull Off
// 0: Prefilter
Pass
{
Name "Bloom Prefilter"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragPrefilter
ENDHLSL
}
// 1: Downsample
Pass
{
Name "Bloom Downsample"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragDownsample
ENDHLSL
}
// 2: Upsample
Pass
{
Name "Bloom Upsample"
Blend One One // Additive Blend for upsampling accumulation
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragUpsample
ENDHLSL
}
// 3: Composite
Pass
{
Name "Bloom Composite"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment FragComposite
ENDHLSL
}
}
}

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 3bc1d4066f58f6e47aeb7c358d24d593
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant: