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

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

  • 1
    $\begingroup$ 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). $\endgroup$ Commented Sep 17, 2021 at 19:54

1 Answer 1


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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.