三次映射
基于 (rx, ry, rz) 向量的标准方法是首先在表中查找一些值。这些值用于每个顶点的 (s,t)(或 (u,v))纹理坐标。
首先找到Reflected Vector R = 2(N dot V)N - V, 其中V = Vertex, N = Normal , R Reflected Vector(rx,ry,rz)
major axis
direction sc tc ma
--------- --- --- --
+rx -rz -ry rx
-rx +rz -ry rx
+ry +rx +rz ry
-ry +rx -rz ry
+rz +rx -ry rz
-rz -rx -ry rz
一旦为 sc、tc 和 ma 分配了值,就可以使用以下公式计算该面的 (s,t) 坐标。
if((rx >= ry) && (rx >= rz))
{
sc = -rz;
tc = -ry;
ma = fabs(rx); //absolute value
s = ((sc/ma) + 1) / 2;
t = ((tc/ma) + 1) / 2;
cout << "+rx (" << s << "," << t << ")" << endl;
}
if((rx <= ry) && (rx <= rz))
{
sc = +rz;
tc = -ry;
ma = fabs(rx);
s = ((sc/ma) + 1) / 2;
t = ((tc/ma) + 1) / 2;
cout << "-rx (" << s << "," << t << ")" << endl;
}
if((ry >= rz) && (ry >= rx))
{
sc = +rx;
tc = +rz;
ma = fabs(ry);
s = ((sc/ma) + 1) / 2;
t = ((tc/ma) + 1) / 2;
cout << "+ry (" << s << "," << t << ")" << endl;
}
if((ry <= rz) && (ry <= rx))
{
sc = +rx;
tc = -rz;
ma = fabs(ry);
s = ((sc/ma) + 1) / 2;
t = ((tc/ma) + 1) / 2;
cout << "-ry (" << s << "," << t << ")" << endl;
}
if((rz >= ry) && (rz >= rx))
{
sc = +rx;
tc = -ry;
ma = fabs(rz);
s = ((sc/ma) + 1) / 2;
t = ((tc/ma) + 1) / 2;
cout << "+rz (" << s << "," << t << ")" << endl;
}
if((rz <= ry) && (rz <= rx))
{
sc = -rx;
tc = -ry;
ma = fabs(rz);
s = ((sc/ma) + 1) / 2;
t = ((tc/ma) + 1) / 2;
cout << "-rz (" << s << "," << t << ")" << endl;
}
参考
http://www.unc.edu/~zimmons/cs238/maps/cubeind.html
球形、立方和抛物线环境映射http://www.unc.edu/~zimmons/cs238/maps/environment.html
OP,请您分享您的用于生成 UV 坐标的最小二乘保形映射算法。谢谢你。