// Token: 0x06003AC2 RID: 15042 RVA: 0x001C67E0 File Offset: 0x001C4BE0
        public void Prepare(RenderTexture source, Material uberMaterial, Texture autoExposure)
        {
            BloomModel.BloomSettings    bloom    = base.model.settings.bloom;
            BloomModel.LensDirtSettings lensDirt = base.model.settings.lensDirt;
            Material material = this.context.materialFactory.Get("Hidden/Post FX/Bloom");

            material.shaderKeywords = null;
            if (autoExposure != null)
            {
                material.EnableKeyword("EYE_ADAPTATION");
                material.SetTexture(BloomComponent.Uniforms._AutoExposure, autoExposure);
            }
            int  width                 = this.context.width / 2;
            int  num                   = this.context.height / 2;
            bool isMobilePlatform      = Application.isMobilePlatform;
            RenderTextureFormat format = (!isMobilePlatform) ? RenderTextureFormat.DefaultHDR : RenderTextureFormat.Default;
            float num2                 = Mathf.Log((float)num, 2f) + bloom.radius - 8f;
            int   num3                 = (int)num2;
            int   num4                 = Mathf.Clamp(num3, 1, 16);
            float thresholdLinear      = bloom.thresholdLinear;

            material.SetFloat(BloomComponent.Uniforms._Threshold, thresholdLinear);
            float   num5 = thresholdLinear * bloom.softKnee + 1E-05f;
            Vector3 v    = new Vector3(thresholdLinear - num5, num5 * 2f, 0.25f / num5);

            material.SetVector(BloomComponent.Uniforms._Curve, v);
            material.SetFloat(BloomComponent.Uniforms._PrefilterOffs, (!bloom.antiFlicker) ? 0f : -0.5f);
            float num6 = 0.5f + num2 - (float)num3;

            material.SetFloat(BloomComponent.Uniforms._SampleScale, num6);
            if (bloom.antiFlicker)
            {
                material.EnableKeyword("ANTI_FLICKER");
            }
            RenderTexture renderTexture = this.context.renderTextureFactory.Get(width, num, 0, format, RenderTextureReadWrite.Default, FilterMode.Bilinear, TextureWrapMode.Clamp, "FactoryTempTexture");

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

            for (int i = 0; i < num4; i++)
            {
                this.m_BlurBuffer1[i] = this.context.renderTextureFactory.Get(renderTexture2.width / 2, renderTexture2.height / 2, 0, format, RenderTextureReadWrite.Default, FilterMode.Bilinear, TextureWrapMode.Clamp, "FactoryTempTexture");
                int pass = (i != 0) ? 2 : 1;
                Graphics.Blit(renderTexture2, this.m_BlurBuffer1[i], material, pass);
                renderTexture2 = this.m_BlurBuffer1[i];
            }
            for (int j = num4 - 2; j >= 0; j--)
            {
                RenderTexture renderTexture3 = this.m_BlurBuffer1[j];
                material.SetTexture(BloomComponent.Uniforms._BaseTex, renderTexture3);
                this.m_BlurBuffer2[j] = this.context.renderTextureFactory.Get(renderTexture3.width, renderTexture3.height, 0, format, RenderTextureReadWrite.Default, FilterMode.Bilinear, TextureWrapMode.Clamp, "FactoryTempTexture");
                Graphics.Blit(renderTexture2, this.m_BlurBuffer2[j], material, 3);
                renderTexture2 = this.m_BlurBuffer2[j];
            }
            RenderTexture renderTexture4 = renderTexture2;

            for (int k = 0; k < 16; k++)
            {
                if (this.m_BlurBuffer1[k] != null)
                {
                    this.context.renderTextureFactory.Release(this.m_BlurBuffer1[k]);
                }
                if (this.m_BlurBuffer2[k] != null && this.m_BlurBuffer2[k] != renderTexture4)
                {
                    this.context.renderTextureFactory.Release(this.m_BlurBuffer2[k]);
                }
                this.m_BlurBuffer1[k] = null;
                this.m_BlurBuffer2[k] = null;
            }
            this.context.renderTextureFactory.Release(renderTexture);
            uberMaterial.EnableKeyword("BLOOM");
            uberMaterial.SetTexture(BloomComponent.Uniforms._BloomTex, renderTexture4);
            uberMaterial.SetVector(BloomComponent.Uniforms._Bloom_Settings, new Vector2(num6, bloom.intensity));
            if (lensDirt.intensity > 0f && lensDirt.texture != null)
            {
                uberMaterial.SetTexture(BloomComponent.Uniforms._Bloom_DirtTex, lensDirt.texture);
                uberMaterial.SetFloat(BloomComponent.Uniforms._Bloom_DirtIntensity, lensDirt.intensity);
                uberMaterial.EnableKeyword("BLOOM_LENS_DIRT");
            }
        }
