Ejemplo n.º 1
0
    public override void Render(PostProcessRenderContext context)
    {
        CommandBuffer cmd = context.command;

        // Create our temp working buffers, work at quarter size
        context.GetScreenSpaceTemporaryRT(cmd, m_BlurTemp1, 0, context.sourceFormat,
                                          RenderTextureReadWrite.Default, FilterMode.Bilinear, context.width / 2, context.height / 2);
        context.GetScreenSpaceTemporaryRT(cmd, m_BlurTemp2, 0, context.sourceFormat,
                                          RenderTextureReadWrite.Default, FilterMode.Bilinear, context.width / 2, context.height / 2);

        // Copy all values about our brightness and inside our mask to a temp buffer
        m_MaskedBrightnessBlit.SetFloat("_BloomThreshold", settings.bloomThreshold);
        cmd.Blit(context.source, m_BlurTemp1, m_MaskedBrightnessBlit);

        // Setup command for blurring the buffer
        m_Blur.SetupCommandBuffer(cmd, m_BlurTemp1, m_BlurTemp2);

        // Blit the blurred brightness back into the color buffer, optionally increasing the brightness
        m_AdditiveBlit.SetFloat("_AdditiveAmount", settings.bloomAmount);
        cmd.Blit(m_BlurTemp1, context.source, m_AdditiveBlit);

        // Blit to the destination buffer
        cmd.BlitFullscreenTriangle(context.source, context.destination);

        // Cleanup
        cmd.ReleaseTemporaryRT(m_BlurTemp1);
        cmd.ReleaseTemporaryRT(m_BlurTemp2);
    }
Ejemplo n.º 2
0
    public override void Execute(ScriptableRenderer renderer, ScriptableRenderContext context, ref RenderingData renderingData)
    {
        CommandBuffer cmd = CommandBufferPool.Get(k_RenderGrabPassTag);

        using (new ProfilingSample(cmd, k_RenderGrabPassTag))
        {
            // copy screen into temporary RT
            int screenCopyID = Shader.PropertyToID("_ScreenCopyTexture");
            RenderTextureDescriptor opaqueDesc = ScriptableRenderer.CreateRenderTextureDescriptor(ref renderingData.cameraData);
            cmd.GetTemporaryRT(screenCopyID, opaqueDesc, FilterMode.Bilinear);
            cmd.Blit(m_ColorHandle.Identifier(), screenCopyID);

            // get two smaller RTs
            cmd.GetTemporaryRT(m_BlurTemp1, opaqueDesc, FilterMode.Bilinear);
            cmd.GetTemporaryRT(m_BlurTemp2, opaqueDesc, FilterMode.Bilinear);

            // downsample screen copy into smaller RT, release screen RT
            cmd.Blit(screenCopyID, m_BlurTemp1);
            cmd.ReleaseTemporaryRT(screenCopyID);

            opaqueDesc.width  /= 2;
            opaqueDesc.height /= 2;

            // Setup blur commands
            m_Blur.SetupCommandBuffer(cmd, m_BlurTemp1, m_BlurTemp2);

            // Set texture id so we can use it later
            cmd.SetGlobalTexture("_GrabBlurTexture", m_BlurTemp1);
        }

        context.ExecuteCommandBuffer(cmd);
        CommandBufferPool.Release(cmd);
    }
Ejemplo n.º 3
0
        // Here you can implement the rendering logic.
        // Use <c>ScriptableRenderContext</c> to issue drawing commands or execute command buffers
        // https://docs.unity3d.com/ScriptReference/Rendering.ScriptableRenderContext.html
        // You don't have to call ScriptableRenderContext.submit, the render pipeline will call it at specific points in the pipeline.
        public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
        {
            CommandBuffer cmd = CommandBufferPool.Get("Bloom Pass");

            RenderTextureDescriptor opaqueDescriptor = renderingData.cameraData.cameraTargetDescriptor;

            opaqueDescriptor.depthBufferBits = 0;
            opaqueDescriptor.height          = opaqueDescriptor.height / 2;
            opaqueDescriptor.width           = opaqueDescriptor.width / 2;

            // Create our temp working buffers, work at quarter size
            cmd.GetTemporaryRT(m_BlurTemp1, opaqueDescriptor, FilterMode.Bilinear);
            cmd.GetTemporaryRT(m_BlurTemp2, opaqueDescriptor, FilterMode.Bilinear);

            // Copy all values about our brightness and inside our mask to a temp buffer
            m_MaskedBrightnessBlit.SetFloat("_BloomThreshold", settings.bloomThreshold);
            Blit(cmd, source, m_BlurTemp1, m_MaskedBrightnessBlit);

            // Setup command for blurring the buffer
            m_Blur.SetupCommandBuffer(cmd, m_BlurTemp1, m_BlurTemp2);

            // Blit the blurred brightness back into the color buffer, optionally increasing the brightness
            m_AdditiveBlit.SetFloat("_AdditiveAmount", settings.bloomAmount);
            Blit(cmd, m_BlurTemp1, source, m_AdditiveBlit);

            // Blit to the destination buffer
            //BlitFullscreenTriangle(context.source, context.destination);
            //Blit(cmd, source, destination.id);

            /*if (destination == RenderTargetHandle.CameraTarget)
             * {
             *  cmd.GetTemporaryRT(temporaryColorTexture.id, opaqueDescriptor, FilterMode.Point);
             *  Blit(cmd, source, temporaryColorTexture.Identifier(), m_MaskedBrightnessBlit, 0);
             *  Blit(cmd, temporaryColorTexture.Identifier(), source);
             *
             * }
             * else Blit(cmd, source, destination.Identifier(), m_MaskedBrightnessBlit, 0);*/


            context.ExecuteCommandBuffer(cmd);
            CommandBufferPool.Release(cmd);
        }
Ejemplo n.º 4
0
    public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
    {
        CommandBuffer cmd = CommandBufferPool.Get(k_RenderGrabPassTag);

        using (new ProfilingSample(cmd, k_RenderGrabPassTag))
        {
            // copy screen into temporary RT
            Blit(cmd, m_ColorSource, m_ScreenCopyId.Identifier());

            // downsample screen copy into smaller RTs
            Blit(cmd, m_ScreenCopyId.Identifier(), m_BlurTemp1.Identifier());

            // Setup blur commands
            m_Blur.SetupCommandBuffer(cmd, m_BlurTemp1.id, m_BlurTemp2.id);

            // Set texture id so we can use it later
            cmd.SetGlobalTexture("_GrabBlurTexture", m_BlurTemp1.id);
        }

        context.ExecuteCommandBuffer(cmd);
        CommandBufferPool.Release(cmd);
    }