Example #1
0
        protected void PerformPostProcessing(RenderTexture source, RenderTexture dest, PostProcessParameters postProcessParams)
        {
            //Graphics.Blit(source, dest);
            source = DepthOfFieldStep(postProcessParams, source);

            //Do this after DoF so DoF gets included (if active)
            postProcessParams.halfResSource = m_downsampling.DownsampleFireflyRemoving(source);
            //postProcessParams.halfResSource = m_downsampling.Downsample(source);

            if (postProcessParams.bloom == true)
            {
                postProcessParams.bloomTexture = m_bloomClass.CreateBloomTexture(postProcessParams.halfResSource, postProcessParams.bloomParams);
                if (postProcessParams.exposure == true)
                {
                    const int     minimumReqPixels = 100;
                    int           numSearches;
                    RenderTexture textureToAverage = m_bloomClass.TryGetSmallBloomTexture(minimumReqPixels, out numSearches);
                    float         energyNormalizer = m_bloomClass.GetEnergyNormalizer(numSearches);
                    if (textureToAverage == null)
                    {
                        textureToAverage = postProcessParams.halfResSource; energyNormalizer = 1.0f;
                    }
                    m_virtualCamera.CalculateVirtualCamera(postProcessParams.cameraParams, textureToAverage, postProcessParams.halfWidth, postProcessParams.preCalcValues.tanHalfFoV,
                                                           energyNormalizer, postProcessParams.DoFParams.focalDistance, postProcessParams.isFirstRender);
                }
            }
            else if (postProcessParams.exposure == true)
            {
                m_virtualCamera.CalculateVirtualCamera(postProcessParams.cameraParams, postProcessParams.halfResSource, postProcessParams.halfWidth,
                                                       postProcessParams.preCalcValues.tanHalfFoV, 1.0f, postProcessParams.DoFParams.focalDistance, postProcessParams.isFirstRender);
            }

            //Graphics.Blit(source, dest);
            m_combinationPass.Combine(source, dest, postProcessParams, m_virtualCamera);
            m_scionDebug.VisualizeDebug(dest);

            RenderTexture.ReleaseTemporary(postProcessParams.halfResSource);
            RenderTexture.ReleaseTemporary(postProcessParams.halfResDepth);
            RenderTexture.ReleaseTemporary(postProcessParams.dofTexture);

            m_bloomClass.EndOfFrameCleanup();
            m_virtualCamera.EndOfFrameCleanup();
            m_depthOfFieldClass.EndOfFrameCleanup();

            if (postProcessParams.depthOfField == true)
            {
                RenderTexture.ReleaseTemporary(source);
            }
        }