private bool Render(float rotation)
        {
            // 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;

            // Rotate the world matrix by the rotation value so that the triangle will spin.
            Matrix.RotationY(rotation, out worldMatrix);

            // 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 (!LightShader.Render(D3D.DeviceContext, Model.IndexCount, worldMatrix, viewMatrix, projectionMatrix, Model.Texture.TextureResource, Light.Direction, Light.DiffuseColour))
            {
                return(false);
            }

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

            return(true);
        }
Пример #2
0
        private bool RenderReflectionScene()
        {
            // Use the camera to render the reflection and create a reflection view matrix.
            Camera.RenderReflection(WaterHeight);

            // Get the camera reflection view matrix instead of the normal view matrix.
            var viewMatrix = Camera.ReflectionViewMatrix;
            // Get the world and projection matrices from the d3d object.
            var worldMatrix      = D3D.WorldMatrix;
            var projectionMatrix = D3D.ProjectionMatrix;

            // Translate to where the bath 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 and the reflection view matrix.
            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);
            }

            return(true);
        }
Пример #3
0
Файл: Sky.cs Проект: ndech/Alpha
 public void Render(DeviceContext deviceContext, Matrix viewMatrix, Matrix projectionMatrix, Light light, ICamera camera)
 {
     _skydome.Render(deviceContext);
     _shader.Render(deviceContext, _skydome.IndexCount,
                    Matrix.Scaling(10000) * Matrix.RotationY(MathUtil.PiOverTwo - _angle / 8), viewMatrix,
                    projectionMatrix, _skydome.Texture, light, camera);
 }
        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;

            // Rotate the world matrix by the rotation value so that the triangle will spin.
            Rotate();

            // Rotate the world matrix by the rotation value so that the triangle will spin.
            Matrix.RotationY(Rotation, out worldMatrix);

            // 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 (!LightShader.Render(D3D.DeviceContext, Model.IndexCount, worldMatrix, viewMatrix, projectionMatrix, Model.TextureCollection.Select(item => item.TextureResource).First(), Light.Direction, Light.DiffuseColour))
            {
                return(false);
            }

            return(true);
        }
Пример #5
0
        public bool RenderLightShader(DeviceContext deviceContext, int indexCount, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix, ShaderResourceView texture, Vector3 lightDirection, Vector4 diffuse)
        {
            // Render the model using the light shader.
            if (!LightShader.Render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture, lightDirection, diffuse))
            {
                return(false);
            }

            return(true);
        }
        public bool RenderLightShader(DeviceContext deviceContext, int indexCount, Matrix worldMatrix, Matrix viewMatrix, Matrix projectionMatrix, ShaderResourceView texture, Vector3 lightDirection, Vector4 ambiant, Vector4 diffuse, Vector3 cameraPosition, Vector4 specular, float specualrPower)
        {
            // Render the model using the light shader.
            if (!LightShader.Render(deviceContext, indexCount, worldMatrix, viewMatrix, projectionMatrix, texture, lightDirection, ambiant, diffuse, cameraPosition, specular, specualrPower))
            {
                return(false);
            }

            return(true);
        }
        private bool Render()
        {
            // Render the depth of the scene to a texture.
            if (!RenderSceneToTexture())
            {
                return(false);
            }

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

            // Get the matrices.
            Matrix worldMatrix          = D3D.WorldMatrix;
            Matrix cameraBaseViewMatrix = Camera.BaseViewMatrix;
            Matrix orthoMatrix          = D3D.OrthoMatrix;

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

            // Put the full screen ortho window vertex and index buffers on the graphics pipeline to prepare them for drawing.
            if (!FullScreenWindow.Render(D3D.DeviceContext))
            {
                return(false);
            }

            // Render the full screen ortho window using the deferred light shader and the render buffers.
            if (!LightShader.Render(D3D.DeviceContext, FullScreenWindow.IndexCount, worldMatrix, cameraBaseViewMatrix, orthoMatrix, DeferredBuffers.ShaderResourceViewArray[0], DeferredBuffers.ShaderResourceViewArray[1], Light.Direction))
            {
                return(false);
            }

            // 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);
        }
Пример #8
0
        private bool Render(float rotation)
        {
            _directX.BeginScene(new Color4(0.1f, 0f, 0f, 1f));

            _camera.Render();

            var viewMatrix       = _camera.ViewMatrix;
            var worldMatrix      = _directX.WorldMatrix;
            var projectionMatrix = _directX.ProjectionMatrix;

            //Matrix.RotationYawPitchRoll(Rotation, Rotation, Rotation, out worldMatrix);
            //Matrix.RotationX(rotation, out worldMatrix);
            //Matrix.RotationY(rotation, out worldMatrix);

            _object.Render(_directX.DeviceContext);

            var translationMatrix = worldMatrix * Matrix.RotationY(rotation) * Matrix.Translation((rotation - 180.0f) / 50.0f, 0.0f, 0.0f);
            var result            = _lightShader.Render(_directX.DeviceContext, _object.IndexCount, translationMatrix, viewMatrix, projectionMatrix, _object.Texture.TextureResource, _light.Direction, _light.DiffuseColour);

            _directX.EndScene();

            return(result);
        }
Пример #9
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);
        }
Пример #10
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;

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