Calculate object distance by 2D coordinates only,
Members - Reputation: 497
Posted 22 May 2012 - 08:55 AM
I'm looking for an EASY way to calculate the approximate distance from the camera to an object (in 3D world space) whose ground surface starts at a specific y-coordinate in 2D screen space (in a pure pixel shader).
It's sufficient for a start to assume that the viewer and the object in question both are located on a flat horizontal plane and the eye direction is horizontally parallel to that plane.
Most articles I found do complex matrix transformations which is way over the top in my opinion. There must be a simple formula instead in the form object_distance = myfunction(uv.y) where uv is the current screen texel coordinate. I'm fairly sure it's some polynomial function but I didn't find the exact factors / exponent for it.