<p>This is to long for a comment so I put it as an answer (but it is really more of a long comment)</p>
<p>Deriving formula for perspective correct texture interpolation : solving for texture coordinate interpolation is the same as solving for any arbitrary attribute interpolation. So you could also title this: Deriving formula for perspective correct interpolation</p>
<p>The diagram is on the right track but all the x's and z's can be confusing to follow. I suggest just giving positions on the diagram plain old points. For example naming points on the triangle p1 and p2, then naming points on the image plain q1 and q2, ect. That makes it a easier/more intuitive to follow the math which would then refer to the individual components. Like <span class="math-container">$q_x$</span> and <span class="math-container">$p_z$</span> for arbitrary points on either plane.</p>
<p>I think the solution is slightly easier to find if you fix s=1 and compute d (sometimes called the focal length). This corresponds better to a standard projection matrix as well.</p>

CC BY-SA 4.0
2021-09-17T15:26:24.267Z
2021-09-17T15:26:24.267Z
pmw1234
<p>I am trying to derive the formula for perspective correct texture interpolation on my own while implementing my own software rasterizer (projecting an arbitrarily rotated triangle in camera space on the projection plane and rasterize its texture). Sure, the solution is that one can interpolate the inverse of z in the projection plane (or screen space). However, given the assumption that I do not know that yet, all I came up with so far is the following:</p>
<p><a href="https://i.sstatic.net/FsW63.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/FsW63.png" alt="enter image description here" /></a></p>
<p>My first step was to formulate the problem (maybe my problem statement is the problem?) and visualize it. Then I tried to find some relations between the variables.</p>
<p>What I am now looking for is some hint / observation that leads to right direction (not the solution).</p>

CC BY-SA 4.0
2021-09-17T19:54:22.310Z
It may help if you try to express things in terms of deltas, like $\Delta x = (x_t - x_1)$ and $\Delta x' = (x'_s - x'_1)$. Also try to bring in the slope of z with respect to x, $\Delta z / \Delta x$ (which is a constant all along the triangle).
Nathan Reed
<texture><mathematics><perspective><interpolation><mapping>
Deriving formula for perspective correct interpolation
Sam
# Deriving formula for perspective correct interpolation

(Asked by: username_0 on 2021-09-17)

I am trying to derive the formula for perspective correct texture interpolation on my own while implementing my own software rasterizer (projecting an arbitrarily rotated triangle in camera space on the projection plane and rasterize its texture). Sure, the solution is that one can interpolate the inverse of z in the projection plane (or screen space). However, given the assumption that I do not know that yet, all I came up with so far is the following:

[![enter image description here](https://i.sstatic.net/FsW63.png)](https://i.sstatic.net/FsW63.png)

My first step was to formulate the problem (maybe my problem statement is the problem?) and visualize it. Then I tried to find some relations between the variables.

What I am now looking for is some hint / observation that leads to right direction (not the solution).

**Tags:** texture, mathematics, perspective, interpolation, mapping

> **Comments:**
> **username_1**: It may help if you try to express things in terms of deltas, like $\Delta x = (x_t - x_1)$ and $\Delta x' = (x'_s - x'_1)$. Also try to bring in the slope of z with respect to x, $\Delta z / \Delta x$ (which is a constant all along the triangle).  

---

## 1 answers

### Answer by username_2 on 2021-09-17. Score: 2

This is to long for a comment so I put it as an answer (but it is really more of a long comment)

Deriving formula for perspective correct texture interpolation : solving for texture coordinate interpolation is the same as solving for any arbitrary attribute interpolation. So you could also title this: Deriving formula for perspective correct interpolation

The diagram is on the right track but all the x's and z's can be confusing to follow. I suggest just giving positions on the diagram plain old points. For example naming points on the triangle p1 and p2, then naming points on the image plain q1 and q2, ect. That makes it a easier/more intuitive to follow the math which would then refer to the individual components. Like $q\_x$ and $p\_z$ for arbitrary points on either plane.

I think the solution is slightly easier to find if you fix s=1 and compute d (sometimes called the focal length). This corresponds better to a standard projection matrix as well.


---

