Wednesday, October 30, 2019

textures - 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.


Broken UV interpolation


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.


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.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...