You should take the perspective foreshortening into account. I drew you a small picture illustrating the effect.
As you can see, the difference in eye space depth value of neighboring pixels increases if you move the object to the far plane. This is not the case for an orthogonal projection.
Interesting Sunray, I tried this equation, I actually derived that equation in 99 when I did the Unreal OpenGL work, it gives the same results as the above equation. Same issue with non linear Z. That is to say that I test 2 Z’s that are fairly close together at some fixed epsilon 5-10 units in my case, and they always test positive while far away, and the edges only test positive when I get closer.
NiCo, how would you suggest I deal with foreshortening? Use 2 ranges lerp’d over the depth range?
In light of your application, I doubt there’s a way to handle this correctly. IMHO, the best you can do is test the difference between eyeZ coordinates like you’re doing already. This way, at least the difference in neighboring pixels for fronto-parallel surfaces should remain constant when translating your scene along the camera axis.