using System; using Echovoid.Runtime.Behavior.Rendering; using SLSUtilities.Rendering.PostProcessing; using UnityEngine; using UnityEngine.Rendering; using UnityEngine.Rendering.Universal; namespace SLSUtilities.Rendering.PostProcessing { [Serializable, VolumeComponentMenu("SLS/Postprocessing/Pixelate")] public class PixelateVolume : ScriptablePostProcessorVolume { public override CustomPostProcessInjectionPoint InjectionPoint => CustomPostProcessInjectionPoint.AfterPostProcess; public override int OrderInInjectionPoint => 100; [Tooltip("是否强制开启像素化效果")] public BoolParameter forceActive = new BoolParameter(false); public FloatParameter strengthX = new FloatParameter(1920f); public FloatParameter strengthY = new FloatParameter(1080f); // 返回我们在 Shader 里定义的名字,保证管家可以据此获取材质 public override string GetShaderName() => "Hidden/Custom/Pixelate"; public override bool IsActive() { // 当激活开关开启时才执行后期渲染(节省平时不开时的性能) return forceActive.value; } public override void Render(CommandBuffer cmd, ref RenderingData renderingData, RTHandle source, RTHandle destination) { if (material == null) return; cmd.SetGlobalFloat(InternalShaderHelpers.ID._PixelateStrengthX, strengthX.value); cmd.SetGlobalFloat(InternalShaderHelpers.ID._PixelateStrengthY, strengthY.value); // 使用你的统一管家分发的 Blitter 进行优雅渲染 Blitter.BlitCameraTexture(cmd, source, destination, material, 0); } } }