Example #1
0
        public override void Render(CommandBuffer cmd, ref RenderingData renderingData, PostProcessingRenderContext context)
        {
            if (!_shader)
            {
                return;
            }
            if (_material == null)
            {
                _material = new Material(_shader);
            }
            this.UpdateMaterialProperties();
            var projMatrix = renderingData.cameraData.GetGPUProjectionMatrix();

            _material.SetMatrix("CustomProjMatrix", projMatrix);
            _material.SetMatrix("CustomInvProjMatrix", projMatrix.inverse);
            if (_blur)
            {
                _material.EnableKeyword("_Blur");
            }
            else
            {
                _material.DisableKeyword("_Blur");
            }
            if (_blur)
            {
                var temp1 = context.GetTemporaryRT(cmd);
                var temp2 = context.GetTemporaryRT(cmd);
                _blitter.Prepare(temp1, temp2);
                //first pass, calculate AO
                _blitter.BlitAndSwap(cmd, _material, 0);

                //second pass, blur horizantal
                _blitter.BlitAndSwap(cmd, _material, 1);

                //third pass, blur vertical
                _blitter.BlitAndSwap(cmd, _material, 2);

                cmd.SetGlobalTexture("_AOTex", _blitter.pingRT);

                context.BlitAndSwap(cmd, _material, 3);

                context.ReleaseTemporaryRT(cmd, temp1);
                context.ReleaseTemporaryRT(cmd, temp2);
            }
            else
            {
                context.BlitAndSwap(cmd, _material);
            }
        }
Example #2
0
        public override void Render(CommandBuffer cmd, ref RenderingData renderingData, PostProcessingRenderContext context)
        {
            if (!_shader)
            {
                return;
            }
            if (!_material)
            {
                _material = new Material(_shader);
            }

            if (_debug)
            {
                _material.EnableKeyword("_BloomDebug");
            }
            else
            {
                _material.DisableKeyword("_BloomDebug");
            }

            _material.SetFloat("_Threshold", _threshold);

            var descriptor = context.sourceRenderTextureDescriptor;

            var temp1 = context.GetTemporaryRT(cmd, descriptor, FilterMode.Bilinear);

            //first pass,提取光亮部分
            cmd.Blit(context.activeRenderTarget, temp1, _material, 0);

            //模糊处理
            _blurBlitter.SetSource(temp1, descriptor);

            _blurBlitter.downSample    = downSample;
            _blurBlitter.iteratorCount = _blurIteratorCount;
            _blurBlitter.blurType      = BlurType.Box;

            _blurBlitter.Render(cmd);

            cmd.SetGlobalTexture("_BloomTex", temp1);

            //combine
            context.BlitAndSwap(cmd, _material, 3);

            context.ReleaseTemporaryRT(cmd, temp1);
        }