public void Shutdown() { // Release the light object. Light = null; Light2 = null; // Release the camera object. Camera = null; // Release the second render to texture object. RenderTexture2?.Shutdown(); RenderTexture2 = null; // Release the shadow shader object. ShadowShader?.ShutDown(); ShadowShader = null; // Release the depth shader object. DepthShader?.ShutDown(); DepthShader = null; /// Release the render to texture object. RenderTexture?.Shutdown(); RenderTexture = null; // Release the ground model object. GroundModel?.Shutdown(); GroundModel = null; // Release the sphere model object. SphereModel?.Shutdown(); SphereModel = null; // Release the cube model object. CubeModel?.Shutdown(); CubeModel = null; // Release the Direct3D object. D3D?.ShutDown(); D3D = null; }
private bool RenderSceneToTexture2() { // Set the render target to be the render to texture. RenderTexture2.SetRenderTarget(D3D.DeviceContext); // Clear the render to texture. RenderTexture2.ClearRenderTarget(D3D.DeviceContext, 0.0f, 0.0f, 0.0f, 1.0f); // Generate the light view matrix based on the light's position. Light2.GenerateViewMatrix(); // Get the world matrix from the d3d object. Matrix worldMareix = D3D.WorldMatrix; // Get the view and orthographic matrices from the light object. Matrix lightViewMatrix = Light2.ViewMatrix; Matrix lightOrthoMatrix = Light2.ProjectionMatrix; // Setup the translation matrix for the cube model. Vector3 cubePosition = CubeModel.GetPosition(); Matrix.Translation(cubePosition.X, cubePosition.Y, cubePosition.Z, out worldMareix); // Render the cube model with the depth shader. CubeModel.Render(D3D.DeviceContext); if (!DepthShader.Render(D3D.DeviceContext, CubeModel.IndexCount, worldMareix, lightViewMatrix, lightOrthoMatrix)) { return(false); } // Reset the world matrix. worldMareix = D3D.WorldMatrix; // Setup the translation matrix for the sphere model. Vector3 spherePosition = SphereModel.GetPosition(); Matrix.Translation(spherePosition.X, spherePosition.Y, spherePosition.Z, out worldMareix); // Render the sphere model with the depth shader. SphereModel.Render(D3D.DeviceContext); if (!DepthShader.Render(D3D.DeviceContext, SphereModel.IndexCount, worldMareix, lightViewMatrix, lightOrthoMatrix)) { return(false); } // Reset the world matrix. worldMareix = D3D.WorldMatrix; // Setup the translation matrix for the ground model. Vector3 groundPosition = GroundModel.GetPosition(); Matrix.Translation(groundPosition.X, groundPosition.Y, groundPosition.Z, out worldMareix); // Render the ground model with the depth shader. GroundModel.Render(D3D.DeviceContext); if (!DepthShader.Render(D3D.DeviceContext, GroundModel.IndexCount, worldMareix, 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); }