public void Dispose() { ReflectionTexture.Clear(); BgTexture.Clear(); SkyTexture.Clear(); Wallpaper.Clear(); }
/// <summary> /// Read texture data and bg color from environments /// </summary> public void HandleEnvironments(RenderEnvironment.Usage usage) { SimulatedEnvironment simenv; switch (usage) { case RenderEnvironment.Usage.Background: if (BackgroundEnvironment != null) { simenv = BackgroundEnvironment.SimulateEnvironment(true); if (simenv != null) { BgColor = simenv.BackgroundColor; } BitmapConverter.EnvironmentBitmapFromEvaluator(BackgroundEnvironment, BgTexture, Gamma); } else { BgColor = Color.Empty; BgTexture.Clear(); } break; case RenderEnvironment.Usage.Skylighting: if (SkylightEnvironment != null) { simenv = SkylightEnvironment.SimulateEnvironment(true); if (simenv != null) { SkyColor = simenv.BackgroundColor; } BitmapConverter.EnvironmentBitmapFromEvaluator(SkylightEnvironment, SkyTexture, Gamma); } else { SkyColor = Color.Empty; SkyTexture.Clear(); } break; case RenderEnvironment.Usage.ReflectionAndRefraction: if (ReflectionEnvironment != null) { simenv = ReflectionEnvironment.SimulateEnvironment(true); if (simenv != null) { ReflectionColor = simenv.BackgroundColor; } BitmapConverter.EnvironmentBitmapFromEvaluator(ReflectionEnvironment, ReflectionTexture, Gamma); } else { ReflectionColor = Color.Empty; ReflectionTexture.Clear(); } break; } }
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 setRenderbuffers() { /*Attach 1 depthbuffer*/ base.genRenderbuffers(1); base.bindFramebuffer(1); base.bindRenderbuffer(1); base.renderbufferStorage(RenderbufferStorage.Depth24Stencil8, ReflectionTexture.GetTextureRezolution()); base.attachRenderbufferToFramebuffer(FramebufferAttachment.DepthStencilAttachment); }
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()); }
private bool RenderReflectionToTexture() { // Setup a clipping plane based on the height of the water to clip everything below it. Vector4 clipPlane = new Vector4(0.0f, 1.0f, 0.0f, -WaterModel.WaterHeight); // Set the render target to be the reflection render to texture. ReflectionTexture.SetRenderTarget(D3D.DeviceContext); // Clear the reflection render to texture. ReflectionTexture.ClearRenderTarget(D3D.DeviceContext, 0.0f, 0.0f, 0.0f, 1.0f); // Use the camera to render the reflection and create a reflection view matrix. Camera.RenderReflection(WaterModel.WaterHeight); // Get the camera reflection view matrix instead of the normal view matrix. Matrix reflectionViewMatrix = Camera.ReflectionViewMatrix; // Get the world and projection matrices from the d3d object. Matrix worldMatrix = D3D.WorldMatrix; Matrix projectionMatrix = D3D.ProjectionMatrix; // Get the position of the camera. Vector3 cameraPosition = Camera.GetPosition(); // Invert the Y coordinate of the camera around the water plane height for the reflected camera position. cameraPosition.Y = -cameraPosition.Y + (WaterModel.WaterHeight * 2.0f); // Translate the sky dome and sky plane to be centered around the reflected camera position. Matrix.Translation(cameraPosition.X, cameraPosition.Y, cameraPosition.Z, out worldMatrix); // Turn off back face culling and the Z buffer. D3D.TurnOffCulling(); D3D.TurnZBufferOff(); // Render the sky dome using the reflection view matrix. SkyDome.Render(D3D.DeviceContext); if (!SkyDomeShader.Render(D3D.DeviceContext, SkyDome.IndexCount, worldMatrix, reflectionViewMatrix, projectionMatrix, SkyDome.ApexColour, SkyDome.CenterColour)) { return(false); } // Enable back face culling. D3D.TurnOnCulling(); // Enable additive blending so the clouds blend with the sky dome color. D3D.EnableSecondBlendState(); // Render the sky plane using the sky plane shader. SkyPlane.Render(D3D.DeviceContext); if (!SkyPlaneShader.Render(D3D.DeviceContext, SkyPlane.IndexCount, worldMatrix, reflectionViewMatrix, projectionMatrix, SkyPlane.CloudTexture.TextureResource, SkyPlane.PerturbTexture.TextureResource, SkyPlane.m_Translation, SkyPlane.m_Scale, SkyPlane.m_Brightness)) { return(false); } // Turn off blending and enable the Z buffer again. D3D.TurnOffAlphaBlending(); D3D.TurnZBufferOn(); // Reset the world matrix. worldMatrix = D3D.WorldMatrix; // Render the terrain using the reflection view matrix and reflection clip plane. TerrainModel.Render(D3D.DeviceContext); if (!ReflectionShader.Render(D3D.DeviceContext, TerrainModel.IndexCount, worldMatrix, reflectionViewMatrix, 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); }