Files
ichni_Creator_Studio/Assets/Shaders/ScriptablePostProcessor/Volumes/Pixelate.cs
SoulliesOfficial 8985d98653 后处理修复
2026-07-09 17:09:34 -04:00

48 lines
2.0 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 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 到 11 为当前渲染分辨率")]
public FloatParameter strengthX = new FloatParameter(1f);
[Tooltip("纵向分辨率比例0 到 11 为当前渲染分辨率")]
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);
}
}
}