Exemplo n.º 1
0
        public override void Render(RenderContext context, GaussianBlur setting)
        {
            var cmd = context.m_command;

            cmd.BeginSample("GaussianBlur");
            //downsample
            float scale   = 1.0f / (1 << setting.m_down_ex);
            int   blurRT1 = RunTimeHelper.GetTemporaryRTID();

            context.GetScreenScaleTemporaryRT(blurRT1, scale);
            cmd.PostBlitFullScreen(context.m_source, blurRT1, setting.m_mat, (int)PassIndex.DS);

            int blurRT2 = RunTimeHelper.GetTemporaryRTID();

            context.GetScreenScaleTemporaryRT(blurRT2, scale);
            float blurScale = setting.m_blur_radius * scale;

            cmd.SetGlobalFloat(ID_BlurScaleValue, blurScale);

            for (int i = 0; i < setting.m_blur_times; ++i)
            {
                cmd.PostBlitFullScreen(blurRT1, blurRT2, setting.m_mat, (int)PassIndex.VBlur);
                cmd.PostBlitFullScreen(blurRT2, blurRT1, setting.m_mat, (int)PassIndex.HBlur);
            }

            cmd.PostBlitFullScreen(blurRT1, context.m_target);
            cmd.ReleaseTemporaryRT(blurRT1);
            cmd.ReleaseTemporaryRT(blurRT2);
            cmd.EndSample("GaussianBlur");
        }
Exemplo n.º 2
0
        private void RenderEffectPoint(EffectPoint effectPoint)
        {
            List <EffectBaseSettingWrap> list = null;

            if (m_activeEffectsDic.TryGetValue(effectPoint, out list) && list.Count > 0)
            {
                SetContextCommandBuffer(effectPoint);
                m_context.m_command.BeginSample(string.Format("PostProcess_{0}", effectPoint));
                var cameraTarget = new RenderTargetIdentifier(BuiltinRenderTextureType.CameraTarget);
                int tmpSRT       = -1;
                tmpSRT             = RunTimeHelper.GetTemporaryRTID();
                m_context.m_source = tmpSRT;
                m_context.GetFullscreenTemporaryRT(tmpSRT, RenderTextureFormat.Default, FilterMode.Bilinear);
                //拷贝屏幕到source
                m_context.m_command.PostBlit(cameraTarget, tmpSRT);

                int tmpTRT = -1;
                if (list.Count > 1)
                {
                    tmpTRT             = RunTimeHelper.GetTemporaryRTID();
                    m_context.m_target = tmpTRT;
                    m_context.GetFullscreenTemporaryRT(tmpTRT, RenderTextureFormat.ARGB32, FilterMode.Bilinear);
                }
                else
                {
                    m_context.m_target = cameraTarget;
                }

                for (int i = 0; i < list.Count; ++i)
                {
                    var setting = list[i];
                    if (m_activeRendererDic.ContainsKey(setting.m_rendererType))
                    {
                        m_activeRendererDic[setting.m_rendererType].BaseRender(m_context, setting.m_setting);
                    }

                    //switch
                    if (i < list.Count - 1)
                    {
                        var tmp = m_context.m_target;
                        m_context.m_target = m_context.m_source;
                        m_context.m_source = tmp;
                    }
                }

                if (tmpSRT > -1)
                {
                    m_context.m_command.ReleaseTemporaryRT(tmpSRT);
                }

                if (tmpTRT > -1)
                {
                    m_context.m_command.ReleaseTemporaryRT(tmpTRT);
                }

                m_context.m_command.EndSample(string.Format("PostProcess_{0}", effectPoint));
            }
        }
Exemplo n.º 3
0
        public override void Render(RenderContext context, Bloom setting)
        {
            var cmd = context.m_command;

            cmd.BeginSample("Bloom");
            cmd.SetGlobalFloat(ID_Threthold, setting.m_threthold);
            int w;
            int h;


            int lastRes = -1;
            int temp1   = RunTimeHelper.GetTemporaryRTID();
            int temp2   = RunTimeHelper.GetTemporaryRTID();

            for (int i = 4; i > 1; i--)
            {
                int scale = 1 << i;
                w = context.m_width >> i;
                h = context.m_height >> i;
                context.GetFullscreenTemporaryRT(temp1, RenderTextureFormat.Default, FilterMode.Bilinear, RenderTextureReadWrite.Default, 0, w, h);
                context.GetFullscreenTemporaryRT(temp2, RenderTextureFormat.Default, FilterMode.Bilinear, RenderTextureReadWrite.Default, 0, w, h);
                cmd.PostBlitFullScreen(context.m_source, temp1, setting.m_mat, (int)EBloomPass.DSample);

                cmd.SetGlobalFloat(ID_BlurScaleValue, setting.m_blur_radius / scale);
                cmd.PostBlitFullScreen(temp1, temp2, setting.m_mat, (int)EBloomPass.VBlur);
                cmd.PostBlitFullScreen(temp2, temp1, setting.m_mat, (int)EBloomPass.HBlur);

                if (lastRes > 0)
                {
                    cmd.SetGlobalTexture(ID_BloomBlur, temp1);
                    cmd.PostBlitFullScreen(lastRes, temp2, setting.m_mat, (int)EBloomPass.Combined);
                    cmd.ReleaseTemporaryRT(temp1);
                    cmd.ReleaseTemporaryRT(lastRes);
                    lastRes = temp2;
                }
                else
                {
                    cmd.ReleaseTemporaryRT(temp2);
                    lastRes = temp1;
                }
            }


            cmd.SetGlobalFloat(ID_Strength, setting.m_Strength);
            cmd.SetGlobalTexture(ID_BloomBlur, lastRes);
            cmd.PostBlitFullScreen(context.m_source, context.m_target, setting.m_mat, (int)EBloomPass.BloomCombined);
            cmd.ReleaseTemporaryRT(lastRes);
            cmd.EndSample("Bloom");
        }