Esempio n. 1
0
        // Function that will return the set of buffers required for the motion vector pass
        public RenderTargetIdentifier[] GetMotionVectorsPassRTI(FrameSettings frameSettings)
        {
            // Note: Hardware allow to not write in all RT bind only if all the previous RT have been written (i.e there is no bubble)
            // So here we need to guarantee that all RTs but last are written by the shader.
            // Material could enable decal or not in Material so it should be last target
            // However with motion vector pass, unlike for depth prepass we have no way to no if we are deferred (don't write normal buffer)
            // or forward (write normal buffer). As we have a single function to setup the target, we are forcing
            // disabled decals to still write 0 in DecalBuffer while render in the Motion vector pass
            // For this reasons we render normal last, as now decal is permanent
            Debug.Assert(m_MotionVectorsSupport);
            using (ListPool <RenderTargetIdentifier> .Get(out var mrts))
            {
                if (frameSettings.IsEnabled(FrameSettingsField.MSAA))
                {
                    Debug.Assert(m_MSAASupported);
                    mrts.Add(m_DepthAsColorMSAART.nameID);
                    mrts.Add(m_MotionVectorsMSAART.nameID);
                    if (frameSettings.IsEnabled(FrameSettingsField.DecalLayers))
                    {
                        mrts.Add(m_DecalPrePassBufferMSAA.nameID);
                    }
                    mrts.Add(m_NormalMSAART.nameID);
                }
                else
                {
                    mrts.Add(m_MotionVectorsRT.nameID);
                    if (frameSettings.IsEnabled(FrameSettingsField.DecalLayers))
                    {
                        mrts.Add(m_DecalPrePassBuffer.nameID);
                    }
                    mrts.Add(m_NormalRT.nameID);
                }

                switch (mrts.Count)
                {
                case 1:
                    mrts.CopyTo(m_RTIDs1);
                    return(m_RTIDs1);

                case 2:
                    mrts.CopyTo(m_RTIDs2);
                    return(m_RTIDs2);

                case 3:
                    mrts.CopyTo(m_RTIDs3);
                    return(m_RTIDs3);

                case 4:
                    mrts.CopyTo(m_RTIDs4);
                    return(m_RTIDs4);

                default:
                    return(null);
                }
            }
        }
Esempio n. 2
0
        // Function that will return the set of buffers required for the prepass (depending on if msaa is enabled or not)
        public RenderTargetIdentifier[] GetDepthPrepassForwardRTI(FrameSettings frameSettings)
        {
            // Note: Hardware allow to not write in all RT bind only if all the previous RT have been written (i.e there is no bubble)
            // So here we need to guarantee that all RTs but last are written by the shader.
            // Material could enable decal or not in Material so it need to be the last target
            using (ListPool <RenderTargetIdentifier> .Get(out var mrts))
            {
                if (frameSettings.IsEnabled(FrameSettingsField.MSAA))
                {
                    Debug.Assert(m_MSAASupported);
                    mrts.Add(m_DepthAsColorMSAART.nameID);
                    mrts.Add(m_NormalMSAART.nameID);
                    if (frameSettings.IsEnabled(FrameSettingsField.DecalLayers))
                    {
                        mrts.Add(m_DecalPrePassBufferMSAA);
                    }
                }
                else
                {
                    mrts.Add(m_NormalRT.nameID);
                    if (frameSettings.IsEnabled(FrameSettingsField.DecalLayers))
                    {
                        mrts.Add(m_DecalPrePassBuffer);
                    }
                }

                switch (mrts.Count)
                {
                case 1:
                    mrts.CopyTo(m_RTIDs1);
                    return(m_RTIDs1);

                case 2:
                    mrts.CopyTo(m_RTIDs2);
                    return(m_RTIDs2);

                case 3:
                    mrts.CopyTo(m_RTIDs3);
                    return(m_RTIDs3);

                default:
                    return(null);
                }
            }
        }
Esempio n. 3
0
        // Function that will return the set of buffers required for the prepass (depending on if msaa is enabled or not)
        public RenderTargetIdentifier[] GetDepthPrepassDeferredRTI(FrameSettings frameSettings)
        {
            // In deferred we did nothing if decal aren't enabled
            if (!frameSettings.IsEnabled(FrameSettingsField.DecalLayers))
            {
                return(null);
            }

            // Note: In deferred we can't have MSAA
            m_RTIDs1Deferred[0] = m_DecalPrePassBuffer.nameID;
            return(m_RTIDs1Deferred);
        }
