private bool Render()
        {
            // Clear the buffer to begin the scene.
            D3D.BeginScene(0f, 0f, 0f, 1f);

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

            // Get the world, view, and projection matrices from camera and d3d objects.
            Matrix viewMatrix       = Camera.ViewMatrix;
            Matrix worldMatrix      = D3D.WorldMatrix;
            Matrix projectionMatrix = D3D.ProjectionMatrix;

            // Turn on alpha blending.
            D3D.TurnOnAlphaBlending();

            // Put the particle system vertex and index buffers on the graphics pipeline to prepare them for drawing.
            ParticleSystem.Render(D3D.DeviceContext);

            // Render the model using the texture shader.
            if (!ParticleShader.Render(D3D.DeviceContext, ParticleSystem.IndexCount, worldMatrix, viewMatrix, projectionMatrix, ParticleSystem.Texture.TextureResource))
            {
                return(false);
            }

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

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

            return(true);
        }
        private bool RenderGraphics()
        {
            // 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, and ortho matrices from the camera and Direct3D objects.
            Matrix worldMatrix      = D3D.WorldMatrix;
            Matrix cameraViewMatrix = Camera.ViewMatrix;
            Matrix projectionMatrix = D3D.ProjectionMatrix;
            Matrix orthoD3DMatrix   = D3D.OrthoMatrix;

            // Construct the frustum.
            Frustum.ConstructFrustum(DSystemConfiguration.ScreenDepth, projectionMatrix, cameraViewMatrix);

            // Set the terrain shader parameters only once now that it will use for rendering.
            if (!TerrainShader.SetShaderParameters(D3D.DeviceContext, worldMatrix, cameraViewMatrix, projectionMatrix, Light.AmbientColor, Light.DiffuseColour, Light.Direction, TerrainModel.Texture.TextureResource))
            {
                return(false);
            }

            // Render the terrain using the quad tree and terrain shader.
            QuadTree.Render(D3D.DeviceContext, Frustum, TerrainShader);

            // Set the number of rendered terrain triangles since some were culled.
            if (!Text.SetRenderCount(QuadTree.DrawCount, D3D.DeviceContext))
            {
                return(false);
            }
            if (!Text.SetSentenceByIndex(11, "TEST", D3D.DeviceContext))
            {
                return(false);
            }

            // 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.
            if (!Text.Render(D3D.DeviceContext, FontShader, worldMatrix, orthoD3DMatrix))
            {
                return(false);
            }

            // 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);
        }
