示例#1
0
        /// <summary>
        /// This renders the refraction map;
        /// </summary>
        private void DrawRefractionMap(GraphicsDevice device, Camera camera, RenderSceneDelegate RenderScene)
        {
            // Clipping computations will be done after vertices have passed through the vertex shader and are in screen space. We must therefore represent the clipping planes
            // screen space as well, which is achieved by multiplying the plane coefficients by the view and projection matrices.

            Vector4 refractionPlaneCoefficients = new Vector4(0.0f, 1.0f, 0.0f, -waterHeight);
            refractionPlaneCoefficients = Vector4.Transform(refractionPlaneCoefficients, Matrix.Transpose(Matrix.Invert(camera.ViewMatrix * camera.ProjMatrix)));

            refractionClippingPlane = new Plane(refractionPlaneCoefficients);

            // Prepare the device for rendering to the desired render target

            device.ClipPlanes[0].Plane = refractionClippingPlane;
            device.ClipPlanes[0].IsEnabled = true;
            device.SetRenderTarget(0, refractionRenderTarget);
            device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1.0f, 0);

            // Render the scene with clipping

            RenderScene();

            // Now disable the clipping plane and save the result to a texture

            device.ClipPlanes[0].IsEnabled = false;
            device.SetRenderTarget(0, null);
            refractionMap = refractionRenderTarget.GetTexture();
        }
示例#2
0
        /// <summary>
        /// This renders the refraction map;
        /// </summary>
        private void DrawRefractionMap(GraphicsDevice device, Camera camera, RenderSceneDelegate RenderScene)
        {
            // Clipping computations will be done after vertices have passed through the vertex shader and are in screen space. We must therefore represent the clipping planes
            // screen space as well, which is achieved by multiplying the plane coefficients by the view and projection matrices.

            Vector4 refractionPlaneCoefficients = new Vector4(0.0f, 1.0f, 0.0f, -waterHeight);

            refractionPlaneCoefficients = Vector4.Transform(refractionPlaneCoefficients, Matrix.Transpose(Matrix.Invert(camera.ViewMatrix * camera.ProjMatrix)));

            refractionClippingPlane = new Plane(refractionPlaneCoefficients);

            // Prepare the device for rendering to the desired render target

            device.ClipPlanes[0].Plane     = refractionClippingPlane;
            device.ClipPlanes[0].IsEnabled = true;
            device.SetRenderTarget(0, refractionRenderTarget);
            device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1.0f, 0);

            // Render the scene with clipping

            RenderScene();

            // Now disable the clipping plane and save the result to a texture

            device.ClipPlanes[0].IsEnabled = false;
            device.SetRenderTarget(0, null);
            refractionMap = refractionRenderTarget.GetTexture();
        }
示例#3
0
        /// <summary>
        /// This draws the scene with reflective and refractive water. It takes a delegate function to perform the actual scene rendering needed to construct the refraction
        /// and reflection maps.
        /// </summary>
        /// <param name="camera"></param>
        public void Draw(Camera camera, RenderSceneDelegate RenderScene)
        {
            GraphicsDevice graphicsDevice = game.GraphicsDevice;

            // Render the refraction and reflection maps

            DrawRefractionMap(graphicsDevice, camera, RenderScene);
        }
示例#4
0
        /// <summary>
        /// This draws the scene with reflective and refractive water. It takes a delegate function to perform the actual scene rendering needed to construct the refraction
        /// and reflection maps.
        /// </summary>
        /// <param name="camera"></param>
        public void Draw(Camera camera, RenderSceneDelegate RenderScene)
        {
            GraphicsDevice graphicsDevice = game.GraphicsDevice;

            // Render the refraction and reflection maps

            DrawRefractionMap(graphicsDevice, camera, RenderScene);
        }