Skip to content

Support morrowind stenciling (#6443)

The stencil buffer is enabled for main scene, but specifically not the RTTs like water. This enables awesome stencil tricks which fake depth on flat surfaces.

I've pretty much followed an apitrace of Morrowind.exe drawing commands to implement this. Things of note:

  1. I've switched all the primary FBO attachments to a packed depth and stencil instead of purely depth, this means we also need to clear the stencil buffer bit.
  2. This is not behind a setting since it's vanilla morrowind behavior.
  3. If stenciling is enabled, the NIF must be drawn in traversal order, meaning they go in their own render bin. The exception is nodes which end up in the transparent bin, in this case it seems Morrowind sorts these still. I've replicated this behavior. I don't see any way around this, things simply need to be drawn in the order defined in the NIF.
  4. Morrowind ignores the test function in a NiZBufferProperty, but it turns out this is only partially true. When rendering a node with a NiStencilProperty and a NiZBufferProperty, the function is used, but with a fixed function of GL_ALWAYS.
  5. This comment in the nifloader is peculiar. In the trace, the stencil function is GL_ALWAYS as defined in the nif, not GL_NEVER (or rather the DX equivalent).
    case 7: return osg::Stencil::NEVER; // NifSkope says this is GL_ALWAYS, but in MW it's GL_NEVER

An example of a mod using OAAB resources which use stencil trick: https://streamable.com/kionga

Closes #6443 (closed)

Edited by Cody Glassman

Merge request reports