Files
ichni_Creator_Studio/Assets/Shaders/ScriptablePostProcessor/Shaders/AdvancedVignette.shader
SoulliesOfficial aee62cd637 大修
2026-03-14 02:30:26 -04:00

90 lines
3.1 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
Shader "SLS/Postprocessing/AdvancedVignette"
{
SubShader
{
Tags
{
"RenderType" = "Opaque"
"RenderPipeline" = "UniversalPipeline"
}
ZWrite Off
Cull Off
HLSLINCLUDE
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#include "Packages/com.unity.render-pipelines.core/Runtime/Utilities/Blit.hlsl"
// --- 参数定义 ---
float4 _VignetteColors; // xy: Unused, z: Unused, w: Unused (颜色单独传)
float4 _ColorInner; // 内部颜色 (过渡色)
float4 _ColorOuter; // 外部颜色 (边缘色)
float3 _VignetteParams1;
// x: Intensity (强度)
// y: Smoothness (柔和度)
// z: Roundness (圆度)
float4 _VignetteCenter; // xy: Center
// 简单的伪随机噪声函数 (用于 Dithering)
float Random(float2 uv)
{
return frac(sin(dot(uv, float2(12.9898, 78.233))) * 43758.5453);
}
half4 Frag(Varyings input) : SV_Target
{
float2 uv = input.texcoord;
// 1. 参数解包
float intensity = _VignetteParams1.x;
float smoothness = max(0.001, _VignetteParams1.y);
float roundness = _VignetteParams1.z;
float2 center = _VignetteCenter.xy;
half3 colInner = _ColorInner.rgb;
half3 colOuter = _ColorOuter.rgb;
// 2. 计算距离场 (SDF)
float2 d = uv - center;
// 圆度计算
d = d * lerp(1.0, 0.5, roundness);
float vdist = length(d);
float boxDist = max(abs(d.x), abs(d.y));
vdist = lerp(boxDist, vdist, roundness);
// 3. 计算遮罩 (Mask)
// 归一化距离,使其适配 Intensity
float maxDist = 0.8;
float threshold = 1.0 - intensity;
// 计算平滑的 0-1 遮罩值
// mask = 0 (中心区域,显示原图) -> 1 (边缘区域,显示暗角)
float mask = smoothstep(threshold - smoothness * 0.5, threshold + smoothness * 0.5, vdist * 2.0);
// 5. 计算最终暗角颜色 (Gradient)
// 随着 mask 从 0 变到 1颜色从 Inner 变到 Outer
// 我们可以用 mask 本身作为插值系数,或者用 vdist
// 这里用 mask 保证颜色变化与透明度变化同步
half3 finalVignetteColor = lerp(colInner, colOuter, mask);
// 6. 混合原图
half4 sceneColor = SAMPLE_TEXTURE2D_X(_BlitTexture, sampler_LinearClamp, uv);
// sceneColor * (1 - mask) + vignetteColor * mask
// 即Lerp(sceneColor, finalVignetteColor, mask)
return lerp(sceneColor, half4(finalVignetteColor, 1), mask);
}
ENDHLSL
Pass
{
Name "Advanced Vignette"
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment Frag
ENDHLSL
}
}
}