46 lines
2.0 KiB
C#
46 lines
2.0 KiB
C#
using Unity.Toonshader;
|
|
using UnityEngine;
|
|
using UnityEngine.Rendering;
|
|
using UnityEngine.Rendering.HighDefinition;
|
|
|
|
public class UTSOutlinePass : DrawRenderersCustomPass
|
|
{
|
|
protected override void Execute(CustomPassContext ctx)
|
|
{
|
|
UTSRenderer utsRenderer = ctx.hdCamera.volumeStack.GetComponent<UTSRenderer>();
|
|
if (utsRenderer == null)
|
|
return;
|
|
|
|
if (!utsRenderer.enableOutline.value || !utsRenderer.enable.value)
|
|
return;
|
|
|
|
Shader.SetGlobalFloat("_Outline_MaxWidth", utsRenderer.outlineMaxWidth.value * 0.01f);
|
|
|
|
ShaderTagId outlineTag = new ShaderTagId("Outline");
|
|
|
|
RenderStateMask mask = RenderStateMask.Nothing;
|
|
RenderStateBlock stateBlock = new RenderStateBlock(mask)
|
|
{
|
|
depthState = new DepthState(depthWrite, depthCompareFunction),
|
|
// We disable the stencil when the depth is overwritten but we don't write to it, to prevent writing to the stencil.
|
|
stencilState = new StencilState(false),
|
|
};
|
|
|
|
PerObjectData renderConfig = ctx.hdCamera.frameSettings.IsEnabled(FrameSettingsField.Shadowmask) ? HDUtils.GetRendererConfiguration(true, false) : HDUtils.GetRendererConfiguration(false, true);
|
|
|
|
UnityEngine.Rendering.RendererUtils.RendererListDesc result = new UnityEngine.Rendering.RendererUtils.RendererListDesc(outlineTag, ctx.cullingResults, ctx.hdCamera.camera)
|
|
{
|
|
rendererConfiguration = renderConfig,
|
|
renderQueueRange = GetRenderQueueRange(renderQueueType),
|
|
sortingCriteria = sortingCriteria,
|
|
excludeObjectMotionVectors = true,
|
|
overrideMaterial = overrideMaterial,
|
|
overrideMaterialPassIndex = (overrideMaterial != null) ? overrideMaterial.FindPass(overrideMaterialPassName) : 0,
|
|
stateBlock = stateBlock,
|
|
layerMask = layerMask,
|
|
};
|
|
|
|
ScriptableRenderContext renderCtx = ctx.renderContext;
|
|
CoreUtils.DrawRendererList(renderCtx, ctx.cmd, renderCtx.CreateRendererList(result));
|
|
}
|
|
} |