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