2026-03-14 03:13:10 -04:00
|
|
|
|
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);
|
2026-07-09 17:10:17 -04:00
|
|
|
|
|
|
|
|
|
|
[Tooltip("横向分辨率比例,0 到 1;1 为当前渲染分辨率")]
|
|
|
|
|
|
public FloatParameter strengthX = new FloatParameter(1f);
|
|
|
|
|
|
|
|
|
|
|
|
[Tooltip("纵向分辨率比例,0 到 1;1 为当前渲染分辨率")]
|
|
|
|
|
|
public FloatParameter strengthY = new FloatParameter(1f);
|
2026-03-14 03:13:10 -04:00
|
|
|
|
|
|
|
|
|
|
// 返回我们在 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;
|
|
|
|
|
|
|
2026-07-09 17:10:17 -04:00
|
|
|
|
cmd.SetGlobalFloat(InternalShaderHelpers.ID._PixelateStrengthX, Mathf.Clamp01(strengthX.value));
|
|
|
|
|
|
cmd.SetGlobalFloat(InternalShaderHelpers.ID._PixelateStrengthY, Mathf.Clamp01(strengthY.value));
|
2026-03-14 03:13:10 -04:00
|
|
|
|
|
|
|
|
|
|
// 使用你的统一管家分发的 Blitter 进行优雅渲染
|
|
|
|
|
|
Blitter.BlitCameraTexture(cmd, source, destination, material, 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2026-07-09 17:10:17 -04:00
|
|
|
|
}
|