Exemple #1
0
    void commandBuffer_FillApplyPostEffect(CommandBuffer cb)
    {
        cb.BeginSample("AO 3 - ApplyPostEffect");

        if (UsingTemporalFilter)
        {
            commandBuffer_TemporalFilter(cb);

            int tmpMotionIntensityRT = 0;

            if (UsingMotionVectors == true)
            {
                tmpMotionIntensityRT = commandBuffer_NeighborMotionIntensity(cb, m_target.width, m_target.height);
            }

            int applyOcclusionRT = 0;
            if (useMRTBlendingFallback)
            {
                applyOcclusionRT = AmplifyOcclusionCommon.SafeAllocateTemporaryRT(cb, "_AO_ApplyOcclusionTexture", m_target.fullWidth, m_target.fullHeight, RenderTextureFormat.ARGB32);
                applyPostEffectTargetsTemporal[0] = applyOcclusionRT;
            }
            else
            {
                applyPostEffectTargetsTemporal[0] = BuiltinRenderTextureType.CameraTarget;
            }

            applyPostEffectTargetsTemporal[1] = new RenderTargetIdentifier(m_temporalAccumRT[m_curTemporalIdx]);

            cb.SetRenderTarget(applyPostEffectTargetsTemporal, applyPostEffectTargetsTemporal[0] /* Not used, just to make Unity happy */);
            PerformBlit(cb, m_applyOcclusionMat, ShaderPass.ApplyPostEffectTemporal + getTemporalPass());

            if (useMRTBlendingFallback)
            {
                cb.SetGlobalTexture("_AO_ApplyOcclusionTexture", applyOcclusionRT);

                cb.SetRenderTarget(BuiltinRenderTextureType.CameraTarget);
                PerformBlit(cb, m_applyOcclusionMat, ShaderPass.ApplyPostEffectTemporalMultiply);

                AmplifyOcclusionCommon.SafeReleaseTemporaryRT(cb, applyOcclusionRT);
            }

            if (UsingMotionVectors == true)
            {
                AmplifyOcclusionCommon.SafeReleaseTemporaryRT(cb, tmpMotionIntensityRT);
            }
        }
        else
        {
            cb.SetGlobalTexture(PropertyID._AO_CurrOcclusionDepth, m_occlusionDepthRT);

            cb.SetRenderTarget(BuiltinRenderTextureType.CameraTarget);
            PerformBlit(cb, m_applyOcclusionMat, ShaderPass.ApplyPostEffect);
        }

        cb.SetRenderTarget(default(RenderTexture));
        cb.EndSample("AO 3 - ApplyPostEffect");
    }
Exemple #2
0
    int commandBuffer_NeighborMotionIntensity(CommandBuffer cb, int aSourceWidth, int aSourceHeight)
    {
        int tmpRT = AmplifyOcclusionCommon.SafeAllocateTemporaryRT(cb, "_AO_IntensityTmp",
                                                                   aSourceWidth / 4, aSourceHeight / 4,
                                                                   m_motionIntensityRTFormat,
                                                                   RenderTextureReadWrite.Linear,
                                                                   FilterMode.Bilinear);


        cb.SetRenderTarget(tmpRT);
        cb.SetGlobalVector("_AO_Target_TexelSize", new Vector4(1.0f / (aSourceWidth / 4.0f),
                                                               1.0f / (aSourceHeight / 4.0f),
                                                               aSourceWidth / 4.0f,
                                                               aSourceHeight / 4.0f));


        PerformBlit(cb, m_occlusionMat, ShaderPass.NeighborMotionIntensity);

        int tmpBlurRT = AmplifyOcclusionCommon.SafeAllocateTemporaryRT(cb, "_AO_BlurIntensityTmp",
                                                                       aSourceWidth / 4, aSourceHeight / 4,
                                                                       m_motionIntensityRTFormat,
                                                                       RenderTextureReadWrite.Linear,
                                                                       FilterMode.Bilinear);

        // Horizontal
        cb.SetGlobalTexture(PropertyID._AO_CurrMotionIntensity, tmpRT);
        cb.SetRenderTarget(tmpBlurRT);
        PerformBlit(cb, m_blurMat, ShaderPass.BlurHorizontalIntensity);

        // Vertical
        cb.SetGlobalTexture(PropertyID._AO_CurrMotionIntensity, tmpBlurRT);
        cb.SetRenderTarget(tmpRT);
        PerformBlit(cb, m_blurMat, ShaderPass.BlurVerticalIntensity);

        AmplifyOcclusionCommon.SafeReleaseTemporaryRT(cb, tmpBlurRT);

        cb.SetGlobalTexture(PropertyID._AO_CurrMotionIntensity, tmpRT);

        return(tmpRT);
    }
