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")] [SupportedOnRenderPipeline(typeof(UniversalRenderPipelineAsset))] public class PixelateVolume : ScriptablePostProcessorVolume { public override CustomPostProcessInjectionPoint InjectionPoint => CustomPostProcessInjectionPoint.AfterPostProcess; public override int OrderInInjectionPoint => 100; [Tooltip("是否强制开启像素化效果")] public BoolParameter forceActive = new BoolParameter(false); [Tooltip("横向分辨率比例,0 到 1;1 为当前渲染分辨率")] public FloatParameter strengthX = new FloatParameter(1f); [Tooltip("纵向分辨率比例,0 到 1;1 为当前渲染分辨率")] public FloatParameter strengthY = new FloatParameter(1f); // 返回我们在 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, Mathf.Clamp01(strengthX.value)); cmd.SetGlobalFloat(InternalShaderHelpers.ID._PixelateStrengthY, Mathf.Clamp01(strengthY.value)); // 使用你的统一管家分发的 Blitter 进行优雅渲染 Blitter.BlitCameraTexture(cmd, source, destination, material, 0); } } }