public void Render(DeviceContext deviceContext, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix, Sun sun) { deviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(_vertexBuffer, Utilities.SizeOf <VertexDefinition.WaterVertex>(), 0)); deviceContext.InputAssembler.SetIndexBuffer(_indexBuffer, Format.R32_UInt, 0); deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; _shader.Render(deviceContext, _indexCount, worldMatrix, viewMatrix, projectionMatrix, _bumpMapTexture, _borderTexture, _waveTranslation, sun); }
public void Render(DeviceContext deviceContext, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix, Light light) { Light newLight = new Light(light.Direction, light.Color, new Vector4(1), light.SpecularPower, light.SpecularColor); _skydome.Render(deviceContext); _renderer.LightShader.Render(deviceContext, _skydome.IndexCount, Matrix.Scaling(10000) * Matrix.RotationY(MathUtil.PiOverTwo - WaveTranslation.X / 8), viewMatrix, projectionMatrix, _skydome.Texture, newLight, _renderer.Camera); deviceContext.ClearDepthStencilView(_renderer.DirectX.RenderToTextureDepthStencilView, DepthStencilClearFlags.Depth, 1, 0); _refractionTexture.SetRenderTarget(deviceContext, _renderer.DirectX.RenderToTextureDepthStencilView); _refractionTexture.ClearRenderTarget(deviceContext, _renderer.DirectX.RenderToTextureDepthStencilView, 0.0f, 0.0f, 0.0f, 1.0f); deviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(TerrainVertexBuffer, Utilities.SizeOf <VertexDefinition.PositionTextureNormal4Weights>(), 0)); deviceContext.InputAssembler.SetIndexBuffer(TerrainIndexBuffer, Format.R32_UInt, 0); deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; TerrainShader.Render(deviceContext, TerrainIndexCount, worldMatrix, viewMatrix, projectionMatrix, light, _terrainTextures, _refractionClippingPlane); deviceContext.ClearDepthStencilView(_renderer.DirectX.RenderToTextureDepthStencilView, DepthStencilClearFlags.Depth, 1, 0); _reflectionTexture.SetRenderTarget(deviceContext, _renderer.DirectX.RenderToTextureDepthStencilView); _reflectionTexture.ClearRenderTarget(deviceContext, _renderer.DirectX.RenderToTextureDepthStencilView, 0.0f, 0.0f, 0.0f, 1.0f); _skydome.Render(deviceContext); _renderer.LightShader.Render(deviceContext, _skydome.IndexCount, Matrix.Scaling(10000) * Matrix.RotationY(MathUtil.PiOverTwo - WaveTranslation.X / 8), viewMatrix, projectionMatrix, _skydome.Texture, newLight, _renderer.Camera); deviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(TerrainVertexBuffer, Utilities.SizeOf <VertexDefinition.PositionTextureNormal4Weights>(), 0)); deviceContext.InputAssembler.SetIndexBuffer(TerrainIndexBuffer, Format.R32_UInt, 0); deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; TerrainShader.Render(deviceContext, TerrainIndexCount, worldMatrix, _renderer.Camera.ReflectionMatrix, projectionMatrix, light, _terrainTextures, _reflectionClippingPlane); _renderer.DirectX.SetBackBufferAsRenderTarget(); //Render water deviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(WaterVertexBuffer, Utilities.SizeOf <VertexDefinition.PositionTexture>(), 0)); deviceContext.InputAssembler.SetIndexBuffer(WaterIndexBuffer, Format.R32_UInt, 0); deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; WaterShader.Render(deviceContext, WaterIndexCount, worldMatrix, viewMatrix, projectionMatrix, _renderer.Camera.ReflectionMatrix, _reflectionTexture.ShaderResourceView, _refractionTexture.ShaderResourceView, _bumpMap.TextureResource, WaveTranslation, _renderer.Camera.Position); //Render terrain deviceContext.InputAssembler.SetVertexBuffers(0, new VertexBufferBinding(TerrainVertexBuffer, Utilities.SizeOf <VertexDefinition.PositionTextureNormal4Weights>(), 0)); deviceContext.InputAssembler.SetIndexBuffer(TerrainIndexBuffer, Format.R32_UInt, 0); deviceContext.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList; TerrainShader.Render(deviceContext, TerrainIndexCount, worldMatrix, viewMatrix, projectionMatrix, light, _terrainTextures, _noClippingPlane); _bitmap.Render(deviceContext); _renderer.TextureShader.Render(deviceContext, _bitmap.IndexCount, Matrix.Identity, _renderer.Camera.UiMatrix, _renderer.DirectX.OrthoMatrix, _refractionTexture.ShaderResourceView); _bitmap2.Render(deviceContext); _renderer.TextureShader.Render(deviceContext, _bitmap.IndexCount, Matrix.Identity, _renderer.Camera.UiMatrix, _renderer.DirectX.OrthoMatrix, _reflectionTexture.ShaderResourceView); }
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); }