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
Answer
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.
No comments:
Post a Comment