Ejemplo n.º 1
0
        private bool RenderRefractionScene()
        {
            // Setup a clipping plane based on the height of the water to clip everything above it.
            var clipPlane = new Vector4(0f, -1f, 0f, WaterHeight + 0.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;

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

            return(true);
        }
Ejemplo n.º 2
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);
        }