OGRE
1.12.13
Object-Oriented Graphics Rendering Engine
|
By default Ogre is using the standard depth setup, which results in a hyperbolical depth value distribution. This means that there is a high depth resolution close to the near plane, while objects far from the near-plane are likely to experience z-fighting.
This typically occurs if you try to render large outdoor scenes, where you have objects very close to the camera, like grass-leaves, as well as objects very far away that all have their separate depth.
To mitigate this problem, Ogre allows you to use a reversed floating-point Z-Buffer, that results in an approximately linear depth value distribution. To use this, enable the "Reversed Z-Buffer"
RenderSystem option.
This will make Ogre use the [1; 0]
range for depth values instead of the standard [0; 1]
range.
However, we also have to use a floating-point depth buffer to get any benefit from that. This is a little bit tricky, as e.g. OpenGL is very restrictive on the main depth-buffer therefore unlikely to allow you to using a floating point buffer there.
Therefore, we will use an off-screen texture for rendering, where we can easily use a floating-point depth buffer and only copy the results to the screen.
For this you can use the following Compositor script:
If reversed depth is enabled, Ogre will automatically assign a floating point buffer here.
See Applying a Compositor, for how to set that compositor on your main window.
OffscreenRender
is the first compositor in the Ogre::CompositorChain.As we only render a full-screen quad to our main window, we should tell Ogre that we do not need a depth buffer for it. We do this as:
OGRE_REVERSED_Z
define, to discover whether reversed depth is enabled.