public void Render(IXNAGame _game) { _game.GraphicsDevice.RenderState.DepthBufferEnable = true; ICamera oldCam = game.Camera; game.SetCamera(renderCamera); for (int i = 0; i < renderables.Count; i++) { if (renderables[i].VisibleReferenceCount > 0) { renderables[i].Render(); } } game.SetCamera(oldCam); }
public void BuildReflectMap(Camera mCamera, RenderDelegate renderDelegate) { DepthStencilBuffer oldDS = game.GraphicsDevice.DepthStencilBuffer; game.GraphicsDevice.DepthStencilBuffer = DepthBuffer; /*------------------------------------------------------------------------------------------ * Render to the Reflection Map */ //mGDevice.SetRenderState( RenderStates.ClipPlaneEnable, true ); mGDevice.RenderState.CullMode = CullMode.CullClockwiseFace; // Cull.Clockwise; mGDevice.SetRenderTarget(0, mReflectMap); //ReflectMap.BeginScene(); //ColorValue color = new ColorValue( 0, 0, 0, 0 ); mGDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, new Color((int)(255 * .13f), (int)(255 * .19f), (int)(255 * .22f)), 1.0f, 0); //mGDevice.Clear( ClearFlags.Target | ClearFlags.ZBuffer, Color.FromArgb( (int)( 255 * .13f ), (int)( 255 * .19f ), (int)( 255 * .22f ) ), 1.0f, 0 ); //reflection plane in local space //Plane waterPlaneL = new Plane( 0.0f, -1.0f, 0.0f, 2.7f * 1.5f ); Plane waterPlaneL = new Plane(0.0f, -1.0f, 0.0f, 1f * 1.5f); Matrix wInvTrans = Matrix.Invert(WorldMatrix); wInvTrans = Matrix.Transpose(wInvTrans); //reflection plane in world space Plane waterPlaneW = Plane.Transform(waterPlaneL, wInvTrans); Matrix wvpInvTrans = Matrix.Invert(WorldMatrix * mCamera.ViewProj); wvpInvTrans = Matrix.Transpose(wvpInvTrans); //reflection plane in homogeneous space Plane waterPlaneH = Plane.Transform(waterPlaneL, wvpInvTrans); mGDevice.ClipPlanes[0].IsEnabled = true; //no clue why to use this //mGDevice.ClipPlanes[ 0 ].Plane = waterPlaneH; mGDevice.ClipPlanes[0].Plane = Plane.Transform(waterPlaneL, WorldMatrix * mCamera.ViewProj); Matrix reflMatrix = Matrix.Identity; reflMatrix = Matrix.CreateReflection(waterPlaneW); //mTerrain.ReflectionPass = true; ICamera oldCam = game.Camera; CustomCamera cam = new CustomCamera(game); cam.SetViewProjectionMatrix(reflMatrix * mCamera.View, mCamera.Projection); game.SetCamera(cam); //render scene objects renderDelegate(game); game.SetCamera(oldCam); /*mSkyModel.Render( mGDevice, mCamera, waterPlaneW ); * drawTerrain( false, waterPlaneW ); * * mWater.ReflectMap.EndScene();*/ mGDevice.ClipPlanes.DisableAll(); //mGDevice.SetRenderState( RenderStates.ClipPlaneEnable, false ); //mGDevice.RenderState.CullMode = Cull.CounterClockwise; mGDevice.RenderState.CullMode = CullMode.CullCounterClockwiseFace; // Cull.Clockwise; game.GraphicsDevice.SetRenderTarget(0, null); game.GraphicsDevice.DepthStencilBuffer = oldDS; }