Exemple #3
0
    void commandBuffer_Blur(CommandBuffer cb, RenderTargetIdentifier aSourceRT, int aSourceWidth, int aSourceHeight)
    {
        cb.BeginSample("AO 2 - Blur");

        int tmpBlurRT = AmplifyOcclusionCommon.SafeAllocateTemporaryRT(cb, "_AO_BlurTmp",
                                                                       aSourceWidth, aSourceHeight,
                                                                       m_occlusionRTFormat,
                                                                       RenderTextureReadWrite.Linear,
                                                                       FilterMode.Bilinear);

        // Apply Cross Bilateral Blur
        for (int i = 0; i < BlurPasses; i++)
        {
            // Horizontal
            cb.SetGlobalTexture(PropertyID._AO_CurrOcclusionDepth, aSourceRT);

            int blurHorizontalPass = ShaderPass.BlurHorizontal1 + (BlurRadius - 1) * 2;

            cb.SetRenderTarget(tmpBlurRT);

            PerformBlit(cb, m_blurMat, blurHorizontalPass);


            // Vertical
            cb.SetGlobalTexture(PropertyID._AO_CurrOcclusionDepth, tmpBlurRT);

            int blurVerticalPass = ShaderPass.BlurVertical1 + (BlurRadius - 1) * 2;

            cb.SetRenderTarget(aSourceRT);

            PerformBlit(cb, m_blurMat, blurVerticalPass);
        }

        AmplifyOcclusionCommon.SafeReleaseTemporaryRT(cb, tmpBlurRT);

        cb.SetRenderTarget(default(RenderTexture));
        cb.EndSample("AO 2 - Blur");
    }
