86 lines
3.4 KiB
C#
86 lines
3.4 KiB
C#
using Echovoid.Runtime.Behavior.Rendering;
|
|
using UnityEngine;
|
|
using UnityEngine.Rendering;
|
|
using UnityEngine.Rendering.Universal;
|
|
|
|
namespace SLSUtilities.Rendering.PostProcessing
|
|
{
|
|
[System.Serializable, VolumeComponentMenu("SLS/Postprocessing/Advanced Chromatic Aberration")]
|
|
public class AdvancedChromaticAberration : ScriptablePostProcessorVolume
|
|
{
|
|
// 建议放在 PostProcess 之后,作为最终的镜头效果
|
|
public override CustomPostProcessInjectionPoint InjectionPoint => CustomPostProcessInjectionPoint.AfterPostProcess;
|
|
public override int OrderInInjectionPoint => 20;
|
|
|
|
[Header("Main Settings")]
|
|
[Tooltip("色散总强度")]
|
|
public ClampedFloatParameter intensity = new(0f, 0f, 1f);
|
|
|
|
[Tooltip("扩散中心点 (0.5, 0.5 为屏幕中心)")]
|
|
public Vector2Parameter center = new(new Vector2(0.5f, 0.5f));
|
|
|
|
[Tooltip("RGB 分离权重。控制每个通道向外扩散的程度。\n例如 (1, 0, -1) 会让红蓝向相反方向分离,绿色不动。")]
|
|
public Vector3Parameter channelSplit = new(new Vector3(1f, 0f, -1f));
|
|
|
|
[Header("Dispersion Map (Broken Glass/Glitch)")]
|
|
[Tooltip("输入的噪波贴图,用于打乱色散的方向")]
|
|
public TextureParameter dispersionMap = new(null);
|
|
|
|
[Tooltip("贴图对色散方向的影响力")]
|
|
public ClampedFloatParameter dispersionStrength = new(0f, 0f, 2f);
|
|
|
|
[Header("Jitter (Temporal Instability)")]
|
|
[Tooltip("UV 采样抖动强度")]
|
|
public ClampedFloatParameter jitterIntensity = new(0f, 0f, 1f);
|
|
|
|
[Tooltip("抖动速度")]
|
|
public FloatParameter jitterSpeed = new(10f);
|
|
|
|
[Header("Masking")]
|
|
[Tooltip("中心保留清晰的半径 (0-1)")]
|
|
public ClampedFloatParameter maskRadius = new(0.2f, 0f, 1f);
|
|
|
|
[Tooltip("遮罩边缘的软硬度")]
|
|
public ClampedFloatParameter maskHardness = new(0.2f, 0.01f, 1f);
|
|
|
|
public override string GetShaderName() => "SLS/Postprocessing/AdvancedChromaticAberration";
|
|
|
|
public override void Render(CommandBuffer cmd, ref RenderingData renderingData, RTHandle source, RTHandle destination)
|
|
{
|
|
if (material == null) return;
|
|
|
|
// Pack Params 1
|
|
Vector4 p1 = new Vector4(
|
|
intensity.value,
|
|
center.value.x,
|
|
center.value.y,
|
|
maskRadius.value
|
|
);
|
|
|
|
// Pack Params 2
|
|
Vector4 p2 = new Vector4(
|
|
jitterIntensity.value,
|
|
jitterSpeed.value,
|
|
dispersionStrength.value,
|
|
maskHardness.value
|
|
);
|
|
|
|
material.SetVector(InternalShaderHelpers.ID._ACA_Params1, p1);
|
|
material.SetVector(InternalShaderHelpers.ID._ACA_Params2, p2);
|
|
material.SetVector(InternalShaderHelpers.ID._ACA_Split, channelSplit.value);
|
|
|
|
if (dispersionMap.value != null)
|
|
{
|
|
material.SetTexture(InternalShaderHelpers.ID._DispersionMap, dispersionMap.value);
|
|
}
|
|
|
|
Blitter.BlitCameraTexture(cmd, source, destination, material, 0);
|
|
}
|
|
|
|
public override bool IsActive()
|
|
{
|
|
// 只要有强度,或者有抖动,就需要渲染
|
|
return intensity.value > 0f || jitterIntensity.value > 0f;
|
|
}
|
|
}
|
|
} |