예제 #1
0
        public void Render(RenderTexture source, RenderTexture destination)
        {
            Material material = this.context.materialFactory.Get("Hidden/Post FX/Temporal Anti-aliasing");

            material.shaderKeywords = null;
            AntialiasingModel.TaaSettings taaSettings = base.model.settings.taaSettings;
            if (this.m_ResetHistory || this.m_HistoryTexture == null || this.m_HistoryTexture.width != source.width || this.m_HistoryTexture.height != source.height)
            {
                if (this.m_HistoryTexture)
                {
                    RenderTexture.ReleaseTemporary(this.m_HistoryTexture);
                }
                this.m_HistoryTexture      = RenderTexture.GetTemporary(source.width, source.height, 0, source.format);
                this.m_HistoryTexture.name = "TAA History";
                Graphics.Blit(source, this.m_HistoryTexture, material, 2);
            }
            material.SetVector(TaaComponent.Uniforms._SharpenParameters, new Vector4(taaSettings.sharpen, 0f, 0f, 0f));
            material.SetVector(TaaComponent.Uniforms._FinalBlendParameters, new Vector4(taaSettings.stationaryBlending, taaSettings.motionBlending, 6000f, 0f));
            material.SetTexture(TaaComponent.Uniforms._MainTex, source);
            material.SetTexture(TaaComponent.Uniforms._HistoryTex, this.m_HistoryTexture);
            RenderTexture temporary = RenderTexture.GetTemporary(source.width, source.height, 0, source.format);

            temporary.name = "TAA History";
            this.m_MRT[0]  = destination.colorBuffer;
            this.m_MRT[1]  = temporary.colorBuffer;
            Graphics.SetRenderTarget(this.m_MRT, source.depthBuffer);
            GraphicsUtils.Blit(material, (!this.context.camera.orthographic) ? 0 : 1);
            RenderTexture.ReleaseTemporary(this.m_HistoryTexture);
            this.m_HistoryTexture = temporary;
            this.m_ResetHistory   = false;
        }
        public void Render(RenderTexture source, RenderTexture destination)
        {
            var material = context.materialFactory.Get(k_ShaderString);

            material.shaderKeywords = null;

            var settings = model.settings.taaSettings;

            if (m_ResetHistory || m_HistoryTexture == null || m_HistoryTexture.width != source.width ||
                m_HistoryTexture.height != source.height)
            {
                if (m_HistoryTexture)
                {
                    RenderTexture.ReleaseTemporary(m_HistoryTexture);
                }

                m_HistoryTexture      = RenderTexture.GetTemporary(source.width, source.height, 0, source.format);
                m_HistoryTexture.name = "TAA History";

                Graphics.Blit(source, m_HistoryTexture, material, 2);
            }

            const float kMotionAmplification = 100f * 60f;

            material.SetVector(Uniforms._SharpenParameters, new Vector4(settings.sharpen, 0f, 0f, 0f));
            material.SetVector(Uniforms._FinalBlendParameters,
                               new Vector4(settings.stationaryBlending, settings.motionBlending, kMotionAmplification, 0f));
            material.SetTexture(Uniforms._MainTex, source);
            material.SetTexture(Uniforms._HistoryTex, m_HistoryTexture);

            var tempHistory = RenderTexture.GetTemporary(source.width, source.height, 0, source.format);

            tempHistory.name = "TAA History";

            m_MRT[0] = destination.colorBuffer;
            m_MRT[1] = tempHistory.colorBuffer;

            Graphics.SetRenderTarget(m_MRT, source.depthBuffer);
            GraphicsUtils.Blit(material, context.camera.orthographic ? 1 : 0);

            RenderTexture.ReleaseTemporary(m_HistoryTexture);
            m_HistoryTexture = tempHistory;

            m_ResetHistory = false;
        }
