Perspective-Correct Interpolation

本文探讨了3D游戏中三角形表面正确插值的重要性,并通过数学推导证明了z坐标的倒数和顶点属性值b/z在线性方式下进行插值的正确性。文中还解释了硬件如何实现这一过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  

(quote from "Mathematics for 3D Game Programming and Computer Graphics Third Edition")

  As the figure above showing,correct interpolation across the face of a triangle is not linear since equally spaced steps taken on the projection plane correspond to larger steps taken on the face of a triangle as the distance from the camera increases.

  What follows in this passage will prove that the reciprocal of the z coordinate is correctly interpolated in a linear manner across the face of a triangle ,so is b/z( b is a vertex attribute value,like texcoord and so on).

  So hardware first linearly interpolate 1/z when rasterizing a scanline(obtain the depth of each pixel),then linearly interpolate b/z to obtain the perspective-correct interpolated value of any vertex attribute b. 

 

Proof:

  Depth Interpolation:

  Assuming that the segment(represent a triangle) does not belong to  a line that passes through the origin, so it is visible( imaging that put a setsquare edge-on in front of you, then you can not tell whether it is a line or a setsquare).Then we can describe the line with the equation

ax+bz = c,where c != 0( equation 1,reference to the figure above).

  Using similar triangles,we can derived the follow relationship.

(equation 2)

  Assume that we konw the two endpoints of the line segment{(x1,z1),(x2,z2)} and their image on the projection plane{(p1,-e),(p2,-e)}(correspond to pixel 1 and pixel 2).Let

p3 = (1-t)p1 + t*p2(0<=t<=1)    (eq 3)

conbining equation 1, 2 and 3, we can find the z coordinate of the point(x3,z3),where the ray cast through the point (p3,-e)intersects the face of the triangle.That is:

   (eq 4)

 

Vertex Attribute Interpolation:

    We would expect the interpolated attribute value b3 to form the same proportion with the total difference along the line segment as does the interpolated depth value z3. ( b1,b2 is the vertex attribute values of the two endpoints{(x1,z1),(x2,z2)} of the line segment )That is, the equation

 (eq 5)

  combining eq 4,5, we can finally get the equation

 

 

 

  PS:Perspective-Correct Interpolation is now implemented by hardware!!!

转载于:https://www.cnblogs.com/swdever/p/3360409.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值