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

76 lines
3.3 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 SLSUtilities.Rendering.PostProcessing
{
[System.Serializable, VolumeComponentMenu("SLS/Postprocessing/Strobe Flash")]
public class StrobeFlash : ScriptablePostProcessorVolume
{
public override CustomPostProcessInjectionPoint InjectionPoint => CustomPostProcessInjectionPoint.BeforePostProcess;
public override int OrderInInjectionPoint => 5;
[Header("Master Switch")]
public BoolParameter enableEffect = new(false);
[Header("Binary Colors")]
public ColorParameter colorHigh = new(Color.white);
public ColorParameter colorLow = new(Color.black);
[Header("Threshold & Flash")]
public ClampedFloatParameter grading = new(0.5f, 0f, 1f);
public BoolParameter autoFlash = new(false);
public FloatParameter frequency = new(15f);
public BoolParameter manualInvert = new(false);
[Header("Optimizations (Art Style)")]
[Tooltip("预模糊:消除地面的细碎噪点。")]
public ClampedFloatParameter noiseReduction = new(1.5f, 0f, 5f);
[Tooltip("柔化边缘:让黑白交界处不那么生硬。")]
public ClampedFloatParameter softness = new(0.05f, 0f, 0.5f);
[Header("Outline Settings")]
[Tooltip("描边粗细:建议值 1.0 - 2.0。如果太小可能看不见。")]
public ClampedFloatParameter outlineThickness = new(1f, 0f, 5f);
[Tooltip("描边敏感度阈值 (米):深度差超过此值才画线。\n解决地面全黑的关键参数\n建议值0.5 - 2.0。")]
public MinFloatParameter outlineThreshold = new(1.0f, 0f); // 默认设为 1米
[Tooltip("感光权重")]
public Vector3Parameter luminanceWeights = new(new Vector3(0.2126f, 0.7152f, 0.0722f));
public override string GetShaderName() => "SLS/Postprocessing/StrobeFlash";
public override void Render(CommandBuffer cmd, ref RenderingData renderingData, RTHandle source, RTHandle destination)
{
if (material == null) return;
material.SetColor(InternalShaderHelpers.ID._StrobeColorHigh, colorHigh.value);
material.SetColor(InternalShaderHelpers.ID._StrobeColorLow, colorLow.value);
material.SetVector(InternalShaderHelpers.ID._LuminanceWeights, new Vector4(luminanceWeights.value.x, luminanceWeights.value.y, luminanceWeights.value.z, 0));
Vector4 paramsVec = new Vector4(
frequency.value,
grading.value,
autoFlash.value ? 1f : 0f,
manualInvert.value ? 1f : 0f
);
material.SetVector(InternalShaderHelpers.ID._StrobeParams, paramsVec);
// 更新:传入 outlineThreshold (w分量)
Vector4 advParamsVec = new Vector4(
noiseReduction.value,
softness.value,
outlineThickness.value,
outlineThreshold.value
);
material.SetVector(InternalShaderHelpers.ID._StrobeAdvParams, advParamsVec);
Blitter.BlitCameraTexture(cmd, source, destination, material, 0);
}
public override bool IsActive() => enableEffect.value;
}
}