Home > 未分类 > W分量与texldp

W分量与texldp

在将RenderTarget反贴到场景上时,需要使用WorldViewProj矩阵乘以如下的trafoMatrix:
      0.5f       0        0         0
      0           -0.5f   0         0
      0           0        0         0
      0.5f       0.5f     0        1
以将(x,y)范围在(-1,-1)~(1,1)的投影后坐标变换到纹理UV空间。然而,直接用m4x4变换顶点的结果Vector4中w分量不为1,而x、y值只有在W归一化后才能落在正确的(-1,-1)~(1,1)范围内。此时在顶点着色器中变换:
//vs_2_0
//dcl_position v0
//c4~c8: world*View*Proj*trafo
m4x4  r0, v0, c4
rcp      r0.w, r0.w
mul     r0.xy, r0.xy, r0.ww
mov    oT0, r0
随后在像素着色器直接取址:
//ps_2_0
//SetTexture(0, renderedTexture)
texld   r0, t0, s0
很遗憾,结果是错误的。因为UV插值对W分量来说不是线性的(?),因此除了顶点处的x、y值是正确的以外,三角形内部的UV值是变形的。正确的做法是将t0的四个分量都留下,在像素插值后使用texldp取样,texldp指令会用x、y分量分别除以w分量后的值进行寻址:
//vs
m4x4  r0, v0, c4
mov    oT0, r0
//ps
texldp   r0, t0, s0
、、
OK…
 
Advertisements
Categories: 未分类
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: