Esempio n. 1
0
        private bool Render2DTextureScene()
        {
            // Clear the buffers to begin the scene.
            D3D.BeginScene(1.0f, 0.0f, 0.0f, 0.0f);

            // Generate the view matrix based on the camera's position.
            Camera.Render();

            // Get the world, view, and ortho matrices from the camera and d3d objects.
            Matrix worldMatrix = D3D.WorldMatrix;
            Matrix viewMatrix  = Camera.ViewMatrix;
            Matrix orthoMatrix = D3D.OrthoMatrix;

            // Turn off the Z buffer to begin all 2D rendering.
            D3D.TurnZBufferOff();

            // Put the full screen ortho window vertex and index buffers on the graphics pipeline to prepare them for drawing.
            FullScreenWindow.Render(D3D.DeviceContext);

            // Render the full screen ortho window using the texture shader and the full screen sized blurred render to texture resource.
            if (!TextureShader.Render(D3D.DeviceContext, FullScreenWindow.IndexCount, worldMatrix, viewMatrix, orthoMatrix, UpSampleTexure.ShaderResourceView))
            {
                return(false);
            }

            // Turn the Z buffer back on now that all 2D rendering has completed.
            D3D.TurnZBufferOn();

            // Present the rendered scene to the screen.
            D3D.EndScene();

            return(true);
        }
Esempio n. 2
0
        private bool UpSampleTexture()
        {
            // Set the render target to be the render to texture.
            UpSampleTexure.SetRenderTarget(D3D.DeviceContext);

            // Clear the render to texture.
            UpSampleTexure.ClearRenderTarget(D3D.DeviceContext, 0.0f, 0.0f, 0.0f, 1.0f);

            // Generate the view matrix based on the camera's position.
            Camera.Render();

            // Get the world and view matrices from the camera and d3d objects.
            Matrix cameraViewMatrix = Camera.BaseViewMatrix;
            Matrix worldMatrix      = D3D.WorldMatrix;

            // Get the ortho matrix from the render to texture since texture has different dimensions.
            Matrix orthoMatrix = UpSampleTexure.OrthoMatrix;

            // Turn off the Z buffer to begin all 2D rendering.
            D3D.TurnZBufferOff();

            // Put the full screen ortho window vertex and index buffers on the graphics pipeline to prepare them for drawing.
            if (!FullScreenWindow.Render(D3D.DeviceContext))
            {
                return(false);
            }

            // Render the full screen ortho window using the texture shader and the small sized final blurred render to texture resource.
            if (!TextureShader.Render(D3D.DeviceContext, FullScreenWindow.IndexCount, worldMatrix, cameraViewMatrix, orthoMatrix, VerticalBlurTexture.ShaderResourceView))
            {
                return(false);
            }

            // Turn the Z buffer back on now that all 2D rendering has completed.
            D3D.TurnZBufferOn();

            // Reset the render target back to the original back buffer and not the render to texture anymore.
            D3D.SetBackBufferRenderTarget();

            // Reset the viewport back to the original.
            D3D.ResetViewPort();

            return(true);
        }
        private bool Render()
        {
            // Render the depth of the scene to a texture.
            if (!RenderSceneToTexture())
            {
                return(false);
            }

            // Clear the scene.
            D3D.BeginScene(0.0f, 0.5f, 0.8f, 1.0f);

            // Get the matrices.
            Matrix worldMatrix          = D3D.WorldMatrix;
            Matrix cameraBaseViewMatrix = Camera.BaseViewMatrix;
            Matrix orthoMatrix          = D3D.OrthoMatrix;

            // Turn off the Z buffer to begin all 2D rendering.
            D3D.TurnZBufferOff();

            // Put the full screen ortho window vertex and index buffers on the graphics pipeline to prepare them for drawing.
            if (!FullScreenWindow.Render(D3D.DeviceContext))
            {
                return(false);
            }

            // Render the full screen ortho window using the deferred light shader and the render buffers.
            if (!LightShader.Render(D3D.DeviceContext, FullScreenWindow.IndexCount, worldMatrix, cameraBaseViewMatrix, orthoMatrix, DeferredBuffers.ShaderResourceViewArray[0], DeferredBuffers.ShaderResourceViewArray[1], Light.Direction))
            {
                return(false);
            }

            // Turn the Z buffer back on now that all 2D rendering has completed.
            D3D.TurnZBufferOn();

            // Present the rendered scene to the screen.
            D3D.EndScene();

            return(true);
        }