Esempio n. 3
0
        private bool RenderGraphics()
        {
            // Clear the scene.
            D3D.BeginScene(0, 0, 0, 1);

            // Generate the view matrix based on the camera's 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;
            var orthoMatrix      = D3D.OrthoMatrix;

            // Construct the frustrum
            Frustum.ConstructFrustum(SystemConfiguration.ScreenDepth, projectionMatrix, viewMatrix);

            // Set the terrain shader parameters that it will use for rendering.
            if (!HeightMapTerrainShader.SetShaderParameters(D3D.DeviceContext,
                                                            worldMatrix, viewMatrix, projectionMatrix,
                                                            Light.Direction, Light.AmbientColor, Light.DiffuseColor,
                                                            Terrain.Texture.TextureResource))
            {
                return(false);
            }

            // Render the terrain using the quad tree and terrain shader
            QuadTree.Render(D3D.DeviceContext, Frustum, HeightMapTerrainShader);

            // Set the number of rendered terrain triangles since some were culled.
            if (!Text.SetRenderCount(QuadTree.DrawCount, D3D.DeviceContext))
            {
                return(false);
            }

            // 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 string.
            if (!Text.Render(D3D.DeviceContext, worldMatrix, orthoMatrix))
            {
                return(false);
            }

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

            // Turn on the Z buffer to begin all 2D rendering.
            D3D.TurnZBufferOn();

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

            return(true);
        }
        public bool Render()
        {
            float   distortionScale, distortionBias;
            Vector3 scrollSpeeds, scales;
            Vector2 distortion1, distortion2, distortion3;

            // Increment the frame time counter.
            FrameTime += 0.001f;
            if (FrameTime >= 1000.0f)
            {
                FrameTime = 0.0f;
            }

            // Set the three scrolling speeds for the three different noise textures.
            // The x value is the scroll speed for the first noise texture. The y value is the scroll speed for the second noise texture. And the z value is the scroll speed for the third noise texture.
            scrollSpeeds = new Vector3(1.3f, 2.1f, 2.3f);

            // Set the three scales which will be used to create the three different noise octave textures.
            scales = new Vector3(1.0f, 2.0f, 3.0f);

            // Set the three different x and y distortion factors for the three different noise textures.
            distortion1 = new Vector2(0.1f, 0.2f);
            distortion2 = new Vector2(0.1f, 0.3f);
            distortion3 = new Vector2(0.1f, 0.1f);

            // The the scale and bias of the texture coordinate sampling perturbation.
            distortionScale = 0.8f;
            distortionBias  = 0.5f;

            // Clear the buffers to begin the scene.
            D3D.BeginScene(0, 0, 0, 1f);

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

            // Get the world, view, and projection matrices from the camera and d3d objects.
            Matrix worldMatrix      = D3D.WorldMatrix;
            Matrix viewMatrix       = Camera.ViewMatrix;
            Matrix projectionMatrix = D3D.ProjectionMatrix;

            // Turn on alpha blending for the fire transparency.
            D3D.TurnOnAlphaBlending();

            // Put the square model vertex and index buffers on the graphics pipeline to prepare them for drawing.
            Model.Render(D3D.DeviceContext);

            // Render the square model using the fire shader.
            FireShader.Render(D3D.DeviceContext, Model.IndexCount, worldMatrix, viewMatrix, projectionMatrix, Model.TextureCollection.Select(item => item.TextureResource).ToArray()[0], Model.TextureCollection.Select(item => item.TextureResource).ToArray()[1], Model.TextureCollection.Select(item => item.TextureResource).ToArray()[2], FrameTime, scrollSpeeds, scales, distortion1, distortion2, distortion3, distortionScale, distortionBias);

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

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

            return(true);
        }
        private bool RenderGraphics()
        {
            // 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, and ortho matrices from the camera and Direct3D objects.
            Matrix worldMatrix      = D3D.WorldMatrix;
            Matrix cameraViewMatrix = Camera.ViewMatrix;
            Matrix projectionMatrix = D3D.ProjectionMatrix;
            Matrix orthoD3DMatrix   = D3D.OrthoMatrix;

            // Render the terrain buffers.
            TerrainModel.Render(D3D.DeviceContext);

            // Render the model using the color shader.
            if (!TerrainShader.Render(D3D.DeviceContext, TerrainModel.IndexCount, worldMatrix, cameraViewMatrix, projectionMatrix, Light.AmbientColor, Light.DiffuseColour, Light.Direction, TerrainModel.Texture.TextureResource))
            {
                return(false);
            }

            // Turn off the Z buffer to begin all 2D rendering.
            D3D.TurnZBufferOff();

            // Render the mini map.
            if (!MiniMap.Render(D3D.DeviceContext, worldMatrix, orthoD3DMatrix, TextureShader))
            {
                return(false);
            }

            // Turn on the alpha blending before rendering the text.
            D3D.TurnOnAlphaBlending();

            // Render the text user interface elements.
            if (!Text.Render(D3D.DeviceContext, worldMatrix, orthoD3DMatrix))
            {
                return(false);
            }

            // 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);
        }
Esempio n. 6
0
        private bool RenderGraphics()
        {
            // Clear the scene.
            D3D.BeginScene(0, 0, 0, 1);

            // Generate the view matrix based on the camera's 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;
            var orthoMatrix      = D3D.OrthoMatrix;

            // Render the terrain buffers.
            Terrain.Render(D3D.DeviceContext);

            // Render the model using the color shader.
            if (!HeightMapTerrainShader.Render(D3D.DeviceContext, Terrain.IndexCount,
                                               worldMatrix, viewMatrix, projectionMatrix,
                                               Light.Direction, Light.AmbientColor, Light.DiffuseColor,
                                               Terrain.Texture.TextureResource))
            {
                return(false);
            }

            // 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 string.
            if (!Text.Render(D3D.DeviceContext, worldMatrix, orthoMatrix))
            {
                return(false);
            }

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

            // Turn on the Z buffer to begin all 2D rendering.
            D3D.TurnZBufferOn();

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

            return(true);
        }