Beispiel #2
0
        public void Prepare(RenderTexture source, Material uberMaterial, Texture autoExposure)
        {
            BloomModel.BloomSettings    bloom    = base.model.settings.bloom;
            BloomModel.LensDirtSettings lensDirt = base.model.settings.lensDirt;
            Material mat = base.context.materialFactory.Get("Hidden/Post FX/Bloom");

            mat.shaderKeywords = null;
            mat.SetTexture(Uniforms._AutoExposure, autoExposure);
            int width  = base.context.width / 2;
            int height = base.context.height / 2;
            RenderTextureFormat format = !Application.isMobilePlatform ? RenderTextureFormat.DefaultHDR : RenderTextureFormat.Default;
            float num3            = (Mathf.Log((float)height, 2f) + bloom.radius) - 8f;
            int   num4            = (int)num3;
            int   num5            = Mathf.Clamp(num4, 1, 0x10);
            float thresholdLinear = bloom.thresholdLinear;

            mat.SetFloat(Uniforms._Threshold, thresholdLinear);
            float   num7   = (thresholdLinear * bloom.softKnee) + 1E-05f;
            Vector3 vector = new Vector3(thresholdLinear - num7, num7 * 2f, 0.25f / num7);

            mat.SetVector(Uniforms._Curve, vector);
            mat.SetFloat(Uniforms._PrefilterOffs, !bloom.antiFlicker ? 0f : -0.5f);
            float num8 = (0.5f + num3) - num4;

            mat.SetFloat(Uniforms._SampleScale, num8);
            if (bloom.antiFlicker)
            {
                mat.EnableKeyword("ANTI_FLICKER");
            }
            RenderTexture dest = base.context.renderTextureFactory.Get(width, height, 0, format, RenderTextureReadWrite.Default, FilterMode.Bilinear, TextureWrapMode.Clamp, "FactoryTempTexture");

            Graphics.Blit(source, dest, mat, 0);
            RenderTexture texture2 = dest;

            for (int i = 0; i < num5; i++)
            {
                this.m_BlurBuffer1[i] = base.context.renderTextureFactory.Get(texture2.width / 2, texture2.height / 2, 0, format, RenderTextureReadWrite.Default, FilterMode.Bilinear, TextureWrapMode.Clamp, "FactoryTempTexture");
                Graphics.Blit(texture2, this.m_BlurBuffer1[i], mat, (i != 0) ? 2 : 1);
                texture2 = this.m_BlurBuffer1[i];
            }
            for (int j = num5 - 2; j >= 0; j--)
            {
                RenderTexture texture3 = this.m_BlurBuffer1[j];
                mat.SetTexture(Uniforms._BaseTex, texture3);
                this.m_BlurBuffer2[j] = base.context.renderTextureFactory.Get(texture3.width, texture3.height, 0, format, RenderTextureReadWrite.Default, FilterMode.Bilinear, TextureWrapMode.Clamp, "FactoryTempTexture");
                Graphics.Blit(texture2, this.m_BlurBuffer2[j], mat, 3);
                texture2 = this.m_BlurBuffer2[j];
            }
            RenderTexture texture4 = texture2;

            for (int k = 0; k < 0x10; k++)
            {
                if (this.m_BlurBuffer1[k] != null)
                {
                    base.context.renderTextureFactory.Release(this.m_BlurBuffer1[k]);
                }
                if ((this.m_BlurBuffer2[k] != null) && (this.m_BlurBuffer2[k] != texture4))
                {
                    base.context.renderTextureFactory.Release(this.m_BlurBuffer2[k]);
                }
                this.m_BlurBuffer1[k] = null;
                this.m_BlurBuffer2[k] = null;
            }
            base.context.renderTextureFactory.Release(dest);
            uberMaterial.SetTexture(Uniforms._BloomTex, texture4);
            uberMaterial.SetVector(Uniforms._Bloom_Settings, new Vector2(num8, bloom.intensity));
            if ((lensDirt.intensity <= 0f) || (lensDirt.texture == null))
            {
                uberMaterial.EnableKeyword("BLOOM");
            }
            else
            {
                uberMaterial.SetTexture(Uniforms._Bloom_DirtTex, lensDirt.texture);
                uberMaterial.SetFloat(Uniforms._Bloom_DirtIntensity, lensDirt.intensity);
                uberMaterial.EnableKeyword("BLOOM_LENS_DIRT");
            }
        }