private bool Render() { // Clear the scene. D3D.BeginScene(0.0f, 0.0f, 0.0f, 1.0f); // Generate the view matrix based on the camera's position. Camera.Render(); // Get the world, view, projection, ortho, base view and reflection matrices from the camera and Direct3D objects. Matrix worldMatrix = D3D.WorldMatrix; Matrix viewCameraMatrix = Camera.ViewMatrix; Matrix projectionMatrix = D3D.ProjectionMatrix; Matrix orthoMatrix = D3D.OrthoMatrix; Matrix baseViewMatrix = Camera.BaseViewMatrix; Matrix reflectionMatrix = Camera.ReflectionViewMatrix; // Get the position of the camera. Vector3 cameraPosition = Camera.GetPosition(); // Translate the sky dome to be centered around the 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 sky dome shader. SkyDome.Render(D3D.DeviceContext); if (!SkyDomeShader.Render(D3D.DeviceContext, SkyDome.IndexCount, worldMatrix, viewCameraMatrix, projectionMatrix, SkyDome.ApexColour, SkyDome.CenterColour)) { return(false); } // Turn back face culling back on. 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, viewCameraMatrix, projectionMatrix, SkyPlane.CloudTexture.TextureResource, SkyPlane.PerturbTexture.TextureResource, SkyPlane.m_Translation, SkyPlane.m_Scale, SkyPlane.m_Brightness)) { return(false); } // Turn off blending. D3D.TurnOffAlphaBlending(); // Turn the Z buffer back on. D3D.TurnZBufferOn(); // Reset the world matrix. worldMatrix = D3D.WorldMatrix; // Render the terrain using the terrain shader. TerrainModel.Render(D3D.DeviceContext); if (!TerrainShader.Render(D3D.DeviceContext, TerrainModel.IndexCount, worldMatrix, viewCameraMatrix, projectionMatrix, TerrainModel.ColorTexture.TextureResource, TerrainModel.NormalMapTexture.TextureResource, Light.DiffuseColour, Light.Direction, 2.0f)) { return(false); } // Translate to the location of the water and render it. Matrix.Translation(240.0f, WaterModel.WaterHeight, 250.0f, out worldMatrix); WaterModel.Render(D3D.DeviceContext); if (!WaterShader.Render(D3D.DeviceContext, WaterModel.IndexCount, worldMatrix, viewCameraMatrix, projectionMatrix, reflectionMatrix, ReflectionTexture.ShaderResourceView, RefractionTexture.ShaderResourceView, WaterModel.Texture.TextureResource, Camera.GetPosition(), WaterModel.NormalMapTiling, WaterModel.WaterTranslation, WaterModel.ReflectRefractScale, WaterModel.RefractionTint, Light.Direction, WaterModel.SpecularShininess)) { return(false); } // Reset the world matrix. worldMatrix = D3D.WorldMatrix; // Turn off the Z buffer to begin all 2D rendering. D3D.TurnZBufferOff(); // Turn on the alpha blending before rendering the text. D3D.TurnOnAlphaBlending(); // Render the text user interface elements. Text.Render(D3D.DeviceContext, worldMatrix, orthoMatrix); // Turn off alpha blending after rendering the text. D3D.TurnOffAlphaBlending(); // 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); }
private bool RenderScene() { // Generate the view matrix based on the camera position. Camera.Render(); // Get the world, view, and projection matrices from camera and d3d objects. var viewMatrix = Camera.ViewMatrix; var worldMatrix = D3D.WorldMatrix; var projectionMatrix = D3D.ProjectionMatrix; #region Render Ground Model // Translate to where the ground model will be rendered. Matrix.Translation(0f, 1f, 0f, out worldMatrix); // Put the ground model vertex and index buffers on the graphics pipeline to prepare them for drawing. GroundModel.Render(D3D.DeviceContext); // Render the ground model using the light shader. if (!LightShader.Render(D3D.DeviceContext, GroundModel.IndexCount, worldMatrix, viewMatrix, projectionMatrix, GroundModel.TextureCollection.Select(item => item.TextureResource).First(), Light.Direction, Light.AmbientColor, Light.DiffuseColour, Camera.GetPosition(), Light.SpecularColor, Light.SpecularPower)) { return(false); } #endregion // Reset the world matrix. worldMatrix = D3D.WorldMatrix; #region Render Wall Model // Translate to where the ground model will be rendered. Matrix.Translation(0f, 6f, 8f, out worldMatrix); // Put the wall model vertex and index buffers on the graphics pipeline to prepare them for drawing. WallModel.Render(D3D.DeviceContext); // Render the wall model using the light shader. if (!LightShader.Render(D3D.DeviceContext, WallModel.IndexCount, worldMatrix, viewMatrix, projectionMatrix, WallModel.TextureCollection.Select(item => item.TextureResource).First(), Light.Direction, Light.AmbientColor, Light.DiffuseColour, Camera.GetPosition(), Light.SpecularColor, Light.SpecularPower)) { return(false); } #endregion // Reset the world matrix. worldMatrix = D3D.WorldMatrix; #region Render Bath Model // Translate to where the bath model will be rendered. Matrix.Translation(0f, 2f, 0f, out worldMatrix); // Put the bath model vertex and index buffers on the graphics pipeline to prepare them for drawing. BathModel.Render(D3D.DeviceContext); // Render the bath model using the light shader. if (!LightShader.Render(D3D.DeviceContext, BathModel.IndexCount, worldMatrix, viewMatrix, projectionMatrix, BathModel.TextureCollection.Select(item => item.TextureResource).First(), Light.Direction, Light.AmbientColor, Light.DiffuseColour, Camera.GetPosition(), Light.SpecularColor, Light.SpecularPower)) { return(false); } #endregion // Reset the world matrix. worldMatrix = D3D.WorldMatrix; #region Render Water Model // Get the camera reflection view matrix. var reflectionMatrix = Camera.ReflectionViewMatrix; // Translate to where the water model will be rendered. Matrix.Translation(0f, WaterHeight, 0f, out worldMatrix); // Put the water model vertex and index buffers on the graphics pipeline to prepare them for drawing. WaterModel.Render(D3D.DeviceContext); // Render the bath model using the light shader. if (!WaterShader.Render(D3D.DeviceContext, WaterModel.IndexCount, worldMatrix, viewMatrix, projectionMatrix, reflectionMatrix, RenderReflectionTexture.ShaderResourceView, RenderRefractionTexture.ShaderResourceView, WaterModel.TextureCollection.Select(item => item.TextureResource).First(), WaterTranslation, 0.1f)) // was 0.01f for scale originally. { return(false); } #endregion return(true); }