Hi Everyone,
So, I'm writing a planet-scale renderer, in which I'm implementing Relative-To-Eye method to deal with precision problems; however, the final result doesn't quite match with the traditional rendering path, and I can't figure out why.
I'll put this simple, assuming left-handed system and:
camera = | 0, 0,-2 |
point = | 1, 0, 0 |
worldView = | 1 0 0 0 |
| 0 1 0 0 |
| 0 0 1 0 |
| 1 0 2 1 |
proj = | 1.54 0 0 0 |
| 0 2.41 0 0 |
| 0 0 1.47 1 |
| 0 0 -1.41 0 |
Traditional method:
worldViewProj = | 1.5 0 0 0 |
| 0 2.41 0 0 |
| 0 0 1.47 1 |
| 1.52 0 1.54 2 |
result = float4(point,1) * worldViewProj = | 3 0 1.54 2 |
result_h = | 1.52 0 0.77 1 | // after homogenous divide
Relative To Eye method:
(some computations here happen using double precision)
worldViewRTE = | 1 0 0 0 | // from the original 'worldView' set 4th's row XYZ to 0's
| 0 1 0 0 |
| 0 0 1 0 |
| 0 0 0 1 |
worldViweProjRTE = | 1.5 0 0 0 | // worldViewRTE * proj
| 0 2.4 0 0 |
| 0 0 1.4 1 |
| 0 0 -1.41 0 |
// set point position relative to eye
pointRTE = point - camera = | 1 0 2 |
result = float4(pointRTE,1) * worldViewProjRTE = | 1.54 0 1.54 2 |
result_h = | 0.77 0 0.77 1 | // after homogenous divide
As you can see in the examples above, the RTE method ends up with an X coordinate being half the value of that of the traditional method, when their values should end up being the same (or very close if you take the precision difference into account)…
The method works well if the point is at the origin.. both traditional and RTE values match, but if the point has any axis away from origin, the same half-value mismatch behavior shows up.
Any ideas what could be worong?