コード例 #1
0
 private void AddBokeh(RenderTexture bokehInfo, RenderTexture tempTex, RenderTexture finalTarget)
 {
     if (this.bokehMaterial)
     {
         Mesh[] meshes = Quads.GetMeshes(tempTex.width, tempTex.height);
         RenderTexture.active = tempTex;
         GL.Clear(false, true, new Color(0f, 0f, 0f, 0f));
         GL.PushMatrix();
         GL.LoadIdentity();
         bokehInfo.filterMode = FilterMode.Point;
         float num  = (float)bokehInfo.width * 1f / ((float)bokehInfo.height * 1f);
         float num2 = 2f / (1f * (float)bokehInfo.width);
         num2 += this.bokehScale * this.maxBlurSpread * DepthOfFieldDeprecated.BOKEH_EXTRA_BLUR * this.oneOverBaseSize;
         this.bokehMaterial.SetTexture("_Source", bokehInfo);
         this.bokehMaterial.SetTexture("_MainTex", this.bokehTexture);
         this.bokehMaterial.SetVector("_ArScale", new Vector4(num2, num2 * num, 0.5f, 0.5f * num));
         this.bokehMaterial.SetFloat("_Intensity", this.bokehIntensity);
         this.bokehMaterial.SetPass(0);
         foreach (Mesh mesh in meshes)
         {
             if (mesh)
             {
                 Graphics.DrawMeshNow(mesh, Matrix4x4.identity);
             }
         }
         GL.PopMatrix();
         Graphics.Blit(tempTex, finalTarget, this.dofMaterial, 8);
         bokehInfo.filterMode = FilterMode.Bilinear;
     }
 }
コード例 #2
0
 public static Mesh[] GetMeshes(int totalWidth, int totalHeight)
 {
     Mesh[] result;
     if (Quads.HasMeshes() && Quads.currentQuads == totalWidth * totalHeight)
     {
         result = Quads.meshes;
     }
     else
     {
         int num  = 10833;
         int num2 = totalWidth * totalHeight;
         Quads.currentQuads = num2;
         int num3 = Mathf.CeilToInt(1f * (float)num2 / (1f * (float)num));
         Quads.meshes = new Mesh[num3];
         int num4 = 0;
         for (int i = 0; i < num2; i += num)
         {
             int triCount = Mathf.FloorToInt((float)Mathf.Clamp(num2 - i, 0, num));
             Quads.meshes[num4] = Quads.GetMesh(triCount, i, totalWidth, totalHeight);
             num4++;
         }
         result = Quads.meshes;
     }
     return(result);
 }
コード例 #3
0
        public void RestoreCamera()
        {
            Quads.Cleanup();

            if (_camera != null)
            {
                _camera.depthTextureMode = DepthTextureMode.None;
            }
        }
コード例 #4
0
        void AddBokeh(RenderTexture bokehInfo, RenderTexture tempTex, RenderTexture finalTarget)
        {
            if (bokehMaterial)
            {
                var meshes = Quads.GetMeshes(tempTex.width, tempTex.height);    // quads: exchanging more triangles with less overdraw

                RenderTexture.active = tempTex;
                GL.Clear(false, true, new Color(0.0f, 0.0f, 0.0f, 0.0f));

                GL.PushMatrix();
                GL.LoadIdentity();

                // point filter mode is important, otherwise we get bokeh shape & size artefacts
                bokehInfo.filterMode = FilterMode.Point;

                float arW = (bokehInfo.width * 1.0f) / (bokehInfo.height * 1.0f);
                float sc  = 2.0f / (1.0f * bokehInfo.width);
                sc += bokehScale * maxBlurSpread * BOKEH_EXTRA_BLUR * oneOverBaseSize;

                bokehMaterial.SetTexture("_Source", bokehInfo);
                bokehMaterial.SetTexture("_MainTex", bokehTexture);
                bokehMaterial.SetVector("_ArScale", new Vector4(sc, sc * arW, 0.5f, 0.5f * arW));
                bokehMaterial.SetFloat("_Intensity", bokehIntensity);
                bokehMaterial.SetPass(0);

                foreach (Mesh m in meshes)
                {
                    if (m)
                    {
                        Graphics.DrawMeshNow(m, Matrix4x4.identity);
                    }
                }

                GL.PopMatrix();

                Graphics.Blit(tempTex, finalTarget, dofMaterial, 8);

                // important to set back as we sample from this later on
                bokehInfo.filterMode = FilterMode.Bilinear;
            }
        }
コード例 #5
0
 private void AddBokeh(RenderTexture bokehInfo, RenderTexture tempTex, RenderTexture finalTarget)
 {
     if (this.bokehMaterial)
     {
         Mesh[] meshes = Quads.GetMeshes(tempTex.width, tempTex.height);
         RenderTexture.active = tempTex;
         GL.Clear(false, true, new Color(0f, 0f, 0f, 0f));
         GL.PushMatrix();
         GL.LoadIdentity();
         bokehInfo.filterMode = FilterMode.Point;
         float num = (bokehInfo.width * 1f) / (bokehInfo.height * 1f);
         float x = (2f / (1f * bokehInfo.width)) + (((this.bokehScale * this.maxBlurSpread) * BOKEH_EXTRA_BLUR) * this.oneOverBaseSize);
         this.bokehMaterial.SetTexture("_Source", bokehInfo);
         this.bokehMaterial.SetTexture("_MainTex", this.bokehTexture);
         this.bokehMaterial.SetVector("_ArScale", new Vector4(x, x * num, 0.5f, 0.5f * num));
         this.bokehMaterial.SetFloat("_Intensity", this.bokehIntensity);
         this.bokehMaterial.SetPass(0);
         Mesh[] meshArray2 = meshes;
         int index = 0;
         while (true)
         {
             if (index >= meshArray2.Length)
             {
                 GL.PopMatrix();
                 Graphics.Blit(tempTex, finalTarget, this.dofMaterial, 8);
                 bokehInfo.filterMode = FilterMode.Bilinear;
                 break;
             }
             Mesh mesh = meshArray2[index];
             if (mesh)
             {
                 Graphics.DrawMeshNow(mesh, Matrix4x4.identity);
             }
             index++;
         }
     }
 }
コード例 #6
0
 void OnDisable()
 {
     Quads.Cleanup();
 }
コード例 #7
0
 void OnDisable()
 {
     Quads.Cleanup();
     _camera.depthTextureMode = DepthTextureMode.None;
 }