# negative depth offset ?

i tried to apply negative depth offset to some object, but it had the effect of positive depth offset. i wonder if there is a way to set depth offset of every object to 8 by default, so i can use values under 8 like negative values. or i have to set depth offset on every object that i put into the scene.

Depth offset accumulates; you can setDepthOffset(8) on render and then call setDepthOffset(-8) on a child node of render. Then when Panda traverses the scene graph during rendering, it will add the offsets of the parent node and child node together to form the final depth offset.

thanks.
here’s another question(s):
why the offset values must be integer ? why is the value limited to 0~16 ?
and what is the unit of the value? 1=1 panda unit ? or is it exponential or something ?
why not let us define the offset to 1 meter, 1 feet , 1 inch or something ?

the above questions need not be answered individually, they are in fact one question described in details.
if it’s because of the system design of Panda and difficult to overcome, or it’s for historical reason and so far it’s unnecessary to change, then just ignore the above questions.

edit: i just read the Panda reference about depthOffsetAttrib, it says the value is limited for reason of portability.
but it also states “The bias is always an integer number, and each integer increment represents the smallest possible increment in Z that is sufficient to completely resolve two coplanar polygons.” which is wrong.

any value of offset can “resolve two coplanar polygons” only if the camera is close to the polygons, when the camera is placed further away, the polygons fights harder and harder. the Z-fighting is affected by camera distance, nearclip & farclip values, so any value of depthOffset can’t garentee resolving the problem. that’s why i don’t understand the unit of depthOffset value.
if the offset value has unit of meter or feet, it’s easier to understand and decide.

This is simply a graphics driver feature that we directly expose. We don’t make up the units, or the meaning of the number; this can actually vary from vendor to vendor. We can’t change the unit because graphics APIs don’t have a feature for doing so.

There is a more reliable alternative to a depth offset, which is to tweak the min/max range that depth values are mapped to when written to the depth buffer. You can slightly bias this range so that values will always be written with an offset. The value here is 0-1 in depth buffer values (note that depth buffers aren’t linear), which is more predictable across graphics cards.

``node.setAttrib(DepthOffsetAttrib.make(0, 0.0, 1.0))``