# Why do perspective correction based texture mapping do depth division

I'm currently trying to understand how works perspective correction texture mapping. I saw that actually it works by interpolating the z value of the three point of the triangle which the current rendered pixel is in, then, it divide the u and v affine texture coordinates by the interpolated z value in order to get the perspective corrected values of u and v. I really can't wrap my head around this division by z to do perspective correction. Can someone explain me the point and the math behind it which makes it do the job ?

Thanks guys !

Edit:

Okay, after reading your advices guys, i dived into perspective correction algorithm. I think i have understood what is done, but i want to expose it to you in order to see if it the right way to think. When rendering pixels on screen you're in raster space, if you interpolate u and v values you will get affine texturing cause it does not take into account depth of the vertices. The solution is to do so : working in a "specific space" of three dimensions : (u,v,z). Each vertices can be represented in this space cause it have u and v tex coordinates and a z coordinate. The idea is the following : you divide each u and v component of the vertices by z. The effect will be a perspective projection on the plane defined by the equation 0*u + 0*v + 1*z = 1. Doing so makes us able to do interpolation into raster space. Then, when we want to get the perspective corrected texel for a specific pixel of the current renderer triangle in raster space, we just have to multiply the interpolated u/z and v/z by interplated z (actually the algorithm divide u/z and v/z by interpolated 1/z which leads exacly to a multiplication by interpolated z). But this multiplication by interpolated z can be viewed as a scalar which multiplies the interpolated vector (u/z, v/z, 1) which will put back the vector from the plane at z=1 to the right place into the original three dimensions space giving us the u and v coordinates interpolated into the three dimension space, taking into account the z coordinates and leading to a correct perspective corrected texture mapping. Am i right ?

• First question: do you understand what perspective-correct texture mapping is trying to accomplish? I'm not being snide; I need to know where to start in explaining the process, because if you say "yes", I can basically summarize about half of what I would otherwise have to spell out. – Nicol Bolas Jan 17 '19 at 0:39
• Well the points used for interpolation when filling a triangle are not the points of the actual triangle. They're the points of the projected triangle which has been flattened. The triangle that has been z divided. IE: It's point x,y,z is basically now x/z, y/z, 1. (not quite because the typical perspective transform has a bit more too it than that, but that's the general idea). Also z is not interpolated. 1/z is interpolated and 1/(1/interpolated z) is used in the divide. – Andrew Wilson Jan 17 '19 at 2:56
• Hi @AndrewWilson, your comment looks like an answer to me. I'd suggest you move it as such. – Julien Guertault Jan 17 '19 at 5:16
• Perhaps you should look at these posts: 1) computergraphics.stackexchange.com/questions/4798/… 2)computergraphics.stackexchange.com/questions/4079/… – Simon F Jan 17 '19 at 9:42
• Ok guys, i've just added an edit section in my original message to explain what i understood from the perspective texture mapping. Can you guys read it and tell me if i'm right about it ? – toto Jan 17 '19 at 16:39