Professional Documents
Culture Documents
Perspective-Correct Interpolati - Wei Zhi
Perspective-Correct Interpolati - Wei Zhi
Perspective-Correct Interpolati - Wei Zhi
Kok-Lim Low
Department of Computer Science
University of North Carolina at Chapel Hill
Email: lowk@cs.unc.edu
1
d sZ1
A (X1, Z1), attribute = I1 .
t= (10)
a (u1, d)
sZ1 + (1 − s ) Z 2
x t C (Xt, Zt), attribute = It
s Substituting (10) into (6), we have
c (us, d) line AB
sZ1
–z 1–s
1–t Z t = Z1 + (Z 2 − Z1 ) , (11)
virtual
b (u2, d)
sZ1 + (1 − s ) Z 2
camera
(0, 0) B (X2, Z2), attribute = I2 which can be simplified to
image
plane 1
0 ≤ s ≤ 1, 0 ≤ t ≤ 1 Zt =
1 1 1 (12)
+ s − ⋅
Figure 2: The virtual camera is looking in the +z direction in the Z1 Z 2 Z1
camera coordinate system. The image plane is at a distance of d
in front of the camera. A, B and C are points on the primitive with Equation (12) tells us that the z-value at point c in the image plane
attribute values I1, I2 and It respectively, and their images on the can be correctly derived by just linearly interpolating between
image plane are a, b and c, respectively. s and t are parameters 1/Z1 and 1/Z2, and then compute the reciprocal of the interpolated
used for linear interpolation. result. For z-buffer purpose, the final reciprocal need not even be
computed, because all we need is to reverse the comparison
operation during z-value comparison.
Our objective is to derive formula to correctly interpolate, in the
screen space, the z-values. The same derivation can be directly
applied to the case of a 3D linear primitive projected onto a 2D 3 INTERPOLATING ATTRIBUTE VALUES
image plane.
Here, we want to derive formula to correctly interpolate, in the
Referring to Figure 2, by similar triangles, we have screen space, the other attribute values.
X 1 u1 uZ Refer to Figure 2 again. By linearly interpolating the attribute
= ⇒ X1 = 1 1 , (1)
Z1 d d values across the primitive in the camera coordinate system, we
get
X 2 u2 u Z
= ⇒ X2 = 2 2 , (2) I t = I1 + t ( I 2 − I1 ) . (13)
Z2 d d
Substituting (10) into (13), we have
X t us dX t .
= ⇒ Zt = (3)
Zt d us sZ1
I t = I1 + ( I 2 − I1 ) , (14)
sZ1 + (1 − s ) Z 2
By linearly interpolating in the image plane (or screen space), we
have which can be rearranged into
u s = u1 + s (u 2 − u1 ) . (4) I I I 1 1 1 .
I t = 1 + s 2 − 1 +s
Z − Z (15)
Z Z Z Z
By linearly interpolating across the primitive in the camera 1 2 1 1 2 1
coordinate system, we have
From (12), we can see that the denominator in (15) is just 1/Zt.
X t = X1 + t( X 2 − X1) , (5) Therefore,
Z t = Z1 + t ( Z 2 − Z1 ) , (6) I I I 1 .
I t = 1 + s 2 − 1 (16)
Z Z Z Zt
Substituting (4) and (5) into (3), 1 2 1
d (X 1 + t (X 2 − X 1 )) . What (16) means is that the attribute value at point c in the image
Zt = (7) plane can be correctly derived by just linearly interpolating
u1 + s(u 2 − u1 )
between I1/Z1 and I2/Z2, and then divide the interpolated result by
Substituting (1) and (2) into (7), 1/Zt, which itself can be derived by linear interpolation in the
screen space as shown in (12).
u Z u Z u Z
d 1 1 + t 2 2 − 1 1
d d d
Zt = REFERENCES
u1 + s (u2 − u1 )
u Z + t (u 2 Z 2 − u1 Z1 ) [1] James D. Foley, Andries van Dam, Steven K. Feiner and
= 1 1 ⋅ (8) John F. Hughes. Computer Graphics: Principles and
u1 + s (u 2 − u1 ) Practice, Second Edition. Addison-Wesley, 1990.
Substituting (6) into (8), [2] Mason Woo, Jackie Neider, Tom Davis, Dave Shreiner
u1 Z1 + t (u 2 Z 2 − u1Z 1 ) , (OpenGL Architecture Review Board). OpenGL
Z1 + t ( Z 2 − Z1 ) = (9) Programming Guide, Third Edition: The Official Guide to
u1 + s(u 2 − u1 ) Learning OpenGL, Version 1.2. Addison-Wesley, 1999.
which can be simplified into