private bool Render()
        {
            // Clear the scene.
            D3D.BeginScene(0.0f, 0.0f, 1.0f, 1.0f);

            // Generate the view matrix based on the camera's position.
            Camera.Render();

            // Get the world, view, projection, ortho, and base view 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;

            // Render the ground model.
            GroundModel.Render(D3D.DeviceContext);
            ShaderManager.RenderTextureShader(D3D.DeviceContext, GroundModel.IndexCount, worldMatrix, viewCameraMatrix, projectionMatrix, GroundModel.ColourTexture.TextureResource);

            // Turn on the alpha-to-coverage blending.
            D3D.EnableSecondBlendState();

            // Render the foliage.
            Foliage.Render(D3D.DeviceContext);
            if (!ShaderManager.RenderFoliageShader(D3D.DeviceContext, Foliage.VertexCount, Foliage.InstanceCount, viewCameraMatrix, projectionMatrix, Foliage.Texture.TextureResource))
            {
                return(false);
            }

            // Turn off the alpha blending.
            D3D.TurnOffAlphaBlending();

            // Render the user interface.
            UserInterface.Render(D3D, ShaderManager, worldMatrix, baseViewMatrix, orthoMatrix);

            // Present the rendered scene to the screen.
            D3D.EndScene();

            return(true);
        }
Ejemplo n.º 2
0
        private bool Render()
        {
            _directX.BeginScene(new Color4(0.0f, 0.0f, 0.0f, 1.0f));

            _camera.Render();

            var worldMatrix      = _directX.WorldMatrix;
            var viewCameraMatrix = _camera.ViewMatrix;
            var projectionMatrix = _directX.ProjectionMatrix;
            var orthoMatrix      = _directX.OrthoMatrix;
            var baseViewMatrix   = _camera.BaseViewMatrix;

            //_groundModel.Render(_directX.DeviceContext);
            //_shaderManager.RenderTextureShader(_directX.DeviceContext, _groundModel.IndexCount, worldMatrix, viewCameraMatrix, projectionMatrix, _groundModel.Texture.TextureResource);

            var ambientColour = new Color4(0.05f, 0.05f, 0.05f, 1.0f);
            //var diffuseColour = new Color4(1.0f, 1.0f, 1.0f, 1.0f);
            //var diffuseColour = new Color4(1.0f, 1.0f, 1.0f, 1.0f);
            //var direction = new Vector3(-0.5f, -1.0f, 0.0f);

            var direction     = TimeOfDay.GetSunDirection();
            var diffuseColour = TimeOfDay.AmbientColour;

            var result = true;

            Matrix.Translation(_camera.Position.X, _camera.Position.Y, _camera.Position.Z, out worldMatrix);

            _directX.SetCulling(false);
            _directX.SetZBuffer(false);

            _skyDome.Render(_directX.DeviceContext);
            //result = _shaderManager.RenderSkyDomeShader(_directX.DeviceContext, _skyDome.IndexCount, worldMatrix, viewCameraMatrix, projectionMatrix, _skyDome.ApexColour, _skyDome.CenterColour);
            result = _shaderManager.RenderSkyDomeShader(_directX.DeviceContext, _skyDome.IndexCount, worldMatrix, viewCameraMatrix, projectionMatrix, TimeOfDay.SkyColour, TimeOfDay.HorizonColour);

            _directX.SetCulling(true);

            _directX.EnableCloudBlendState();

            _skyPlane.Render(_directX.DeviceContext);
            //result &= _shaderManager.RenderSkyPlaneShader(_directX.DeviceContext, _skyPlane.IndexCount, worldMatrix, viewCameraMatrix, projectionMatrix, _skyPlane.CloudTexture.TextureResource, _skyPlane.PerturbTexture.TextureResource, _skyPlane.Translation, _skyPlane.Scale, _skyPlane.Brightness);
            result &= _shaderManager.RenderSkyPlaneShader(_directX.DeviceContext, _skyPlane.IndexCount, worldMatrix, viewCameraMatrix, projectionMatrix, _skyPlane.CloudTexture.TextureResource, _skyPlane.PerturbTexture.TextureResource, _skyPlane.Translation, _skyPlane.Scale, TimeOfDay.CloudBrightness);

            worldMatrix = _directX.WorldMatrix;

            _directX.SetZBuffer(true);

            _directX.EnableSecondBlendState();

            _foliage.Render(_directX.DeviceContext);
            result &= _shaderManager.RenderFoliageShader(_directX.DeviceContext, _foliage.VertexCount, _foliage.InstanceCount, viewCameraMatrix, projectionMatrix, _foliage.Texture.TextureResource);

            _directX.SetAlphaBlending(false);

            _terrain.Render(_directX.DeviceContext);
            result = _shaderManager.RenderTerrainShader(_directX.DeviceContext, _terrain.IndexCount, worldMatrix, viewCameraMatrix, projectionMatrix, ambientColour, diffuseColour, direction, _terrain.Texture.TextureResource);

            _directX.SetZBuffer(false);
            _directX.SetAlphaBlending(true);

            _userInterface.Render(_directX, _shaderManager, worldMatrix, baseViewMatrix, orthoMatrix);

            _directX.SetAlphaBlending(false);
            _directX.SetZBuffer(true);

            _directX.EndScene();

            return(result);
        }