Exemple #4
0
    void commandBuffer_FillApplyDeferred(CommandBuffer cb, bool logTarget)
    {
        cb.BeginSample("AO 3 - ApplyDeferred");

        if (!logTarget)
        {
            if (UsingTemporalFilter)
            {
                commandBuffer_TemporalFilter(cb);

                int tmpMotionIntensityRT = 0;

                if (UsingMotionVectors == true)
                {
                    tmpMotionIntensityRT = commandBuffer_NeighborMotionIntensity(cb, m_target.width, m_target.height);
                }

                int applyOcclusionRT = 0;
                if (useMRTBlendingFallback)
                {
                    applyOcclusionRT = AmplifyOcclusionCommon.SafeAllocateTemporaryRT(cb, "_AO_ApplyOcclusionTexture", m_target.fullWidth, m_target.fullHeight, RenderTextureFormat.ARGB32);

                    applyOcclusionTemporal[0] = applyOcclusionRT;
                    applyOcclusionTemporal[1] = new RenderTargetIdentifier(m_temporalAccumRT[m_curTemporalIdx]);

                    cb.SetRenderTarget(applyOcclusionTemporal, applyOcclusionTemporal[0] /* Not used, just to make Unity happy */);
                    PerformBlit(cb, m_applyOcclusionMat, ShaderPass.ApplyPostEffectTemporal + getTemporalPass());                       // re-use ApplyPostEffectTemporal pass to apply without Blend to the RT.
                }
                else
                {
                    applyDeferredTargetsTemporal[0] = m_applyDeferredTargets[0];
                    applyDeferredTargetsTemporal[1] = m_applyDeferredTargets[1];
                    applyDeferredTargetsTemporal[2] = new RenderTargetIdentifier(m_temporalAccumRT[m_curTemporalIdx]);

                    cb.SetRenderTarget(applyDeferredTargetsTemporal, applyDeferredTargetsTemporal[0] /* Not used, just to make Unity happy */);
                    PerformBlit(cb, m_applyOcclusionMat, ShaderPass.ApplyDeferredTemporal + getTemporalPass());
                }

                if (useMRTBlendingFallback)
                {
                    cb.SetGlobalTexture("_AO_ApplyOcclusionTexture", applyOcclusionRT);

                    applyOcclusionTemporal[0] = m_applyDeferredTargets[0];
                    applyOcclusionTemporal[1] = m_applyDeferredTargets[1];

                    cb.SetRenderTarget(applyOcclusionTemporal, applyOcclusionTemporal[0] /* Not used, just to make Unity happy */);
                    PerformBlit(cb, m_applyOcclusionMat, ShaderPass.ApplyDeferredTemporalMultiply);

                    AmplifyOcclusionCommon.SafeReleaseTemporaryRT(cb, applyOcclusionRT);
                }

                if (UsingMotionVectors == true)
                {
                    AmplifyOcclusionCommon.SafeReleaseTemporaryRT(cb, tmpMotionIntensityRT);
                }
            }
            else
            {
                cb.SetGlobalTexture(PropertyID._AO_CurrOcclusionDepth, m_occlusionDepthRT);

                // Multiply Occlusion
                cb.SetRenderTarget(m_applyDeferredTargets, m_applyDeferredTargets[0] /* Not used, just to make Unity happy */);
                PerformBlit(cb, m_applyOcclusionMat, ShaderPass.ApplyDeferred);
            }
        }
        else
        {
            // Copy Albedo and Emission to temporary buffers
            int gbufferAlbedoRT = AmplifyOcclusionCommon.SafeAllocateTemporaryRT(cb, "_AO_tmpAlbedo",
                                                                                 m_target.fullWidth, m_target.fullHeight,
                                                                                 RenderTextureFormat.ARGB32);

            int gbufferEmissionRT = AmplifyOcclusionCommon.SafeAllocateTemporaryRT(cb, "_AO_tmpEmission",
                                                                                   m_target.fullWidth, m_target.fullHeight,
                                                                                   m_temporaryEmissionRTFormat);

            cb.Blit(BuiltinRenderTextureType.GBuffer0, gbufferAlbedoRT);
            cb.Blit(BuiltinRenderTextureType.GBuffer3, gbufferEmissionRT);

            cb.SetGlobalTexture(PropertyID._AO_GBufferAlbedo, gbufferAlbedoRT);
            cb.SetGlobalTexture(PropertyID._AO_GBufferEmission, gbufferEmissionRT);

            if (UsingTemporalFilter)
            {
                commandBuffer_TemporalFilter(cb);

                int tmpMotionIntensityRT = 0;

                if (UsingMotionVectors == true)
                {
                    tmpMotionIntensityRT = commandBuffer_NeighborMotionIntensity(cb, m_target.width, m_target.height);
                }

                applyDeferredTargets_Log_Temporal[0] = m_applyDeferredTargets_Log[0];
                applyDeferredTargets_Log_Temporal[1] = m_applyDeferredTargets_Log[1];
                applyDeferredTargets_Log_Temporal[2] = new RenderTargetIdentifier(m_temporalAccumRT[m_curTemporalIdx]);

                cb.SetRenderTarget(applyDeferredTargets_Log_Temporal, applyDeferredTargets_Log_Temporal[0] /* Not used, just to make Unity happy */);
                PerformBlit(cb, m_applyOcclusionMat, ShaderPass.ApplyDeferredLogTemporal + getTemporalPass());

                if (UsingMotionVectors == true)
                {
                    AmplifyOcclusionCommon.SafeReleaseTemporaryRT(cb, tmpMotionIntensityRT);
                }
            }
            else
            {
                cb.SetGlobalTexture(PropertyID._AO_CurrOcclusionDepth, m_occlusionDepthRT);

                cb.SetRenderTarget(m_applyDeferredTargets_Log, m_applyDeferredTargets_Log[0] /* Not used, just to make Unity happy */);
                PerformBlit(cb, m_applyOcclusionMat, ShaderPass.ApplyDeferredLog);
            }

            AmplifyOcclusionCommon.SafeReleaseTemporaryRT(cb, gbufferAlbedoRT);
            AmplifyOcclusionCommon.SafeReleaseTemporaryRT(cb, gbufferEmissionRT);
        }

        cb.SetRenderTarget(default(RenderTexture));
        cb.EndSample("AO 3 - ApplyDeferred");
    }
