101 lines
4.4 KiB
C#
101 lines
4.4 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine.Rendering.Universal.Internal;
|
|
|
|
namespace UnityEngine.Rendering.Universal
|
|
{
|
|
internal class DecalDrawGBufferSystem : DecalDrawSystem
|
|
{
|
|
public DecalDrawGBufferSystem(DecalEntityManager entityManager) : base("DecalDrawGBufferSystem.Execute", entityManager) { }
|
|
protected override int GetPassIndex(DecalCachedChunk decalCachedChunk) => decalCachedChunk.passIndexGBuffer;
|
|
}
|
|
|
|
internal class DecalGBufferRenderPass : ScriptableRenderPass
|
|
{
|
|
private FilteringSettings m_FilteringSettings;
|
|
private ProfilingSampler m_ProfilingSampler;
|
|
private List<ShaderTagId> m_ShaderTagIdList;
|
|
private DecalDrawGBufferSystem m_DrawSystem;
|
|
private DecalScreenSpaceSettings m_Settings;
|
|
private DeferredLights m_DeferredLights;
|
|
private RenderTargetIdentifier[] m_GbufferAttachments;
|
|
|
|
public DecalGBufferRenderPass(DecalScreenSpaceSettings settings, DecalDrawGBufferSystem drawSystem)
|
|
{
|
|
renderPassEvent = RenderPassEvent.AfterRenderingGbuffer;
|
|
|
|
m_DrawSystem = drawSystem;
|
|
m_Settings = settings;
|
|
m_ProfilingSampler = new ProfilingSampler("Decal GBuffer Render");
|
|
m_FilteringSettings = new FilteringSettings(RenderQueueRange.opaque, -1);
|
|
|
|
m_ShaderTagIdList = new List<ShaderTagId>();
|
|
if (drawSystem == null)
|
|
m_ShaderTagIdList.Add(new ShaderTagId(DecalShaderPassNames.DecalGBufferProjector));
|
|
else
|
|
m_ShaderTagIdList.Add(new ShaderTagId(DecalShaderPassNames.DecalGBufferMesh));
|
|
}
|
|
|
|
internal void Setup(DeferredLights deferredLights)
|
|
{
|
|
m_DeferredLights = deferredLights;
|
|
}
|
|
|
|
public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
|
|
{
|
|
if (m_DeferredLights != null && m_DeferredLights.UseRenderPass)
|
|
{
|
|
if (m_GbufferAttachments == null)
|
|
m_GbufferAttachments = new RenderTargetIdentifier[]
|
|
{
|
|
m_DeferredLights.GbufferAttachmentIdentifiers[0], m_DeferredLights.GbufferAttachmentIdentifiers[1],
|
|
m_DeferredLights.GbufferAttachmentIdentifiers[2], m_DeferredLights.GbufferAttachmentIdentifiers[3]
|
|
};
|
|
}
|
|
else
|
|
m_GbufferAttachments = m_DeferredLights.GbufferAttachmentIdentifiers;
|
|
|
|
ConfigureTarget(m_GbufferAttachments, m_DeferredLights.DepthAttachmentIdentifier);
|
|
}
|
|
|
|
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
|
|
{
|
|
SortingCriteria sortingCriteria = renderingData.cameraData.defaultOpaqueSortFlags;
|
|
DrawingSettings drawingSettings = CreateDrawingSettings(m_ShaderTagIdList, ref renderingData, sortingCriteria);
|
|
|
|
CommandBuffer cmd = CommandBufferPool.Get();
|
|
using (new ProfilingScope(cmd, m_ProfilingSampler))
|
|
{
|
|
context.ExecuteCommandBuffer(cmd);
|
|
cmd.Clear();
|
|
|
|
NormalReconstruction.SetupProperties(cmd, renderingData.cameraData);
|
|
|
|
CoreUtils.SetKeyword(cmd, ShaderKeywordStrings.DecalNormalBlendLow, m_Settings.normalBlend == DecalNormalBlend.Low);
|
|
CoreUtils.SetKeyword(cmd, ShaderKeywordStrings.DecalNormalBlendMedium, m_Settings.normalBlend == DecalNormalBlend.Medium);
|
|
CoreUtils.SetKeyword(cmd, ShaderKeywordStrings.DecalNormalBlendHigh, m_Settings.normalBlend == DecalNormalBlend.High);
|
|
|
|
context.ExecuteCommandBuffer(cmd);
|
|
cmd.Clear();
|
|
|
|
m_DrawSystem?.Execute(cmd);
|
|
|
|
context.DrawRenderers(renderingData.cullResults, ref drawingSettings, ref m_FilteringSettings);
|
|
}
|
|
context.ExecuteCommandBuffer(cmd);
|
|
CommandBufferPool.Release(cmd);
|
|
}
|
|
|
|
public override void OnCameraCleanup(CommandBuffer cmd)
|
|
{
|
|
if (cmd == null)
|
|
{
|
|
throw new System.ArgumentNullException("cmd");
|
|
}
|
|
|
|
CoreUtils.SetKeyword(cmd, ShaderKeywordStrings.DecalNormalBlendLow, false);
|
|
CoreUtils.SetKeyword(cmd, ShaderKeywordStrings.DecalNormalBlendMedium, false);
|
|
CoreUtils.SetKeyword(cmd, ShaderKeywordStrings.DecalNormalBlendHigh, false);
|
|
}
|
|
}
|
|
}
|