How to use LESS rather than LEQUAL for depth test?

It seems playcanvas is using FUNC_LESSEQUAL for depth testing. How can I overwrite this for a material to use FUNC_LESS instead?

If this is not possible, could this please be added (optimally to have full depth test control per material)

yes these are currently missing, I came across this few times in the past … and so I’ve created a ticket to track the implementation: https://github.com/playcanvas/engine/issues/4093

At the moment you could build custom engine with all the related complexities, or you could monkey patch this function: https://github.com/playcanvas/engine/blob/d95908bbafd5b3a3e79cde3171942a1b364a9ec6/src/graphics/webgl/webgl-graphics-device.js#L2064-L2068

2 Likes

I created a pull request.

However, would be great if someone could doublecheck it, because it removes the following lines which do not seem to really make sense to me:

                    // this fixes the case where the user wishes to turn off depth testing but wants to write depth
                    if (material.depthWrite && !material.depthTest) {
                        device.setDepthFunc(FUNC_ALWAYS);
                        device.setDepthTest(true);
                    } else {
                        device.setDepthFunc(FUNC_LESSEQUAL);
                        device.setDepthTest(material.depthTest);
                    }

this should not be necessary as the following should be equivalent:

device.setDepthTest(material.depthTest);
device.setDepthWrite(material.depthWrite);

I don’t see why having depthWrite = true and depthTest = false would require to enable depthTest and set depthFunc to FUNC_ALWAYS, since depthFunc FUNC_ALWAYS should be equivalent to depthTest disabled (unless this is working around some bug somewhere).

1 Like

Oh never mind, I found the corresponding section in the GL specification:

"
4.1.6 Depth Buffer Test

The depth buffer test discards the incoming fragment if a depth comparison fails.The comparison is enabled or disabled with the generic Enable and Disable commands using the symbolic constant DEPTH TEST.

When disabled, the depth comparison and subsequent possible updates to the depth buffer value are bypassed and the fragment is passed to the next operation.
"

edit: I re-added the fix, now it should not change the behavior of existing code in any way.

1 Like