Depth test must be applied again after setting DepthTestAttrib?

I’ve encountered a strange behaviour related to depth testing :

If I set an explicit depth test attrib on a root node (e.g. render.set_attrib(DepthTestAttrib.make(DepthTestAttrib.M_less_equal)) ), it seems that some child nodes no longer have depth test enabled, and they start appearing in front of other object though they should be hidden or clipped.

If after setting the depth test attrib, I explicitly enable depth testing on that root node using set_depth_test(True), the children nodes are correctly using depth testing. Also, if I don’t set the depth test attrib, the scene looks fine too.

Could this be a bug, or a not documented behaviour, or a mistake from me ?

Mmmh, after trying to do a minimal reproducible example it seems the depth test attrib is merely one of the triggers of the problem.

The actual problem looks like to be due to the composition of all the transforms in the scene tree for the problematic nodes, if I apply the net transform on each node directly (instead of having shared parents) there are no more z-fight. Now I have to find why :slight_smile:

Found the problem and it was indeed in my code :stuck_out_tongue:

For those interested, I’m using a dedicated display region and camera for the objects that are close to the viewer in order to not spread the depth buffer over too large a range.
But this means that each node must have the correct camera mask to be rendered in the correct display region. This was not the case for the problematic node and so it was rendered twice on itself, hence the z-fighting and the change of behaviour when changing the depth test. In retrospect this was obvious but I had my assumptions completely wrong !

1 Like