Depth Buffer Test Functions


I am trying to draw a “selection box” comparable to the ones used in RTS games around a 3D object. This is fairly simple using a textured Quad located underneath the 3D object.

Now the tricky part: The selection box has some indicators that should be always visible (e.g. if there is an entrance located at a specific side of a building etc). I want to achieve a transparency effect that allows to see the parts of the selection box that are occluded by the 3D Object shaded in a darker color.

Simple transparency on the 3D object is not sufficient in this case because other parts of the background should not be visible, just the selection box.

The best idea I could come up with was to render the selection box twice:

  • a normal run with with default depth test enabled, this will draw the non occluded parts
  • a second run with an inverted depth test that will only draw the occluded parts using a darker color

    If my research was correct, setting the depth buffer test to greater instead of lessEqual (default behaviour) in the second run should do the trick.

    Is there any possibility to change the depth buffer test function in jme3? The code in LwjglRenderer seems to use a hardcoded call to glDepthFunc(GL_LEQUAL) whenever depth buffer tests are enabled. Or do I have to modify the Renderer?

    Or is there a simpler/other way to achieve the behavior described above?