private bool RenderRefractionToTexture() { // Setup a clipping plane based on the height of the water to clip everything above it to create a refraction. Vector4 clipPlane = new Vector4(0.0f, -1.0f, 0.0f, WaterModel.WaterHeight + 0.1f); // Set the render target to be the refraction render to texture. RefractionTexture.SetRenderTarget(D3D.DeviceContext); // Clear the refraction render to texture. RefractionTexture.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 matrices from the camera and d3d objects. Matrix worldMatrix = D3D.WorldMatrix; Matrix viewMatrix = Camera.ViewMatrix; Matrix projectionMatrix = D3D.ProjectionMatrix; // Render the terrain using the reflection shader and the refraction clip plane to produce the refraction effect. TerrainModel.Render(D3D.DeviceContext); if (!ReflectionShader.Render(D3D.DeviceContext, TerrainModel.IndexCount, worldMatrix, viewMatrix, projectionMatrix, TerrainModel.ColorTexture.TextureResource, TerrainModel.NormalMapTexture.TextureResource, Light.DiffuseColour, Light.Direction, 2.0f, clipPlane)) { 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() { // Release the position object. Position = null; // Release the light object. Light = null; // Release the fps object. FPS = null; // Release the camera object. Camera = null; // Release the text object. Text?.Shutdown(); Text = null; // Release the cpu object. CPU?.Shutdown(); CPU = null; // Release the water shader object. WaterShader?.ShutDown(); WaterShader = null; // Release the water object. WaterModel?.ShutDown(); WaterModel = null; // Release the reflection shader object. ReflectionShader?.ShutDown(); ReflectionShader = null; // Release the reflection render to texture object. ReflectionTexture?.Shutdown(); ReflectionTexture = null; // Release the refraction render to texture object. RefractionTexture?.Shutdown(); RefractionTexture = null; // Release the sky plane shader object. SkyPlaneShader?.ShutDown(); SkyPlaneShader = null; // Release the sky plane object. SkyPlane?.ShurDown(); SkyPlane = null; // Release the sky dome shader object. SkyDomeShader?.ShutDown(); SkyDomeShader = null; // Release the sky dome object. SkyDome?.ShutDown(); SkyDome = null; // Release the terrain shader object. TerrainShader?.ShutDown(); TerrainShader = null; // Release the tree object. TerrainModel?.ShutDown(); TerrainModel = null; // Release the input object. Input?.Shutdown(); Input = null; // Release the Direct3D object. D3D?.ShutDown(); D3D = null; }
protected override void setFramebuffers() { /*Create 2 framebuffers : * 1 - for reflection * 2 - for refraction*/ base.genFramebuffers(2); base.bindFramebuffer(1); base.attachTextureToFramebuffer(FramebufferAttachment.ColorAttachment0, ReflectionTexture.GetTextureDescriptor()); base.bindFramebuffer(2); base.attachTextureToFramebuffer(FramebufferAttachment.ColorAttachment0, RefractionTexture.GetTextureDescriptor()); base.attachTextureToFramebuffer(FramebufferAttachment.DepthStencilAttachment, DepthTexture.GetTextureDescriptor()); }