<p>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 ?</p>

<p>Thanks guys !</p>

<p>Edit:</p>

<p>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 ? </p>

CC BY-SA 4.0
2019-01-17T00:39:21.650Z
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
CC BY-SA 4.0
2019-01-17T02:56:44.157Z
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
CC BY-SA 4.0
2019-01-17T05:16:51.307Z
Hi @AndrewWilson, your comment looks like an answer to me. I'd suggest you move it as such.
Julien Guertault
CC BY-SA 4.0
2019-01-17T09:42:28.923Z
Perhaps you should look at these posts:
1) https://computergraphics.stackexchange.com/questions/4798/what-happened-to-my-texture-mapping 

2)https://computergraphics.stackexchange.com/questions/4079/perspective-correct-texture-mapping
Simon F
CC BY-SA 4.0
2019-01-17T16:39:23.637Z
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
<texture><mapping>
Why do perspective correction based texture mapping do depth division
toto
# Why do perspective correction based texture mapping do depth division

(Asked by: username_0 on 2019-01-16)

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 ?

**Tags:** texture, mapping

> **Comments:**
> **username_1**: 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.  
> **username_2**: 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.  
> **username_3**: Hi @username_2, your comment looks like an answer to me. I'd suggest you move it as such.  
> **username_4**: Perhaps you should look at these posts: 1) https://computergraphics.stackexchange.com/questions/4798/what-happened-to-my-texture-mapping   2)https://computergraphics.stackexchange.com/questions/4079/perspective-correct-texture-mapping  
> **username_0**: 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 ?  

---

## 0 answers

