# UV interpolation is wrong with a wide FOV

How should I take FOV into account when interpolating UV coordinates? This picture shows the result today. Everything works fine with a narrow fov, but when I make it really wide, things deviate. The black line is expected to be straight. I'm writing a software renderer myself, so I can't just invoke some OpenGL function. Any advice is appreciated.

https://bitbucket.org/jevring/threedee

UV interpolation needs to take into account the depth of the vertices.

You need to perform perspective-correct interpolation, which involves dividing by the w coordinate of the interpolated homogeneous vector.

The "folded plane" effect of affine interpolation becomes more pronounced at wide FOV or when the camera is close to an object, but it's not caused by the wide FOV itself. It's just that narrow views approximate an orthographic camera, which doesn't need perspective correction since it doesn't experience perspective.

Wikipedia gives an equivalent formulation without homogeneous coordinates. if the endpoints you're interpolating have coordinates u_0 and u_1, and an interpolation factor a, then your interpolated u_a lies at

for affine texture mapping,

which becomes

for perspective-correct mapping,

where z_0 and z_1 are the distances of the endpoints from the viewer, along the axis perpendicular to the image plane.

• What's the 'w' coordinate in this context? Mar 7, 2014 at 20:37
• I've added a link to the Wikipedia article on homogeneous coordinates above. In short, it's typical to represent your 3D vertex positions with 4-component vectors, with the 4th component (conventionally called "w") set to 1. This way, transformations including translations and perspective projection can be performed by multiplying the vector by a 4x4 matrix. After projecting the vector in this fashion, the w coordinate of the result contains useful information about the perspective distortion, used for correcting artifacts like the one you're experiencing. Mar 8, 2014 at 1:18
• Unfortunately for me, I don't work with homogenous coordinates, for a variety of reasons. I'm fairly sure that this would be sufficient answer for someone who does, though =) Mar 8, 2014 at 13:09
• Added a version that doesn't use homogeneous coordinates, care of Wikipedia. Mar 8, 2014 at 16:42
• I'm trying that last formula (applied to my code, obviously), but I'm not getting the desired results. Must be something wrong on my end. I'm marking this as solved, as this is no doubt the correct way. I'm just making a mistake somewhere... Mar 8, 2014 at 20:20