Render layering with specific depth hierarchy

Do you still have the depth test set to M_always when rendering the torus? You still need to do that for this trick to work, but doing that will bring up the self-occlusion problem again, so in that sense using display regions doesn’t really help you directly.

If you want the torus to render with correct depth testing to handle the self-occlusion problem more generally, you might try this method instead, which does require ordering using at least 2 display regions because it involves clearing the depth buffer:

  • Render the set
  • Render the cube
  • Clear the depth buffer
  • Render the cube to the depth buffer only, using setAttrib(ColorWriteAttrib.make(ColorWriteAttrib.C_off))
  • Render the torus

Maybe this would work? It makes sure that the cube will be rendered depth-tested against the set, and that the torus will be rendered depth-tested against the cube but not the set, and everything is still depth-testing against itself properly.

Alternatively, you could try the stencil buffer (which doesn’t need multiple display regions), maybe something like this:

  • Enable stencil buffer using framebuffer-stencil true in Config.prc and stencil-bits 1
  • Render the torus first, with a StencilAttrib that writes a 1 to the stencil buffer.
  • Render the set, with a StencilAttrib that discards the pixel if the stencil buffer contains 0.
  • Render the cube.
1 Like