Esempio n. 7
0
        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;

            // Put the model vertex and index buffers on the graphics pipeline to prepare them for drawing.
            Model.Render(D3D.DeviceContext);

            // Render the model using the color shader.
            if (!TextureShader.Render(D3D.DeviceContext, Model.IndexCount, worldMatrix, viewMatrix, projectionMatrix, Model.TextureCollection.Select(item => item.TextureResource).First()))
            {
                return(false);
            }

            // Put the model vertex and index buffers on the graphics pipeline to prepare them for drawing.
            Model.Render(D3D.DeviceContext);

            // Translate to the right by one unit and towards the camera by one unit.
            Matrix.Translation(1, 0, -1, out worldMatrix);

            // Setup a clipping plane.
            var blendAmount = 0.5f;

            // Turn on alpha blending for the transparency to work.
            D3D.TurnOnAlphaBlending();

            // Put the second square model on the graphics pipeline.
            Model2.Render(D3D.DeviceContext);

            // Render the model using the color shader.
            if (!TransparentShader.Render(D3D.DeviceContext, Model2.IndexCount, worldMatrix, viewMatrix, projectionMatrix, Model2.TextureCollection.Select(item => item.TextureResource).ToArray(), blendAmount))
            {
                return(false);
            }

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

            return(true);
        }
