Пример #1
0
        public void DrawRefractionMap(Camera camera, RenderRefractionHandler render)
        {
            Vector3 planeNormalDirection = new Vector3(0, -1, 0);

            planeNormalDirection.Normalize();
            Vector4 planeCoefficients = new Vector4(planeNormalDirection, waterHeight);

            Matrix camMatrix    = camera.View * camera.Projection;
            Matrix invCamMatrix = Matrix.Invert(camMatrix);

            invCamMatrix = Matrix.Transpose(invCamMatrix);

            planeCoefficients = Vector4.Transform(planeCoefficients, invCamMatrix);
            Plane refractionClipPlane = new Plane(planeCoefficients);


            //device.SetRenderTarget(0, refractionRT);
            device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1.0f, 0);


            render.Invoke();


            refractionMap = refractionRT.GetTexture();
        }
Пример #2
0
        public void DrawRefraction(GameTime gameTime, RenderRefractionHandler render)
        {
            // Create our Refraction Plane
            Microsoft.Xna.Framework.Plane refractionPlane = Utilitys.CreatePlane(WaterHeight + 20.0f, Vector3.Down, Camera.View, Camera.Projection, false);

            // Setup the graphics Device
            GraphicsDevice.SetRenderTarget(rtRefraction);             // <- render to our RT

            // Clear the back buffer
            GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.Black, 1.0f, 0);

            render.Invoke(gameTime);

            // Remove our render target from our device
            GraphicsDevice.SetRenderTarget(null);

            // Snag our Texture from our RenderTarget
            refractionMap = rtRefraction;

            // For diag just save it to disk
            //refractionMap.Save(AppDomain.CurrentDomain.BaseDirectory + @"\refractionMap.jpg", ImageFileFormat.Jpg);
        }