how precision is increased by inverting the numerators and denominators

stagger

New member
Joined
Jul 19, 2020
Messages
4
In graphics programing, we calculate the depth of a pixel by:

depth = z-min/(max-min) where, min and max are the minimum and maximum values for the value of z ,

But, it is said( here)since we need more precision for values of z near min than max, we use the following form of the formula:
depth = (1/z)-(1/near)/( (1/far)-(1/near) )

I quite don't get how this formula was derived. Could I be given some insight or derviation to this, please?
 
In graphics programming, we calculate the depth of a pixel by:

depth = z-min/(max-min) where, min and max are the minimum and maximum values for the value of z ,

But, it is said( here)since we need more precision for values of z near min than max, we use the following form of the formula:
depth = (1/z)-(1/near)/( (1/far)-(1/near) )

I quite don't get how this formula was derived. Could I be given some insight or derivation to this, please?
I am assuming that the first formula you meant to present was:

\(\displaystyle depth \ = \ \frac{z - min}{max - min}\) .....................................................................(1)

which should have been written as depth = (z - min) / (max - min)

Those parentheses in the numerator (and the denominator) are very important to convey correct order of operations. The second equation being:

\(\displaystyle depth \ = \ \frac{\frac{1}{z} - \frac{1}{near}}{\frac{1}{far} - \frac{1}{near}}\) .....................................................................(2)

In equation (1) you have variables 'min' and 'max' - where as in equation (2) you have variables 'far' and 'near'.

How are those related?
 
In graphics programing, we calculate the depth of a pixel by:

depth = z-min/(max-min) where, min and max are the minimum and maximum values for the value of z ,

But, it is said( here)since we need more precision for values of z near min than max, we use the following form of the formula:
depth = (1/z)-(1/near)/( (1/far)-(1/near) )

I quite don't get how this formula was derived. Could I be given some insight or derviation to this, please?
They tell you clearly that this is a different function than the first one. They are not meant to be equivalent.

Each is meant to be a transformation from an interval [near, far] to [0, 1], and that is all that matters. They chose this one because it has better properties for their purposes:

In practice however, a linear depth buffer like this is almost never used. Because of projection properties a non-linear depth equation is used that is proportional to 1/z. The result is that we get enormous precision when z is small and much less precision when z is far away.​

Specifically, they are applying the same linear transformation represented by the first equation [which you changed to use min and max where they used near and far], to 1/z rather than to z itself. They replaced z, near, and far with 1/z, 1/near, and 1/far.
 
I am assuming that the first formula you meant to present was:

\(\displaystyle depth \ = \ \frac{z - min}{max - min}\) .....................................................................(1)

which should have been written as depth = (z - min) / (max - min)

Those parentheses in the numerator (and the denominator) are very important to convey correct order of operations. The second equation being:

\(\displaystyle depth \ = \ \frac{\frac{1}{z} - \frac{1}{near}}{\frac{1}{far} - \frac{1}{near}}\) .....................................................................(2)

In equation (1) you have variables 'min' and 'max' - where as in equation (2) you have variables 'far' and 'near'.

How are those related?
really sorry for the typo, but I meant min=near and max=far , I just changed them for convienience of explaining.
 
Top