Files
com.misaki.hdrp-toon/Runtime/UTS Renderer/UTSToonmapping/UTSTonemapping.cs
2025-01-31 17:25:19 +09:00

48 lines
1.7 KiB
C#

using System;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;
[Serializable, VolumeComponentMenu("Post-processing/UTS Tonemapping")]
public sealed class UTSTonemapping : CustomPostProcessVolumeComponent, IPostProcessComponent
{
[Tooltip("Controls the intensity of the effect.")]
public BoolParameter state = new BoolParameter(false, BoolParameter.DisplayType.EnumPopup);
private Material _material;
public bool IsActive() => _material != null && state.value;
// Do not forget to add this post process in the Custom Post Process Orders list (Project Settings > Graphics > HDRP Global Settings).
public override CustomPostProcessInjectionPoint injectionPoint => CustomPostProcessInjectionPoint.AfterPostProcess;
const string Shader_Name = "Hidden/Shader/UTSTonemapping";
public override void Setup()
{
if (Shader.Find(Shader_Name) != null)
{
_material = CoreUtils.CreateEngineMaterial(Shader_Name);
}
else
{
Debug.LogError($"Unable to find shader '{Shader_Name}'. Post Process Volume UTSToonmapping is unable to load. To fix this, please edit the 'kShaderName' constant in UTSToonmapping.cs or change the name of your custom post process shader.");
}
}
public override void Render(CommandBuffer cmd, HDCamera camera, RTHandle source, RTHandle destination)
{
if (_material == null || !state.value)
{
return;
}
_material.SetTexture("_MainTex", source);
HDUtils.DrawFullScreen(cmd, _material, destination, shaderPassId: 0);
}
public override void Cleanup()
{
CoreUtils.Destroy(_material);
}
}