Ejemplo n.º 1
0
        void OnRenderImage(RenderTexture source, RenderTexture destination)
        {
            if (CMainMaterial)
            {
                // 申请两块降低了分辨率的RT
                RenderTexture rt1 = RenderTexture.GetTemporary(source.width >> down_sample_factor, source.height >> down_sample_factor, 0, source.format);
                RenderTexture rt2 = RenderTexture.GetTemporary(source.width >> down_sample_factor, source.height >> down_sample_factor, 0, source.format);
                Graphics.Blit(source, rt1);

                // 使用降低分辨率的rt进行模糊:pass0
                CMainMaterial.SetFloat("_BlurFactor", blur_factor);
                CMainMaterial.SetVector("_BlurCenter", blur_center);
                Graphics.Blit(rt1, rt2, CMainMaterial, 0);

                // 使用rt2和原始图像lerp:pass1
                CMainMaterial.SetTexture("_BlurTex", rt2);
                CMainMaterial.SetFloat("_LerpFactor", lerp_factor);
                Graphics.Blit(source, destination, CMainMaterial, 1);

                // 释放RT
                RenderTexture.ReleaseTemporary(rt1);
                RenderTexture.ReleaseTemporary(rt2);
            }
            else
            {
                Graphics.Blit(source, destination);
            }
        }
Ejemplo n.º 2
0
        void OnRenderImage(RenderTexture source, RenderTexture destination)
        {
            if (CMainMaterial)
            {
                //申请RenderTexture,RT的分辨率按照downSample降低
                RenderTexture rt1 = RenderTexture.GetTemporary(source.width >> downSample, source.height >> downSample, 0, source.format);
                RenderTexture rt2 = RenderTexture.GetTemporary(source.width >> downSample, source.height >> downSample, 0, source.format);

                //直接将原图拷贝到降分辨率的RT上
                Graphics.Blit(source, rt1);

                //进行迭代高斯模糊
                for (int i = 0; i < iteration; i++)
                {
                    //第一次高斯模糊,设置offsets,竖向模糊
                    CMainMaterial.SetVector("_offsets", new Vector4(0, BlurRadius, 0, 0));
                    Graphics.Blit(rt1, rt2, CMainMaterial);
                    //第二次高斯模糊,设置offsets,横向模糊
                    CMainMaterial.SetVector("_offsets", new Vector4(BlurRadius, 0, 0, 0));
                    Graphics.Blit(rt2, rt1, CMainMaterial);
                }

                //将结果输出
                Graphics.Blit(rt1, destination);

                //释放申请的两块RenderBuffer内容
                RenderTexture.ReleaseTemporary(rt1);
                RenderTexture.ReleaseTemporary(rt2);
            }
        }
Ejemplo n.º 3
0
 void OnRenderImage(RenderTexture source, RenderTexture destination)
 {
     if (CMainMaterial)
     {
         CMainMaterial.SetFloat("_BlurFactor", blur_factor);
         CMainMaterial.SetVector("_BlurCenter", blur_center);
         Graphics.Blit(source, destination, CMainMaterial);
     }
     else
     {
         Graphics.Blit(source, destination);
     }
 }