private bool RenderSceneToTexture()
        {
            // Set the render target to be the render to texture.
            RenderTexture.SetRenderTarget(D3D.DeviceContext);

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

            // Get the world matrix from the d3d object.
            Matrix worldMatrix = D3D.WorldMatrix;

            // Generate the light view matrix based on the light's position.
            Light.GenerateViewMatrix();

            // Get the view and orthographic matrices from the light object.
            Matrix lightViewMatrix  = Light.ViewMatrix;
            Matrix lightOrthoMatrix = Light.OrthoMatrix;

            // Translate to the position of the tree.
            Vector3 treePosition = TreeModel.GetPosition();

            Matrix.Translation(treePosition.X, treePosition.Y, treePosition.Z, out worldMatrix);

            // Render the tree trunk with the depth shader.
            TreeModel.RenderTrunk(D3D.DeviceContext);
            if (!DepthShader.Render(D3D.DeviceContext, TreeModel.TrunkIndexCount, worldMatrix, lightViewMatrix, lightOrthoMatrix))
            {
                return(false);
            }

            // Render the tree leaves using the depth transparency shader.
            TreeModel.RenderLeaves(D3D.DeviceContext);
            if (!TransparentDepthShader.Render(D3D.DeviceContext, TreeModel.LeafIndexCount, worldMatrix, lightViewMatrix, lightOrthoMatrix, TreeModel.LeafTexture.TextureResource))
            {
                return(false);
            }

            // Reset the world matrix.
            worldMatrix = D3D.WorldMatrix;

            // Translate to the position of the ground model.
            Vector3 groundPosition = GroundModel.GetPosition();

            Matrix.Translation(groundPosition.X, groundPosition.Y, groundPosition.Z, out worldMatrix);

            // Render the ground model with the depth shader.
            GroundModel.Render(D3D.DeviceContext);
            if (!DepthShader.Render(D3D.DeviceContext, GroundModel.IndexCount, worldMatrix, lightViewMatrix, lightOrthoMatrix))
            {
                return(false);
            }

            // 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);
        }
        public void ShutDown()
        {
            DPerfLogger.ShutDown();

            // Release the light object.
            Light = null;
            // Release the position object.
            Position = null;
            // Release the timer object.
            Timer = null;
            // Release the camera object.
            Camera = null;

            // Release the shadow shader object.
            ShadowShader?.ShutDown();
            ShadowShader = null;
            // Release the transparent depth shader object.
            TransparentDepthShader?.ShutDown();
            TransparentDepthShader = null;
            // Release the depth shader object.
            DepthShader?.ShutDown();
            DepthShader = null;
            // Release the render to texture object.
            RenderTexture?.Shutdown();
            RenderTexture = null;
            // Release the tree object.
            TreeModel?.Shutdown();
            TreeModel = null;
            // Release the model object.
            GroundModel?.Shutdown();
            GroundModel = null;
            // Release the input object.
            Input?.Shutdown();
            Input = null;
            // Release the Direct3D object.
            D3D?.ShutDown();
            D3D = null;
        }