Original Post
Hi,
I'm writing a depth only software rasterizer and have a few questions about perspective correct depth interpolation.
Vertex position in homogeneous coordinates in clip space: [x, y, z, w]
Vertex position after projection: [x', y', z'] = [x/w, y/w, z/w]
1. In some articles they say that You should interpolate z/w and 1/w. And later divide it to calculate persp corr depth. Other ones (C. Hecker's texture mapper docs) say that You can just interpolate 1/z'. This two ways lead to two different equations, so what is the correct way?
2. If it's ok to interpolate 1/z', then what to do, when z' is 0? For example DirectX style projection matrix returns z' from [0;1] range. Should I tweak it to have z' in (0;1] range or am I missing something?
I'm writing a depth only software rasterizer and have a few questions about perspective correct depth interpolation.
Vertex position in homogeneous coordinates in clip space: [x, y, z, w]
Vertex position after projection: [x', y', z'] = [x/w, y/w, z/w]
1. In some articles they say that You should interpolate z/w and 1/w. And later divide it to calculate persp corr depth. Other ones (C. Hecker's texture mapper docs) say that You can just interpolate 1/z'. This two ways lead to two different equations, so what is the correct way?
2. If it's ok to interpolate 1/z', then what to do, when z' is 0? For example DirectX style projection matrix returns z' from [0;1] range. Should I tweak it to have z' in (0;1] range or am I missing something?