Files
Cielonos/Assets/Shaders/ScriptablePostProcessor/PostProcessing/SpeedLines.cs
SoulliesOfficial ef7b479712 initial
2025-11-25 08:19:33 -05:00

68 lines
3.5 KiB
C#
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.
using Echovoid.Runtime.Behavior.Rendering;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
namespace SLSFramework.Rendering.PostProcessing
{
[System.Serializable, VolumeComponentMenu("Custom/Speed Lines")]
public class SpeedLines : ScriptablePostProcessorVolume
{
// 注入点:这决定了你的效果在 URP 渲染的哪个阶段执行
// AfterPostProcess 意味着它会在所有内置后处理(如 Bloom, Vignette之后运行
public override CustomPostProcessInjectionPoint InjectionPoint => CustomPostProcessInjectionPoint.AfterPostProcess;
public override int OrderInInjectionPoint => 20; // 调整执行顺序
[Header("Effect Color & Intensity")]
// 对应原 Shader 的 _Colour
// 我们将 Alpha 通道 (a) 用作效果的总体强度
public ColorParameter color = new(new Color(1f, 1f, 1f, 0.5f), true, true, true);
[Header("Lines")]
// 对应 _SpeedLinesTiling
public FloatParameter speedLinesTiling = new(200f);
// 对应 _SpeedLinesRadialScale
public ClampedFloatParameter speedLinesRadialScale = new(0.1f, 0f, 10f);
// 对应 _SpeedLinesPower
public FloatParameter speedLinesPower = new(0f);
// 对应 _SpeedLinesRemap
public ClampedFloatParameter speedLinesRemap = new(1f, 0f, 1f);
// 对应 _SpeedLinesAnimation
public FloatParameter speedLinesAnimation = new(3f);
[Header("Radial Mask")]
// 对应 _MaskScale
public ClampedFloatParameter maskScale = new(1f, 0f, 2f);
// 对应 _MaskHardness
public ClampedFloatParameter maskHardness = new(0f, 0f, 1f);
// 对应 _MaskPower
public FloatParameter maskPower = new(5f);
// 告诉框架这个效果的 Shader "外壳" 文件叫什么名字
protected override string GetShaderName() => "Hidden/Custom/SpeedLines";
// 这是 "激活" 逻辑。我们检查颜色参数的 alpha 值。
// 原 Shader 使用 alpha 混合,所以 alpha 为 0 意味着效果不可见。
public override bool IsActive() => speedLinesRemap.value < 1f || color.value.a > 0f;
// Render() 函数:每一帧将 C# 中的参数值发送到 GPU
public override void Render(CommandBuffer cmd, ref RenderingData renderingData, RTHandle source, RTHandle target)
{
if (material == null) return;
// 将所有 Volume 参数设置到 Material 上
material.SetColor(InternalShaderHelpers.ID._SpeedLinesColour, color.value);
material.SetFloat(InternalShaderHelpers.ID._SpeedLinesTiling, speedLinesTiling.value);
material.SetFloat(InternalShaderHelpers.ID._SpeedLinesRadialScale, speedLinesRadialScale.value);
material.SetFloat(InternalShaderHelpers.ID._SpeedLinesPower, speedLinesPower.value);
material.SetFloat(InternalShaderHelpers.ID._SpeedLinesRemap, speedLinesRemap.value);
material.SetFloat(InternalShaderHelpers.ID._SpeedLinesAnimation, speedLinesAnimation.value);
material.SetFloat(InternalShaderHelpers.ID._MaskScale, maskScale.value);
material.SetFloat(InternalShaderHelpers.ID._MaskHardness, maskHardness.value);
material.SetFloat(InternalShaderHelpers.ID._MaskPower, maskPower.value);
// 执行 Blit使用 Shader 的第 0 个 Pass
Blitter.BlitCameraTexture(cmd, source, target, material, 0);
}
}
}