예제 #3
0
        // Token: 0x06003AF9 RID: 15097 RVA: 0x001C8630 File Offset: 0x001C6A30
        public void Prepare(RenderTexture source, Material uberMaterial, bool antialiasCoC)
        {
            DepthOfFieldModel.Settings settings = base.model.settings;
            Material material = this.context.materialFactory.Get("Hidden/Post FX/Depth Of Field");

            material.shaderKeywords = null;
            float num  = settings.focusDistance;
            float num2 = this.CalculateFocalLength();

            num = Mathf.Max(num, num2);
            material.SetFloat(DepthOfFieldComponent.Uniforms._Distance, num);
            float num3 = num2 * num2 / (settings.aperture * (num - num2) * 0.024f * 2f);

            material.SetFloat(DepthOfFieldComponent.Uniforms._LensCoeff, num3);
            float num4 = this.CalculateMaxCoCRadius(source.height);

            material.SetFloat(DepthOfFieldComponent.Uniforms._MaxCoC, num4);
            material.SetFloat(DepthOfFieldComponent.Uniforms._RcpMaxCoC, 1f / num4);
            float value = (float)source.height / (float)source.width;

            material.SetFloat(DepthOfFieldComponent.Uniforms._RcpAspect, value);
            RenderTexture renderTexture = this.context.renderTextureFactory.Get(this.context.width / 2, this.context.height / 2, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Default, FilterMode.Bilinear, TextureWrapMode.Clamp, "FactoryTempTexture");

            source.filterMode = FilterMode.Point;
            Graphics.Blit(source, renderTexture, material, 0);
            RenderTexture renderTexture2 = renderTexture;

            if (antialiasCoC)
            {
                renderTexture2 = this.context.renderTextureFactory.Get(this.context.width / 2, this.context.height / 2, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Default, FilterMode.Bilinear, TextureWrapMode.Clamp, "FactoryTempTexture");
                if (this.m_CoCHistory == null || !this.m_CoCHistory.IsCreated() || this.m_CoCHistory.width != this.context.width / 2 || this.m_CoCHistory.height != this.context.height / 2)
                {
                    this.m_CoCHistory            = RenderTexture.GetTemporary(this.context.width / 2, this.context.height / 2, 0, RenderTextureFormat.RHalf);
                    this.m_CoCHistory.filterMode = FilterMode.Point;
                    this.m_CoCHistory.name       = "CoC History";
                    Graphics.Blit(renderTexture, this.m_CoCHistory, material, 6);
                }
                RenderTexture temporary = RenderTexture.GetTemporary(this.context.width / 2, this.context.height / 2, 0, RenderTextureFormat.RHalf);
                temporary.filterMode = FilterMode.Point;
                temporary.name       = "CoC History";
                this.m_MRT[0]        = renderTexture2.colorBuffer;
                this.m_MRT[1]        = temporary.colorBuffer;
                material.SetTexture(DepthOfFieldComponent.Uniforms._MainTex, renderTexture);
                material.SetTexture(DepthOfFieldComponent.Uniforms._HistoryCoC, this.m_CoCHistory);
                Graphics.SetRenderTarget(this.m_MRT, renderTexture.depthBuffer);
                GraphicsUtils.Blit(material, 5);
                RenderTexture.ReleaseTemporary(this.m_CoCHistory);
                this.m_CoCHistory = temporary;
            }
            RenderTexture renderTexture3 = this.context.renderTextureFactory.Get(this.context.width / 2, this.context.height / 2, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Default, FilterMode.Bilinear, TextureWrapMode.Clamp, "FactoryTempTexture");

            Graphics.Blit(renderTexture2, renderTexture3, material, (int)(1 + settings.kernelSize));
            if (this.context.profile.debugViews.IsModeActive(BuiltinDebugViewsModel.Mode.FocusPlane))
            {
                uberMaterial.SetTexture(DepthOfFieldComponent.Uniforms._DepthOfFieldTex, renderTexture);
                uberMaterial.SetVector(DepthOfFieldComponent.Uniforms._DepthOfFieldParams, new Vector2(num, num3));
                uberMaterial.EnableKeyword("DEPTH_OF_FIELD_COC_VIEW");
                this.context.Interrupt();
            }
            else
            {
                uberMaterial.SetTexture(DepthOfFieldComponent.Uniforms._DepthOfFieldTex, renderTexture3);
                uberMaterial.EnableKeyword("DEPTH_OF_FIELD");
            }
            if (antialiasCoC)
            {
                this.context.renderTextureFactory.Release(renderTexture2);
            }
            this.context.renderTextureFactory.Release(renderTexture);
            source.filterMode = FilterMode.Bilinear;
        }
        public void Prepare(RenderTexture source, Material uberMaterial, bool antialiasCoC)
        {
            if (target == null)
            {
                target = GameObject.FindGameObjectWithTag("Target").transform;
            }


            var settings = model.settings;

            // Material setup
            var material = context.materialFactory.Get(k_ShaderString);

            material.shaderKeywords = null;

            var s1 = Vector3.Distance(Camera.main.transform.position, target.position);//settings.focusDistance;
            var f  = CalculateFocalLength();

            s1 = Mathf.Max(s1, f);
            material.SetFloat(Uniforms._Distance, s1);

            Debug.Log(s1);

            var coeff = f * f / (settings.aperture * (s1 - f) * k_FilmHeight * 2);

            material.SetFloat(Uniforms._LensCoeff, coeff);

            var maxCoC = CalculateMaxCoCRadius(source.height);

            material.SetFloat(Uniforms._MaxCoC, maxCoC);
            material.SetFloat(Uniforms._RcpMaxCoC, 1f / maxCoC);

            var rcpAspect = (float)source.height / source.width;

            material.SetFloat(Uniforms._RcpAspect, rcpAspect);

            var rt1 = context.renderTextureFactory.Get(context.width / 2, context.height / 2, 0, RenderTextureFormat.ARGBHalf);

            source.filterMode = FilterMode.Point;

            // Pass #1 - Downsampling, prefiltering and CoC calculation
            if (!antialiasCoC)
            {
                Graphics.Blit(source, rt1, material, 0);
            }
            else
            {
                var initial = m_CoCHistory == null || !m_CoCHistory.IsCreated() || m_CoCHistory.width != context.width / 2 || m_CoCHistory.height != context.height / 2;

                var tempCoCHistory = RenderTexture.GetTemporary(context.width / 2, context.height / 2, 0, RenderTextureFormat.RHalf);
                tempCoCHistory.filterMode = FilterMode.Point;
                tempCoCHistory.name       = "CoC History";

                m_MRT[0] = rt1.colorBuffer;
                m_MRT[1] = tempCoCHistory.colorBuffer;
                material.SetTexture(Uniforms._MainTex, source);
                material.SetTexture(Uniforms._HistoryCoC, m_CoCHistory);
                material.SetFloat(Uniforms._HistoryWeight, initial ? 0 : 0.5f);
                Graphics.SetRenderTarget(m_MRT, rt1.depthBuffer);
                GraphicsUtils.Blit(material, 1);

                RenderTexture.ReleaseTemporary(m_CoCHistory);
                m_CoCHistory = tempCoCHistory;
            }

            // Pass #2 - Bokeh simulation
            var rt2 = context.renderTextureFactory.Get(context.width / 2, context.height / 2, 0, RenderTextureFormat.ARGBHalf);

            Graphics.Blit(rt1, rt2, material, 2 + (int)settings.kernelSize);

            // Pass #3 - Postfilter blur
            Graphics.Blit(rt2, rt1, material, 6);

            if (context.profile.debugViews.IsModeActive(DebugMode.FocusPlane))
            {
                uberMaterial.SetVector(Uniforms._DepthOfFieldParams, new Vector2(s1, coeff));
                uberMaterial.EnableKeyword("DEPTH_OF_FIELD_COC_VIEW");
                context.Interrupt();
            }
            else
            {
                uberMaterial.SetTexture(Uniforms._DepthOfFieldTex, rt1);
                uberMaterial.EnableKeyword("DEPTH_OF_FIELD");
            }

            context.renderTextureFactory.Release(rt2);
            source.filterMode = FilterMode.Bilinear;
        }
        public void Prepare(RenderTexture source, Material uberMaterial, bool antialiasCoC)
        {
            var settings = model.settings;

            // Material setup
            var material = context.materialFactory.Get(k_ShaderString);

            material.shaderKeywords = null;

            var s1 = settings.focusDistance;
            var f  = CalculateFocalLength();

            s1 = Mathf.Max(s1, f);
            material.SetFloat(Uniforms._Distance, s1);

            var coeff = f * f / (settings.aperture * (s1 - f) * k_FilmHeight * 2);

            material.SetFloat(Uniforms._LensCoeff, coeff);

            var maxCoC = CalculateMaxCoCRadius(source.height);

            material.SetFloat(Uniforms._MaxCoC, maxCoC);
            material.SetFloat(Uniforms._RcpMaxCoC, 1f / maxCoC);

            var rcpAspect = (float)source.height / source.width;

            material.SetFloat(Uniforms._RcpAspect, rcpAspect);

            var rt1 = context.renderTextureFactory.Get(context.width / 2, context.height / 2, 0, RenderTextureFormat.ARGBHalf);

            source.filterMode = FilterMode.Point;

            // Pass #1 - Downsampling, prefiltering and CoC calculation
            Graphics.Blit(source, rt1, material, 0);

            // Pass #2 - CoC Antialiasing
            var pass = rt1;

            if (antialiasCoC)
            {
                pass = context.renderTextureFactory.Get(context.width / 2, context.height / 2, 0, RenderTextureFormat.ARGBHalf);

                if (m_CoCHistory == null || !m_CoCHistory.IsCreated() || m_CoCHistory.width != context.width / 2 || m_CoCHistory.height != context.height / 2)
                {
                    m_CoCHistory            = RenderTexture.GetTemporary(context.width / 2, context.height / 2, 0, RenderTextureFormat.RHalf);
                    m_CoCHistory.filterMode = FilterMode.Point;
                    m_CoCHistory.name       = "CoC History";
                    Graphics.Blit(rt1, m_CoCHistory, material, 6);
                }

                var tempCoCHistory = RenderTexture.GetTemporary(context.width / 2, context.height / 2, 0, RenderTextureFormat.RHalf);
                tempCoCHistory.filterMode = FilterMode.Point;
                tempCoCHistory.name       = "CoC History";

                m_MRT[0] = pass.colorBuffer;
                m_MRT[1] = tempCoCHistory.colorBuffer;
                material.SetTexture(Uniforms._MainTex, rt1);
                material.SetTexture(Uniforms._HistoryCoC, m_CoCHistory);
                Graphics.SetRenderTarget(m_MRT, rt1.depthBuffer);
                GraphicsUtils.Blit(material, 5);

                RenderTexture.ReleaseTemporary(m_CoCHistory);
                m_CoCHistory = tempCoCHistory;
            }

            // Pass #3 - Bokeh simulation
            var rt2 = context.renderTextureFactory.Get(context.width / 2, context.height / 2, 0, RenderTextureFormat.ARGBHalf);

            Graphics.Blit(pass, rt2, material, 1 + (int)settings.kernelSize);

            if (context.profile.debugViews.IsModeActive(DebugMode.FocusPlane))
            {
                uberMaterial.SetTexture(Uniforms._DepthOfFieldTex, rt1);
                uberMaterial.SetFloat(Uniforms._MaxCoC, maxCoC);
                uberMaterial.EnableKeyword("DEPTH_OF_FIELD_COC_VIEW");
                context.Interrupt();
            }
            else
            {
                uberMaterial.SetTexture(Uniforms._DepthOfFieldTex, rt2);
                uberMaterial.EnableKeyword("DEPTH_OF_FIELD");
            }

            if (antialiasCoC)
            {
                context.renderTextureFactory.Release(pass);
            }

            context.renderTextureFactory.Release(rt1);
            source.filterMode = FilterMode.Bilinear;
        }