To interpolate between perspective and orthographic projection I'm using the following formula (which works great because the clipping planes align perfectly):
X' = rw + X / ((Z * fwi - ox) * (1f - a) + ox);
Y' = rh + Y / ((Z * fhi - oy) * (1f - a) + oy);
Where:
rw or rh is (renderWidth or Height - 1) / 2f,
ox is vSize / rw, oy is hSize / rh,
fwi is tan(vFOV/2) / rw, fhi is tan(hFOV/2) / rh,
a is lerp coefficient; 0 = perspective, 1 = orthographic, 0.5 = in between.
Now to correctly calculate the Z depth in for each fragment, I'm calculating z = 1/z before interpolating it in screen space via a ScanLine function, and finally calculating the true depth at the end via 1/z.
However orthographic projection does not require this depth correction, so I was wondering whats the correct way to determine the true Z, when the projection is being blended. The current XYZ to XY formula can be summarized via:
Currently I'm interpolating UV coords via the Depth and it is clearly incorrect when the projection is in between perspective and orthographic. When it reaches 1, it bypasses the 1/z depth correction.
Please note that this is a software renderer, so performance is quite important. Ideally I would like to be doing the same thing OpenGL is doing in these types of situations.

