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.

Broken UV interpolation



1 Answer 1


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.

Texture mapping approaches

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

Affine texture mapping formula for affine texture mapping,

which becomes

Perspective-correct mapping formula 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.

  • \$\begingroup\$ What's the 'w' coordinate in this context? \$\endgroup\$ Commented Mar 7, 2014 at 20:37
  • 2
    \$\begingroup\$ 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. \$\endgroup\$
    – DMGregory
    Commented Mar 8, 2014 at 1:18
  • \$\begingroup\$ 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 =) \$\endgroup\$ Commented Mar 8, 2014 at 13:09
  • \$\begingroup\$ Added a version that doesn't use homogeneous coordinates, care of Wikipedia. \$\endgroup\$
    – DMGregory
    Commented Mar 8, 2014 at 16:42
  • \$\begingroup\$ 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... \$\endgroup\$ Commented Mar 8, 2014 at 20:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .