<p>The way homogeneous coordinates (x, y, z, w) work is that if you multiply the vector by any nonzero value, it still represents the same point in 3D projective space. These different xyzw representations of the same point are all considered equivalent to each other: one is just as good as another. The point (1, 2, 3, 4) is the same as the point (2, 4, 6, 8), or (−1, −2, −3, −4), etc.</p>
<p>For converting back from projective space to the ordinary 3D space embedded in it, it's convenient to normalize to w = 1. That's all that the division by w is really doing. It's not part of the transformation per se.</p>
<p>It's a lot like normalizing a vector, by dividing it by its magnitude. It still points the same direction, but it's convenient for later calculations to ensure it has length 1 (in cases where the direction is the thing you care about and the length doesn't matter).</p>
<p>Just as you might normalize a direction vector after passing it through some 3D transformations, you can &quot;normalize&quot; projective points represented by homogeneous coordinates, after passing them through some projective transformations, to restore them to w = 1.</p>
<p>The 4×4 matrix is the actual projective transformation, and the inverse transformation is just given by the matrix inverse. Recovering the exact original w value before transformation is meaningless, and isn't possible anyway since the division by w loses that information—just as normalizing a direction vector loses the information about its original length, but that's ok since the length wasn't relevant anyway.</p>

CC BY-SA 4.0
2021-07-28T21:05:45.797Z
2021-07-28T21:05:45.797Z
Nathan Reed
<p>For example, when you want to compute the world space position of a fragment in the fragment shader, you can construct the fragment's NDC coordinates, then multiply by the inverse of whatever transform was used on the triangle that was rasterized to that fragment.</p>
<p>And when this reverse process includes some projective transformation, you have to divide by w after doing that multiplication. Just like if you did the forward process.</p>
<p>But why? My intuition would be that you instead multiply by w (the original one for the fragment, which is stored in e.g. gl_FragCoord.w as 1/w) before applying the transformation, or something like that.</p>
<p>It kind of makes sense that you have to do a perspective divide after applying the inverse projection transform - after all it's going to alter the x,y,z and w components of the result in projecty ways, but I don't understand why this would then correctly give you back the original world space position for the fragment instead of an arbitrary result.</p>

<transformations><perspective>
Why perspective division ( div by w) when applying the inverse to a perspective transformation?
cg_guy420
# Why perspective division ( div by w) when applying the inverse to a perspective transformation?

(Asked by: username_0 on 2021-07-28)

For example, when you want to compute the world space position of a fragment in the fragment shader, you can construct the fragment's NDC coordinates, then multiply by the inverse of whatever transform was used on the triangle that was rasterized to that fragment.

And when this reverse process includes some projective transformation, you have to divide by w after doing that multiplication. Just like if you did the forward process.

But why? My intuition would be that you instead multiply by w (the original one for the fragment, which is stored in e.g. gl\_FragCoord.w as 1/w) before applying the transformation, or something like that.

It kind of makes sense that you have to do a perspective divide after applying the inverse projection transform - after all it's going to alter the x,y,z and w components of the result in projecty ways, but I don't understand why this would then correctly give you back the original world space position for the fragment instead of an arbitrary result.

**Tags:** transformations, perspective


---

## 1 answers

### Answer by username_1 on 2021-07-28. Score: 3 | Accepted answer

The way homogeneous coordinates (x, y, z, w) work is that if you multiply the vector by any nonzero value, it still represents the same point in 3D projective space. These different xyzw representations of the same point are all considered equivalent to each other: one is just as good as another. The point (1, 2, 3, 4) is the same as the point (2, 4, 6, 8), or (−1, −2, −3, −4), etc.

For converting back from projective space to the ordinary 3D space embedded in it, it's convenient to normalize to w = 1. That's all that the division by w is really doing. It's not part of the transformation per se.

It's a lot like normalizing a vector, by dividing it by its magnitude. It still points the same direction, but it's convenient for later calculations to ensure it has length 1 (in cases where the direction is the thing you care about and the length doesn't matter).

Just as you might normalize a direction vector after passing it through some 3D transformations, you can "normalize" projective points represented by homogeneous coordinates, after passing them through some projective transformations, to restore them to w = 1.

The 4×4 matrix is the actual projective transformation, and the inverse transformation is just given by the matrix inverse. Recovering the exact original w value before transformation is meaningless, and isn't possible anyway since the division by w loses that information—just as normalizing a direction vector loses the information about its original length, but that's ok since the length wasn't relevant anyway.


---