Esempio n. 4
0
        // This function will setup the required render target array. This take into account if shadow mask and light layers are enabled or not.
        // Note for the future: Setup works fine as we don't have change per object (like velocity for example). If in the future it is the case
        // the changing per object buffer MUST be the last one so the shader can decide if it write to it or not
        public RenderTargetIdentifier[] GetBuffersRTI(FrameSettings frameSettings)
        {
            // We do two loop to avoid to have to allocate an array every frame
            // Do a first step to know how many RT we require
            int gbufferIndex = 0;

            for (int i = 0; i < m_BufferCount; ++i)
            {
                if (m_GBufferUsage[i] == GBufferUsage.ShadowMask && !frameSettings.IsEnabled(FrameSettingsField.ShadowMask))
                {
                    continue; // Skip
                }
                if (m_GBufferUsage[i] == GBufferUsage.LightLayers && !frameSettings.IsEnabled(FrameSettingsField.LightLayers))
                {
                    continue; // Skip
                }
                gbufferIndex++;
            }

            // Now select the correct array and do another loop to fill the array
            RenderTargetIdentifier[] m_RTIDsArrayCurrent = m_RTIDsArray[gbufferIndex - 1];

            gbufferIndex = 0;
            // nameID can change from one frame to another depending on the msaa flag so so we need to update this array to be sure it's up to date.
            for (int i = 0; i < m_BufferCount; ++i)
            {
                if (m_GBufferUsage[i] == GBufferUsage.ShadowMask && !frameSettings.IsEnabled(FrameSettingsField.ShadowMask))
                {
                    continue; // Skip
                }
                if (m_GBufferUsage[i] == GBufferUsage.LightLayers && !frameSettings.IsEnabled(FrameSettingsField.LightLayers))
                {
                    continue; // Skip
                }
                m_RTIDsArrayCurrent[gbufferIndex] = m_RTs[i].nameID;
                gbufferIndex++;
            }

            return(m_RTIDsArrayCurrent);
        }
Esempio n. 5
0
        internal static void MigrateMSAA(ref FrameSettings cameraFrameSettings, ref FrameSettingsOverrideMask newFrameSettingsOverrideMask)
        {
            if (cameraFrameSettings.IsEnabled(FrameSettingsField.MSAA))
            {
                cameraFrameSettings.msaaMode = MSAAMode.FromHDRPAsset;
            }
            else
            {
                cameraFrameSettings.msaaMode = MSAAMode.None;
            }

            newFrameSettingsOverrideMask.mask[(int)FrameSettingsField.MSAAMode] = newFrameSettingsOverrideMask.mask[(int)FrameSettingsField.MSAA];
            newFrameSettingsOverrideMask.mask[(int)FrameSettingsField.MSAA]     = false;
        }
Esempio n. 6
0
 // Function that will return the set of buffers required for the prepass (depending on if msaa is enabled or not)
 public RenderTargetIdentifier[] GetPrepassBuffersRTI(FrameSettings frameSettings)
 {
     if (frameSettings.IsEnabled(FrameSettingsField.MSAA))
     {
         Debug.Assert(m_MSAASupported);
         m_RTIDs2[0] = m_NormalMSAART.nameID;
         m_RTIDs2[1] = m_DepthAsColorMSAART.nameID;
         return(m_RTIDs2);
     }
     else
     {
         m_RTIDs1[0] = m_NormalRT.nameID;
         return(m_RTIDs1);
     }
 }
Esempio n. 7
0
 // Function that will return the set of buffers required for the motion vector pass
 public RenderTargetIdentifier[] GetMotionVectorsPassBuffersRTI(FrameSettings frameSettings)
 {
     Debug.Assert(m_MotionVectorsSupport);
     if (frameSettings.IsEnabled(FrameSettingsField.MSAA))
     {
         Debug.Assert(m_MSAASupported);
         m_RTIDs3[0] = m_MotionVectorsMSAART.nameID;
         m_RTIDs3[1] = m_NormalMSAART.nameID;
         m_RTIDs3[2] = m_DepthAsColorMSAART.nameID;
         return(m_RTIDs3);
     }
     else
     {
         Debug.Assert(m_MotionVectorsSupport);
         m_RTIDs2[0] = m_MotionVectorsRT.nameID;
         m_RTIDs2[1] = m_NormalRT.nameID;
         return(m_RTIDs2);
     }
 }
Esempio n. 8
0
        public void RenderShadows(CullingResults cullResults, FrameSettings frameSettings, ScriptableRenderContext renderContext, CommandBuffer cmd)
        {
            if (m_ShadowRequests.Count == 0)
            {
                return;
            }

            ShadowDrawingSettings shadowDrawSettings = new ShadowDrawingSettings(cullResults, 0);

            shadowDrawSettings.useRenderingLayerMaskTest = frameSettings.IsEnabled(FrameSettingsField.LightLayers);

            var parameters = PrepareRenderShadowsParameters();

            RenderShadows(parameters, m_Atlas, shadowDrawSettings, renderContext, cmd);

            if (parameters.blurAlgorithm == BlurAlgorithm.IM)
            {
                IMBlurMoment(parameters, m_Atlas, m_AtlasMoments[0], m_IntermediateSummedAreaTexture, m_SummedAreaTexture, cmd);
            }
            else if (parameters.blurAlgorithm == BlurAlgorithm.EVSM)
            {
                EVSMBlurMoments(parameters, m_Atlas, m_AtlasMoments, cmd);
            }
        }
