using System.Collections.Generic; using UnityEngine.Rendering.Universal.Internal; namespace UnityEngine.Rendering.Universal { internal class DecalDrawScreenSpaceSystem : DecalDrawSystem { public DecalDrawScreenSpaceSystem(DecalEntityManager entityManager) : base("DecalDrawScreenSpaceSystem.Execute", entityManager) { } protected override int GetPassIndex(DecalCachedChunk decalCachedChunk) => decalCachedChunk.passIndexScreenSpace; } internal class DecalScreenSpaceRenderPass : ScriptableRenderPass { private FilteringSettings m_FilteringSettings; private ProfilingSampler m_ProfilingSampler; private List m_ShaderTagIdList; private DecalDrawScreenSpaceSystem m_DrawSystem; private DecalScreenSpaceSettings m_Settings; public DecalScreenSpaceRenderPass(DecalScreenSpaceSettings settings, DecalDrawScreenSpaceSystem drawSystem) { renderPassEvent = RenderPassEvent.AfterRenderingSkybox; ConfigureInput(ScriptableRenderPassInput.Depth); // Require depth m_DrawSystem = drawSystem; m_Settings = settings; m_ProfilingSampler = new ProfilingSampler("Decal Screen Space Render"); m_FilteringSettings = new FilteringSettings(RenderQueueRange.opaque, -1); m_ShaderTagIdList = new List(); if (m_DrawSystem == null) m_ShaderTagIdList.Add(new ShaderTagId(DecalShaderPassNames.DecalScreenSpaceProjector)); else m_ShaderTagIdList.Add(new ShaderTagId(DecalShaderPassNames.DecalScreenSpaceMesh)); } public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData) { SortingCriteria sortingCriteria = SortingCriteria.CommonTransparent; DrawingSettings drawingSettings = CreateDrawingSettings(m_ShaderTagIdList, ref renderingData, sortingCriteria); CommandBuffer cmd = CommandBufferPool.Get(); using (new ProfilingScope(cmd, m_ProfilingSampler)) { context.ExecuteCommandBuffer(cmd); cmd.Clear(); RenderingUtils.SetScaleBiasRt(cmd, in renderingData); 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); } } }