Today I fixed the cube texture warping:
The perspective correction uses interpolated Z values to do a sort of perspective divide in the texture space. I don’t entirely understand how it works yet, so I’ll add a note here if this is all wrong.
Here’s what I have so far: The problem is that the texture doesn’t respond to perspective shifts: it’s always mapped as if the triangle is facing the screen. The idea is to change the texture mapping so that it accounts for the perspective shift. The method of doing that is interpolating the Z values of each point in the triangle and using them to adjust the UV values. The problem is that the Z values of each point aren’t linear across the triangle, so using barycentric coordinates directly on the Z values won’t work. However, the reciprocal of Z is linear. So I can instead interpolate with the the reciprocal of Z using barycentric coordinates. Then dividing the U and V values by the interpolated Z value yields the perspective corrected UV values.
I’ll review perspective correction again tomorrow to understand it better. See you then!
Your data is processed in accordance with my privacy policy. Comments are manually approved and may take a while to appear.