float3 vScreenPos = In.ClipPos.xyz;
vScreenPos /= In.ClipPos.w;
vScreenPos.xy += 1.f;
vScreenPos.xy *= 0.5f;
vScreenPos.y = 1.f - vScreenPos.y;
这个是shader里从vertex最后那个pos 里取 uv的算法
pos是指经过了 world view proj的变换得到的 齐次坐标(x,y,z,w)
我之前 一直不明白 为什么 要xy/w
后来 我认为是这样的 齐次坐标系 是为了 将 P‘=M1 *P+M2 (点P P' 变换矩阵M1 M2)
这种变换 统一到 一个矩阵里表示 就加了一维 使其 把变换统一到 相乘
进行 world view 变换时 w那里一直是一所以可以把 xyz1->xyz想成空间中的点 做各种变换
但是 proj之后 w就不是1了 好像 world view 时M2的系数是1 proj时 M2的系数不是1了(这里表述不严谨 大体是这个意思)
这样 就不能再把 点*Matrix的点当成 空间中对应位置的点 来想象 位置了 这步 就只是个计算 所以最后 要把w除去 以把P‘单独 提出来
/w只是计算中的一步 没有几何意义
理解起来 参见 齐次方程 x+y=0 (A)
非齐次方程 x + y =b (B)
B的解=A的通解+特解
为什么 x=xh/h y=yh/h!!
http://www.cs.mtu.edu/~shene/COURSES/cs3621/NOTES/geometry/homo-coor.html
因为这里说的这些 符合在这样的 才能使 多项式成为齐次
再次感慨下 中文搜的东西 基本都雷同 技术资料只能找英文的!!!!!
One of the many purposes of using homogeneous coordinates is to capture the concept of infinity. In the Euclidean coordinate system, infinity is something that does not exist. Mathematicians have discovered that many geometric concepts and computations can be greatly simplified if the concept of infinity is used. This will become very clear when we move to curves and surfaces design. Without the use of homogeneous coordinates system, it would be difficult to design certain classes of very useful curves and surfaces in computer graphics and computer-aided design.
Let us consider two real numbers, a and w, and compute the value of a/w. Let us hold the value of a fixed and vary the value of w. As w getting smaller, the value ofa/w is getting larger. If w approaches zero, a/w approaches to infinity! Thus, to capture the concept of infinity, we use two numbers a and w to represent a value v,v=a/w. If <