Fighting z-fighting (projective texture mapping)

I’ve noticed that my projective texture shader produces artifacts due to z-fighting on my uber “Mobile Intel® 4 Series Express Chipset Family” GPU.

Since shadow mapping is similar, I tested if the problem also occurs with TestPssmShadow and it does.

I managed to solve this issue either in the SceneProcessor like this


textureMat = new Material(assetManager, “Common/MatDefs/Misc/ProjectiveTextureMapping1pass.j3md”);

textureMat.getAdditionalRenderState().setPolyOffset(-1f, -1f); // prevent z-fighting


or in the corresponding vertex shader like this


gl_Position = g_WorldViewProjectionMatrix * vec4(inPosition, 1.0);

// prevent z-fighting

gl_Position.z *= 0.99999;

gl_Position.z -= 0.00001;


Has anyone experience with this and can tell me which method is preferable? Also, does it have any impacts or side effects? Is it Intel GPU’s fault or do the other GPUs just circumvent this issue? I also wonder if it’s possible to get rid of these ugly transition from shadow to light on the sphere surface in “TestPssmShadow”. My “TestProjectiveTextureMapping” does something similar and doesn’t show such fringes.

It’s a depth buffer precision issue. You probably only have a 8 bit depth buffer on your intel card.

read this, the background color stings the eyes but the information is invaluable :wink:

using polyOffset will solve the issue for nearby objects but far objects will still have it.