2025-12-15 21:15:33 +09:00

116 lines
4.2 KiB
C#

// NiloToon Fur Shell Pass
// Renders fur shell pass for materials with "NiloToonFurShell" LightMode tag
// Only handles fur rendering - mask buffer is handled by NiloToonFurMaskPass
using System;
using UnityEngine;
using UnityEngine.Rendering;
#if UNITY_6000_0_OR_NEWER
using UnityEngine.Rendering.RenderGraphModule;
#endif
using UnityEngine.Rendering.Universal;
namespace NiloToon.NiloToonURP
{
public class NiloToonFurShellPass : ScriptableRenderPass
{
static readonly ShaderTagId furShellLightModeShaderTagId = new ShaderTagId("NiloToonFurShell");
[Serializable]
public class Settings
{
[Header("Fur Shell Settings")]
[Tooltip("Enable to render fur shells.\n\nDefault: ON")]
public bool ShouldRenderFurShell = true;
[Tooltip("When to render fur shells in the rendering pipeline.\n\nDefault: AfterRenderingSkybox + 1 (right after classic outline)")]
public RenderPassEvent renderTiming = RenderPassEvent.AfterRenderingSkybox + 1;
}
Settings settings;
ProfilingSampler m_ProfilingSampler;
RenderQueueRange renderQueueRange;
public NiloToonFurShellPass(Settings settings)
{
this.settings = settings;
m_ProfilingSampler = new ProfilingSampler("NiloToonFurShellPass");
this.renderQueueRange = RenderQueueRange.all;
}
#if UNITY_6000_0_OR_NEWER
[Obsolete]
#endif
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
if (!settings.ShouldRenderFurShell)
return;
CommandBuffer cmd = CommandBufferPool.Get();
using (new ProfilingScope(cmd, m_ProfilingSampler))
{
context.ExecuteCommandBuffer(cmd);
cmd.Clear();
DrawingSettings drawingSettings = CreateDrawingSettings(
furShellLightModeShaderTagId,
ref renderingData,
SortingCriteria.CommonTransparent
);
FilteringSettings filteringSettings = new FilteringSettings(renderQueueRange);
context.DrawRenderers(renderingData.cullResults, ref drawingSettings, ref filteringSettings);
}
context.ExecuteCommandBuffer(cmd);
cmd.Clear();
CommandBufferPool.Release(cmd);
}
#if UNITY_6000_0_OR_NEWER
private class PassData
{
public RendererListHandle rendererListHandle;
}
public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer frameData)
{
if (!settings.ShouldRenderFurShell)
return;
UniversalRenderingData renderingData = frameData.Get<UniversalRenderingData>();
UniversalCameraData cameraData = frameData.Get<UniversalCameraData>();
UniversalLightData lightData = frameData.Get<UniversalLightData>();
UniversalResourceData resourceData = frameData.Get<UniversalResourceData>();
using (var builder = renderGraph.AddRasterRenderPass<PassData>("NiloToonFurShellPass", out var passData, m_ProfilingSampler))
{
var drawingSettings = RenderingUtils.CreateDrawingSettings(
furShellLightModeShaderTagId,
renderingData,
cameraData,
lightData,
SortingCriteria.CommonTransparent
);
var filteringSettings = new FilteringSettings(renderQueueRange);
var renderListParams = new RendererListParams(renderingData.cullResults, drawingSettings, filteringSettings);
passData.rendererListHandle = renderGraph.CreateRendererList(renderListParams);
builder.UseRendererList(passData.rendererListHandle);
builder.SetRenderAttachment(resourceData.activeColorTexture, 0);
builder.SetRenderAttachmentDepth(resourceData.activeDepthTexture);
builder.SetRenderFunc((PassData data, RasterGraphContext rgContext) =>
{
rgContext.cmd.DrawRendererList(data.rendererListHandle);
});
}
}
#endif
}
}