コード例 #1
0
        public void DrawReflectionMap(Camera camera, RenderReflectionHandler render)
        {
            reflectionViewMatrix = ((FreeCamera)camera).UpdateReflectiveMatrices();
            float   reflectionCamYCoord   = -camera.Position.Y + (waterHeight * 2);
            Vector3 reflectionCamPosition = new Vector3(camera.Position.X, reflectionCamYCoord, camera.Position.Z);

            Vector3 planeNormalDirection = new Vector3(0, 1, 0);

            planeNormalDirection.Normalize();
            Vector4 planeCoefficients = new Vector4(planeNormalDirection, -3f);

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

            invCamMatrix = Matrix.Transpose(invCamMatrix);

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

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


            render.Invoke(reflectionViewMatrix, reflectionCamPosition);

            device.SetRenderTarget(0, null);
            reflectionMap = reflectionRT.GetTexture();

            device.ClipPlanes[0].IsEnabled = false;
        }
コード例 #2
0
        public void DrawReflection(GameTime gameTime, RenderReflectionHandler render)
        {
            Microsoft.Xna.Framework.Plane reflectionPlane = Utilitys.CreatePlane(WaterHeight - 0.5f, Vector3.Down, ReflectionViewMatrix, Camera.Projection, true);

            // Setup the Graphics Device
            GraphicsDevice.SetRenderTarget(rtReflection);

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

            // Draw anything that should reflect onto the water
            render.Invoke(ReflectionViewMatrix, Camera.Position, gameTime);

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

            // Snag our Texture from our RenderTarget
            reflectionMap = rtReflection;

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