Decal as spatials with stencil buffer


I need to make decaling work. Since land in the game is pretty near far plane, I either have a case of z fighting or decals at the height of character knees. I've read about possibility of using stencil buffer to avoid z fighting, and I've haven't managed to find useful documentation or examples about StencilState, so can someone please help me (possibly with some example code) do that?

hello Mr Denton!

I am not sure if StencilStates work in this Case.

I have made two things for our DecalTrimeshs.

First I check the Location, if there is already a Decal, in not I can create a new one.

As second step, I move the decal 1centimeters to the camera like so:

   public void updateGeometricState(float time, boolean initiator) {
      super.updateGeometricState(time, initiator);

perhabs this works with your decals too.

Greetings, hellG


I'm using this article as reference for that work:

I cannot afford raising decals at a height that fixes zfighting, because then they end at the height of character knees, as I mentioned. On the other hand (since we use near-isometric perspective), zbuffer is not precise enough at the far end to properly test decals against the ground at lower values.


Have you looked at using the Z-Offset?

    public class MyNode extends Node {

        public void draw( final Renderer renderer ) {
            renderer.setPolygonOffset( 1, 4 );
            super.draw( renderer );

No, I haven't but this looks like exact thing I might need. I'll try it out, thanks a lot!