Files
ichni_Official/Assets/Shaders/ScriptablePostProcessor/Volumes/AdvancedVignette.cs

63 lines
2.5 KiB
C#
Raw Normal View History

2026-03-14 03:13:10 -04:00
using Echovoid.Runtime.Behavior.Rendering;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
namespace SLSUtilities.Rendering.PostProcessing
{
[System.Serializable, VolumeComponentMenu("SLS/Postprocessing/Advanced Vignette")]
public class AdvancedVignette : ScriptablePostProcessorVolume
{
// 放在最最后
public override CustomPostProcessInjectionPoint InjectionPoint => CustomPostProcessInjectionPoint.AfterPostProcess;
public override int OrderInInjectionPoint => 100;
[Header("Gradient Colors")]
[Tooltip("外部颜色(边缘)。最暗的地方显示的颜色。")]
public ColorParameter colorOuter = new(Color.black, true, true, true);
[Tooltip("内部颜色(过渡区)。\n当暗角开始出现时显示的颜色。\n设为与外部相同则为单色暗角。\n设为红色可做受伤效果。")]
public ColorParameter colorInner = new(Color.black, true, true, true);
[Header("Shape Settings")]
[Tooltip("中心位置")]
public Vector2Parameter center = new(new Vector2(0.5f, 0.5f));
[Tooltip("强度。0 = 无效果")]
public ClampedFloatParameter intensity = new(0f, 0f, 1f);
[Tooltip("柔和度。控制渐变区域的宽度。")]
public ClampedFloatParameter smoothness = new(0.5f, 0.01f, 1f);
[Tooltip("圆度。1 = 圆形0 = 方形。")]
public ClampedFloatParameter roundness = new(1f, 0f, 1f);
public override string GetShaderName() => "SLS/Postprocessing/AdvancedVignette";
public override void Render(CommandBuffer cmd, ref RenderingData renderingData, RTHandle source, RTHandle destination)
{
if (material == null) return;
material.SetColor(InternalShaderHelpers.ID._ColorInner, colorInner.value);
material.SetColor(InternalShaderHelpers.ID._ColorOuter, colorOuter.value);
material.SetVector(InternalShaderHelpers.ID._VignetteCenter, center.value);
// Pack Params
Vector3 p1 = new Vector3(
intensity.value,
smoothness.value,
roundness.value
);
material.SetVector(InternalShaderHelpers.ID._VignetteParams1, p1);
Blitter.BlitCameraTexture(cmd, source, destination, material, 0);
}
public override bool IsActive()
{
return intensity.value > 0f;
}
}
}