Esempio n. 8
0
        public bool Render(int mousePosX, int mousePosY)
        {
            // Clear the buffer to begin the scene.
            D3D.BeginScene(0f, 0f, 0f, 1f);

            // 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;
            var orthoMatrix      = D3D.OrthoMatrix;

            // 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 string.
            if (!Text.Render(D3D.DeviceContext, worldMatrix, orthoMatrix))
            {
                return(false);
            }

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

            // Turn on the Z buffer to begin all 2D rendering.
            D3D.TurnZBufferOn();

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

            return(true);
        }
        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 RenderGraphics()
        {
            // 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, and ortho matrices from the camera and Direct3D objects.
            Matrix worldMatrix      = D3D.WorldMatrix;
            Matrix cameraViewMatrix = Camera.ViewMatrix;
            Matrix projectionMatrix = D3D.ProjectionMatrix;
            Matrix orthoD3DMatrix   = D3D.OrthoMatrix;

            // Get the position of the camera.
            Vector3 cameraPostion = Camera.GetPosition();

            // Translate the sky dome to be centered around the camera position.
            Matrix.Translation(cameraPostion.X, cameraPostion.Y, cameraPostion.Z, out worldMatrix);

            // Turn off back face culling.
            D3D.TurnOffCulling();

            // Turn off the Z buffer.
            D3D.TurnZBufferOff();

            // Render the sky dome using the sky dome shader.
            SkyDome.Render(D3D.DeviceContext);
            if (!SkyDomeShader.Render(D3D.DeviceContext, SkyDome.IndexCount, worldMatrix, cameraViewMatrix, 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, cameraViewMatrix, 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 buffers.
            TerrainModel.Render(D3D.DeviceContext);

            // Render the model using the color shader.
            if (!TerrainShader.Render(D3D.DeviceContext, TerrainModel.IndexCount, worldMatrix, cameraViewMatrix, projectionMatrix, Light.AmbientColor, Light.DiffuseColour, Light.Direction, TerrainModel.Texture.TextureResource))
            {
                return(false);
            }

            //// 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.
            if (!Text.Render(D3D.DeviceContext, worldMatrix, orthoD3DMatrix))
            {
                return(false);
            }

            //// 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);
        }
Esempio n. 11
0
        public bool Render()
        {
            // Clear the buffer to begin the scene.
            D3D.BeginScene(0f, 0f, 0f, 1f);

            // 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;
            var orthoMatrix      = D3D.OrthoMatrix;

            // Construct the frustum.
            Frustum.ConstructFrustum(SystemConfiguration.ScreenDepth, projectionMatrix, viewMatrix);

            // Initialize the count of the models that have been rendered.
            var renderCount = 0;

            Vector3 position;
            Vector4 color;

            // Go through all models and render them only if they can seen by the camera view.
            for (int index = 0; index < ModelList.ModelCount; index++)
            {
                // Get the position and color of the sphere model at this index.
                ModelList.GetData(index, out position, out color);

                // Set the radius of the sphere to 1.0 since this is already known.
                var radius = 1.0f;

                // Check if the sphere model is in the view frustum.
                var renderModel = Frustum.CheckSphere(position, radius);

                // If it can be seen then render it, if not skip this model and check the next sphere.
                if (renderModel)
                {
                    // Move the model to the location it should be rendered at.
                    worldMatrix = Matrix.Translation(position);

                    // Put the model vertex and index buffer on the graphics pipeline to prepare them for drawing.
                    Model.Render(D3D.DeviceContext);

                    // Render the model using the color shader.
                    if (!LightShader.Render(D3D.DeviceContext, Model.IndexCount, worldMatrix, viewMatrix, projectionMatrix, Model.Texture.TextureResource, Light.Direction, Light.AmbientColor, color, Camera.GetPosition(), Light.SpecularColor, Light.SpecularPower))
                    {
                        return(false);
                    }

                    // Reset to the original world matrix.
                    worldMatrix = D3D.WorldMatrix;

                    // Since this model was rendered then increase the count for this frame.
                    renderCount++;
                }
            }

            // Set the number of the models that was actually rendered this frame.
            if (!Text.SetRenderCount(renderCount, D3D.DeviceContext))
            {
                return(false);
            }

            // 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 string.
            if (!Text.Render(D3D.DeviceContext, worldMatrix, orthoMatrix))
            {
                return(false);
            }

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

            // Turn on the Z buffer to begin all 2D rendering.
            D3D.TurnZBufferOn();

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

            return(true);
        }
        private bool Render()
        {
            // Clear the buffers to begin 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, and projection and Ortho matrices from the camera and d3d objects.
            Matrix viewMatrix       = Camera.ViewMatrix;
            Matrix worldMatrix      = D3D.WorldMatrix;
            Matrix projectionMatrix = D3D.ProjectionMatrix;
            Matrix orthoMatrix      = D3D.OrthoMatrix;

            // Translate to the location of the sphere.
            Matrix translatedWorldMatrix = Matrix.Translation(-5.0f, 1.0f, 5.0f);

            worldMatrix = Matrix.Multiply(worldMatrix, translatedWorldMatrix);

            // Render the model using the light shader.
            Model.Render(D3D.DeviceContext);
            if (!LightShader.Render(D3D.DeviceContext, Model.IndexCount, worldMatrix, viewMatrix, projectionMatrix, Model.Texture.TextureResource, Light.Direction))
            {
                return(false);
            }

            // Reset the world matrix.
            worldMatrix = D3D.WorldMatrix;

            // Turn off the Z buffer to begin all 2D rendering.
            D3D.TurnZBufferOff();

            // Turn on alpha blending.
            D3D.TurnOnAlphaBlending();

            // Get the location of the mouse from the input object,
            int mouseX = Input._MouseX;
            int mouseY = Input._MouseY;

            // Render the mouse cursor with the texture shader.
            if (!BitMap.Render(D3D.DeviceContext, mouseX, mouseY))
            {
                return(false);
            }
            if (!TextureShader.Render(D3D.DeviceContext, BitMap.IndexCount, worldMatrix, viewMatrix, orthoMatrix, BitMap.Texture.TextureResource))
            {
                return(false);
            }

            // Render the text strings.
            if (!Text.Render(D3D.DeviceContext, worldMatrix, orthoMatrix))
            {
                return(false);
            }

            // Turn of alpha blending.
            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 Render()
        {
            // Render the depth of the scene to a texture.
            if (!RenderSceneToTexture())
            {
                return(false);
            }

            // Clear the scene to Grey
            D3D.BeginScene(0.0f, 0.5f, 0.8f, 1.0f);

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

            // Generate the light view matrix based on the light's position.
            Light.GenerateViewMatrix();

            // Get the matrices from the camera and d3d objects.
            Matrix viewCameraMatrix = Camera.ViewMatrix;
            Matrix worldMatrix      = D3D.WorldMatrix;
            Matrix projectionMatrix = D3D.ProjectionMatrix;

            // Get the light's view and projection matrices from the light object.
            Matrix lightViewMatrix  = Light.ViewMatrix;
            Matrix lightOrthoMatrix = Light.OrthoMatrix;

            // Set the light color attributes.
            Light.SetDiffuseColor(1.0f, 1.0f, 1.0f, 1.0f);
            Light.SetAmbientColor(0.15f, 0.15f, 0.15f, 1.0f);

            // Translate to the position of the ground model.
            Vector3 groundPosition = GroundModel.GetPosition();

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

            // Render the ground model using the shadow shader.
            GroundModel.Render(D3D.DeviceContext);
            if (!ShadowShader.Render(D3D.DeviceContext, GroundModel.IndexCount, worldMatrix, viewCameraMatrix, projectionMatrix, lightViewMatrix, lightOrthoMatrix, GroundModel.Texture.TextureResource, RenderTexture.ShaderResourceView, Light.Direction, Light.AmbientColor, Light.DiffuseColour))
            {
                return(false);
            }

            // Reset the world matrix.
            worldMatrix = D3D.WorldMatrix;

            // Translate to the position of the tree model.
            Vector3 treePosition = TreeModel.GetPosition();

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

            // Render the tree trunk.
            TreeModel.RenderTrunk(D3D.DeviceContext);
            if (!ShadowShader.Render(D3D.DeviceContext, TreeModel.TrunkIndexCount, worldMatrix, viewCameraMatrix, projectionMatrix, lightViewMatrix, lightOrthoMatrix, TreeModel.TrunkTexture.TextureResource, RenderTexture.ShaderResourceView, Light.Direction, Light.AmbientColor, Light.DiffuseColour))
            {
                return(false);
            }

            // Enable blending and
            D3D.TurnOnAlphaBlending();

            // Render the tree leaves.
            TreeModel.RenderLeaves(D3D.DeviceContext);
            if (!ShadowShader.Render(D3D.DeviceContext, TreeModel.LeafIndexCount, worldMatrix, viewCameraMatrix, projectionMatrix, lightViewMatrix, lightOrthoMatrix, TreeModel.LeafTexture.TextureResource, RenderTexture.ShaderResourceView, Light.Direction, Light.AmbientColor, Light.DiffuseColour))
            {
                return(false);
            }

            // Turn off Alpha Blending.
            D3D.TurnOffAlphaBlending();

            // Reset the world matrix.
            worldMatrix = D3D.WorldMatrix;

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

            return(true);
        }
Esempio n. 14
0
        private bool RenderGraphics()
        {
            // First render the scene to a texture.
            if (!RenderSceneToTexture())
            {
                return(false);
            }

            // 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, and base view matrices from the camera and Direct3D objects.
            Matrix worldMatrix      = D3D.WorldMatrix;
            Matrix cameraViewMatrix = Camera.ViewMatrix;
            Matrix projectionMatrix = D3D.ProjectionMatrix;
            Matrix orthoD3DMatrix   = D3D.OrthoMatrix;
            Matrix baseViewMatrix   = Camera.BaseViewMatrix;

            // Render the terrain buffers.
            TerrainModel.Render(D3D.DeviceContext);

            // Render the terrain using the terrain shader.
            if (!TerrainShader.Render(D3D.DeviceContext, TerrainModel.IndexCount, worldMatrix, cameraViewMatrix, projectionMatrix, Light.AmbientColor, Light.DiffuseColour, Light.Direction, TerrainModel.Texture.TextureResource, TerrainModel.DetailTexture.TextureResource))
            {
                return(false);
            }

            ///// Turn off the Z buffer to begin all 2D rendering.
            D3D.TurnZBufferOff();

            // Put the debug window on the graphics pipeline to prepare it for drawing.
            if (!DebugWindow.Render(D3D.DeviceContext, 100, 60))
            {
                return(false);
            }

            // Render the bitmap model using the texture shader and the render to texture resource.
            if (!TextureShader.Render(D3D.DeviceContext, DebugWindow.IndexCount, worldMatrix, baseViewMatrix, orthoD3DMatrix, RenderTexture.ShaderResourceView))
            {
                return(false);
            }

            // Turn on the alpha blending before rendering the text.
            D3D.TurnOnAlphaBlending();

            // Render the text user interface elements.
            if (!Text.Render(D3D.DeviceContext, worldMatrix, orthoD3DMatrix))
            {
                return(false);
            }

            // 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);
        }