/// <summary>
        /// Renders depth information to grayscale so it is more useful for debug.
        /// </summary>
        /// <param name="fullScreenQuad">FullScreenQuad class.</param>
        public void UpdateDepthDebugBuffer(FullScreenQuad fullScreenQuad)
        {
            // Clear render target
            SetViewport();

            // Create render target if it doesn't exist or is lost
            if (depthDebugBuffer == null)
            {
                CreateDepthDebugBuffer();
            }
            else if (depthDebugBuffer.IsContentLost)
            {
                CreateDepthDebugBuffer();
            }

            // Set render target
            graphicsDevice.SetRenderTarget(depthDebugBuffer);

            // Set render states
            graphicsDevice.BlendState        = BlendState.Opaque;
            graphicsDevice.DepthStencilState = DepthStencilState.None;

            // Set values
            drawDebugDepthBufferEffect.Parameters["DepthMap"].SetValue(depthRT);
            drawDebugDepthBufferEffect.Parameters["HalfPixel"].SetValue(halfPixel);

            // Apply changes and draw
            drawDebugDepthBufferEffect.Techniques[0].Passes[0].Apply();
            fullScreenQuad.Draw(graphicsDevice);
        }
 /// <summary>
 /// Clear GBuffer.
 /// </summary>
 /// <param name="clearBufferEffect">Effect to clear GBuffer with.</param>
 /// <param name="fullScreenQuad">FullScreenQuad class.</param>
 /// <param name="clearColor">Clear colour for diffuse buffer.</param>
 public void ClearGBuffer(Effect clearBufferEffect, FullScreenQuad fullScreenQuad, Color clearColor)
 {
     graphicsDevice.BlendState        = BlendState.Opaque;
     graphicsDevice.DepthStencilState = DepthStencilState.None;
     clearBufferEffect.Parameters["ClearColor"].SetValue(clearColor.ToVector3());
     clearBufferEffect.Techniques[0].Passes[0].Apply();
     fullScreenQuad.Draw(graphicsDevice);
 }
        /// <summary>
        /// Compose buffers into one layer.
        /// </summary>
        public void ComposeFinal(Effect finalCombineEffect, FullScreenQuad fullScreenQuad)
        {
            // Set render states
            graphicsDevice.BlendState        = BlendState.Opaque;
            graphicsDevice.RasterizerState   = RasterizerState.CullNone;
            graphicsDevice.DepthStencilState = DepthStencilState.None;

            // Set values
            finalCombineEffect.Parameters["ColorMap"].SetValue(colorRT);
            finalCombineEffect.Parameters["LightMap"].SetValue(lightRT);
            finalCombineEffect.Parameters["DepthMap"].SetValue(depthRT);
            finalCombineEffect.Parameters["HalfPixel"].SetValue(halfPixel);
            finalCombineEffect.Parameters["AmbientColor"].SetValue(ambientLightColor);

            // Apply changes and draw
            finalCombineEffect.Techniques[0].Passes[0].Apply();
            fullScreenQuad.Draw(graphicsDevice);
        }
示例#4
0
        /// <summary>
        /// Combines all render targets into back buffer for presentation.
        ///  Runs post-processing until a proper framework is written.
        /// </summary>
        private void ComposeFinal()
        {
            // No post-processing enabled, just compose into render target
            if (!fxaaEnabled && !bloomEnabled)
            {
                // Set render target
                graphicsDevice.SetRenderTarget(renderTarget);

                // Clear target
                graphicsDevice.Clear(clearColor);

                // Compose final image from GBuffer
                gBuffer.ComposeFinal(finalCombineEffect, fullScreenQuad);
            }

            // Only fxaa is enabled
            else if (fxaaEnabled && !bloomEnabled)
            {
                // Set render target
                graphicsDevice.SetRenderTarget(fxaaRenderTarget);

                // Clear target
                graphicsDevice.Clear(clearColor);

                // Compose final image from GBuffer
                gBuffer.ComposeFinal(finalCombineEffect, fullScreenQuad);

                // Set render target
                graphicsDevice.SetRenderTarget(renderTarget);

                // Clear target
                graphicsDevice.Clear(clearColor);

                // Set effect parameters
                fxaaAntialiasing.CurrentTechnique = fxaaAntialiasing.Techniques["ppfxaa"];
                fxaaAntialiasing.Parameters["SCREEN_WIDTH"].SetValue(fxaaRenderTarget.Width);
                fxaaAntialiasing.Parameters["SCREEN_HEIGHT"].SetValue(fxaaRenderTarget.Height);
                fxaaAntialiasing.Parameters["gScreenTexture"].SetValue(fxaaRenderTarget as Texture2D);

                // Set render states
                graphicsDevice.BlendState        = BlendState.AlphaBlend;
                graphicsDevice.SamplerStates[0]  = SamplerState.LinearClamp;
                graphicsDevice.DepthStencilState = DepthStencilState.None;

                // Draw FXAA
                fxaaAntialiasing.Techniques[0].Passes[0].Apply();
                fullScreenQuad.Draw(graphicsDevice);
            }

            // Only bloom is enabled
            else if (bloomEnabled && !fxaaEnabled)
            {
                // Set render target
                graphicsDevice.SetRenderTarget(bloomRenderTarget);

                // Clear target
                graphicsDevice.Clear(clearColor);

                // Compose final image from GBuffer
                gBuffer.ComposeFinal(finalCombineEffect, fullScreenQuad);

                // Draw bloom
                bloomProcessor.Draw(bloomRenderTarget, renderTarget);
            }

            // Both fxaa and bloom are enabled
            else if (fxaaEnabled && bloomEnabled)
            {
                // Set render target
                graphicsDevice.SetRenderTarget(fxaaRenderTarget);

                // Clear target
                graphicsDevice.Clear(clearColor);

                // Compose final image from GBuffer
                gBuffer.ComposeFinal(finalCombineEffect, fullScreenQuad);

                // Next render target
                graphicsDevice.SetRenderTarget(bloomRenderTarget);

                // Clear target
                graphicsDevice.Clear(clearColor);

                // Set effect parameters
                fxaaAntialiasing.CurrentTechnique = fxaaAntialiasing.Techniques["ppfxaa"];
                fxaaAntialiasing.Parameters["SCREEN_WIDTH"].SetValue(fxaaRenderTarget.Width);
                fxaaAntialiasing.Parameters["SCREEN_HEIGHT"].SetValue(fxaaRenderTarget.Height);
                fxaaAntialiasing.Parameters["gScreenTexture"].SetValue(fxaaRenderTarget as Texture2D);

                // Set render states
                graphicsDevice.BlendState        = BlendState.AlphaBlend;
                graphicsDevice.SamplerStates[0]  = SamplerState.LinearClamp;
                graphicsDevice.DepthStencilState = DepthStencilState.None;

                // Draw FXAA
                fxaaAntialiasing.Techniques[0].Passes[0].Apply();
                fullScreenQuad.Draw(graphicsDevice);

                // Draw bloom
                bloomProcessor.Draw(bloomRenderTarget, renderTarget);
            }
        }