Exemple #5
0
    private void commandBuffer_FillComputeOcclusion(CommandBuffer cb)
    {
        cb.BeginSample("AO 1 - ComputeOcclusion");

        if ((PerPixelNormals == PerPixelNormalSource.GBuffer) ||
            (PerPixelNormals == PerPixelNormalSource.GBufferOctaEncoded))
        {
            cb.SetGlobalTexture(PropertyID._AO_GBufferNormals, BuiltinRenderTextureType.GBuffer2);
        }

        Vector4 oneOverSize_Size = new Vector4(m_target.oneOverWidth,
                                               m_target.oneOverHeight,
                                               m_target.width,
                                               m_target.height);

        int sampleCountPass = ((int)SampleCount) * AmplifyOcclusionCommon.PerPixelNormalSourceCount;

        int occlusionPass = (ShaderPass.OcclusionLow_None +
                             sampleCountPass +
                             ((int)PerPixelNormals));

        if (CacheAware == true)
        {
            occlusionPass += ShaderPass.OcclusionLow_None_UseDynamicDepthMips;

            // Construct Depth mipmaps
            int previouslyTmpMipRT = 0;

            for (int i = 0; i < m_numberMips; i++)
            {
                int tmpMipRT;

                int width  = m_target.width >> (i + 1);
                int height = m_target.height >> (i + 1);

                tmpMipRT = AmplifyOcclusionCommon.SafeAllocateTemporaryRT(cb, m_tmpMipString[i],
                                                                          width, height,
                                                                          RenderTextureFormat.RFloat,
                                                                          RenderTextureReadWrite.Linear,
                                                                          FilterMode.Bilinear);

                // _AO_CurrDepthSource was previously set
                cb.SetRenderTarget(tmpMipRT);

                PerformBlit(cb, m_occlusionMat, ((i == 0)?ShaderPass.ScaleDownCloserDepthEven_CameraDepthTexture:ShaderPass.ScaleDownCloserDepthEven));

                cb.CopyTexture(tmpMipRT, 0, 0, m_depthMipmap, 0, i);

                if (previouslyTmpMipRT != 0)
                {
                    AmplifyOcclusionCommon.SafeReleaseTemporaryRT(cb, previouslyTmpMipRT);
                }

                previouslyTmpMipRT = tmpMipRT;

                cb.SetGlobalTexture(PropertyID._AO_CurrDepthSource, tmpMipRT);                   // Set next MipRT ID
            }

            AmplifyOcclusionCommon.SafeReleaseTemporaryRT(cb, previouslyTmpMipRT);

            cb.SetGlobalTexture(PropertyID._AO_SourceDepthMipmap, m_depthMipmap);
        }

        if (Downsample)
        {
            int halfWidth  = m_target.width / 2;
            int halfHeight = m_target.height / 2;

            int tmpSmallOcclusionRT = AmplifyOcclusionCommon.SafeAllocateTemporaryRT(cb, "_AO_SmallOcclusionTexture",
                                                                                     halfWidth, halfHeight,
                                                                                     m_occlusionRTFormat,
                                                                                     RenderTextureReadWrite.Linear,
                                                                                     FilterMode.Bilinear);

            cb.SetGlobalVector(PropertyID._AO_Source_TexelSize, oneOverSize_Size);
            cb.SetGlobalVector(PropertyID._AO_Target_TexelSize, new Vector4(1.0f / (m_target.width / 2.0f),
                                                                            1.0f / (m_target.height / 2.0f),
                                                                            m_target.width / 2.0f,
                                                                            m_target.height / 2.0f));

            cb.SetRenderTarget(tmpSmallOcclusionRT);
            PerformBlit(cb, m_occlusionMat, occlusionPass);

            cb.SetRenderTarget(default(RenderTexture));
            cb.EndSample("AO 1 - ComputeOcclusion");

            if (BlurEnabled == true)
            {
                commandBuffer_Blur(cb, tmpSmallOcclusionRT, halfWidth, halfHeight);
            }

            // Combine
            cb.BeginSample("AO 2b - Combine");

            cb.SetGlobalTexture(PropertyID._AO_CurrOcclusionDepth, tmpSmallOcclusionRT);

            cb.SetGlobalVector(PropertyID._AO_Target_TexelSize, oneOverSize_Size);

            cb.SetRenderTarget(m_occlusionDepthRT);

            PerformBlit(cb, m_occlusionMat, ShaderPass.CombineDownsampledOcclusionDepth);

            AmplifyOcclusionCommon.SafeReleaseTemporaryRT(cb, tmpSmallOcclusionRT);

            cb.SetRenderTarget(default(RenderTexture));
            cb.EndSample("AO 2b - Combine");
        }
        else
        {
            cb.SetGlobalVector(PropertyID._AO_Source_TexelSize, oneOverSize_Size);
            cb.SetGlobalVector(PropertyID._AO_Target_TexelSize, oneOverSize_Size);

            cb.SetRenderTarget(m_occlusionDepthRT);
            PerformBlit(cb, m_occlusionMat, occlusionPass);

            cb.SetRenderTarget(default(RenderTexture));
            cb.EndSample("AO 1 - ComputeOcclusion");

            if (BlurEnabled == true)
            {
                commandBuffer_Blur(cb, m_occlusionDepthRT, m_target.width, m_target.height);
            }
        }
    }