Esempio n. 9
0
        internal TextureHandle RenderShadows(RenderGraph renderGraph, CullingResults cullResults, FrameSettings frameSettings, string shadowPassName)
        {
            TextureHandle result = new TextureHandle();

            if (m_ShadowRequests.Count == 0)
            {
                return(result);
            }

            using (var builder = renderGraph.AddRenderPass <RenderShadowsPassData>(shadowPassName, out var passData, ProfilingSampler.Get(HDProfileId.RenderShadowMaps)))
            {
                passData.parameters = PrepareRenderShadowsParameters();
                // TODO: Get rid of this and refactor to use the same kind of API than RendererList
                passData.shadowDrawSettings = new ShadowDrawingSettings(cullResults, 0);
                passData.shadowDrawSettings.useRenderingLayerMaskTest = frameSettings.IsEnabled(FrameSettingsField.LightLayers);
                passData.atlasTexture = builder.WriteTexture(
                    renderGraph.CreateTexture(new TextureDesc(width, height)
                {
                    filterMode = m_FilterMode, depthBufferBits = m_DepthBufferBits, isShadowMap = true, name = m_Name, clearBuffer = passData.parameters.debugClearAtlas
                }, passData.parameters.atlasShaderID));

                result = passData.atlasTexture;

                if (passData.parameters.blurAlgorithm == BlurAlgorithm.EVSM)
                {
                    passData.momentAtlasTexture1 = builder.WriteTexture(AllocateMomentAtlas(renderGraph, string.Format("{0}Moment", m_Name), passData.parameters.momentAtlasShaderID));
                    passData.momentAtlasTexture2 = builder.WriteTexture(AllocateMomentAtlas(renderGraph, string.Format("{0}MomentCopy", m_Name)));

                    result = passData.momentAtlasTexture1;
                }
                else if (passData.parameters.blurAlgorithm == BlurAlgorithm.IM)
                {
                    passData.momentAtlasTexture1 = builder.WriteTexture(renderGraph.CreateTexture(new TextureDesc(width, height)
                    {
                        colorFormat = GraphicsFormat.R32G32B32A32_SFloat, name = string.Format("{0}Moment", m_Name), enableRandomWrite = true
                    }, passData.parameters.momentAtlasShaderID));
                    passData.intermediateSummedAreaTexture = builder.WriteTexture(renderGraph.CreateTexture(new TextureDesc(width, height)
                    {
                        colorFormat = GraphicsFormat.R32G32B32A32_SInt, name = string.Format("{0}IntermediateSummedArea", m_Name), enableRandomWrite = true
                    }, passData.parameters.momentAtlasShaderID));
                    passData.summedAreaTexture = builder.WriteTexture(renderGraph.CreateTexture(new TextureDesc(width, height)
                    {
                        colorFormat = GraphicsFormat.R32G32B32A32_SInt, name = string.Format("{0}SummedArea", m_Name), enableRandomWrite = true
                    }, passData.parameters.momentAtlasShaderID));

                    result = passData.momentAtlasTexture1;
                }


                builder.SetRenderFunc(
                    (RenderShadowsPassData data, RenderGraphContext context) =>
                {
                    RTHandle atlasTexture = context.resources.GetTexture(data.atlasTexture);
                    RenderShadows(data.parameters,
                                  atlasTexture,
                                  data.shadowDrawSettings,
                                  context.renderContext, context.cmd);

                    if (data.parameters.blurAlgorithm == BlurAlgorithm.EVSM)
                    {
                        RTHandle[] momentTextures = context.renderGraphPool.GetTempArray <RTHandle>(2);
                        momentTextures[0]         = context.resources.GetTexture(data.momentAtlasTexture1);
                        momentTextures[1]         = context.resources.GetTexture(data.momentAtlasTexture2);

                        EVSMBlurMoments(data.parameters, atlasTexture, momentTextures, context.cmd);
                    }
                    else if (data.parameters.blurAlgorithm == BlurAlgorithm.IM)
                    {
                        RTHandle momentAtlas            = context.resources.GetTexture(data.momentAtlasTexture1);
                        RTHandle intermediateSummedArea = context.resources.GetTexture(data.intermediateSummedAreaTexture);
                        RTHandle summedArea             = context.resources.GetTexture(data.summedAreaTexture);
                        IMBlurMoment(data.parameters, atlasTexture, momentAtlas, intermediateSummedArea, summedArea, context.cmd);
                    }
                });

                return(result);
            }
        }