又一篇学习笔记,参考Mathematics for 3D Game Programming and Computer Graphics和ShaderX4上一篇关于tangent space计算的文章写的东西。对于计算时需要分裂顶点的内容看的还不是太清楚-_-b。另外,目前的算法还不能完美处理镜像或者在纹理不连续处可能出现的问题,就算在Farcry中,很多问题也是通过美工来“隐藏”的,再一次应证了之前对美工重要性的结论^^。
算法:
Tangent space在Bump Map中有着重要作用,通常需要把灯光转换到tangent space进行计算。对由参数方程计算出的规则曲面(比如,球体,圆环)来说,很容易通过方程计算出tangent space,但对任意的三角形网格来说,则没有那么简单。
Tangent space是一个三维空间。对3D空间中的一个顶点来说,切空间的三条座标轴分别对应该点的法线N,切线T,和副法线(binormal)B,显然,对不同的顶点来说,切空间是不同的。那么在已知三角形三个顶点及其纹理坐标的时候,如何计算出N,T,B呢?
目前已知的数据有三角形的三个顶点在世界坐标中的位置: P0, P1,P2, 以及相应的纹理坐标在纹理空间中的位置C0 (U0,V0),C1,C2,则有:
P10 = P1 – P0,
P20 = P2 - P1 ,
C10 = C1 – C0 = (U1-U0, V1-V0) = ( U10 ,V10)
C20 = C2 – C0.= (U2-U0, V2-V0) = ( U20 ,V20)
注意,P10在世界坐标中的方向和C10在纹理空间中的方向是一致的(这一点确实比较抽象,偶画图研究了好久才弄明白-_-),同样,P20和C20也是如此,发现这一点很重要,可以说是整个计算的基石。进一步来说,T,B分别和纹理坐标轴U,V是平行的。因此我们有:
P10 = U10T + V10B
P20 = U20T + V20B
把矢量展开得到:
两边乘以[C10 C20]的逆矩阵,最后得到
法线N = T x B
这样我们就得到了坐标从切空间转变到世界坐标下的变换矩阵M = [ T B N ],当然,更加常用的是M的逆矩阵。注意,这里计算得出的只是面法线,如果需要计算每个顶点的法线,则应该对共享该顶点的多个面的法线取均值,求出结果。
实现:
ogre calculate tangent:
Vector3 Math::calculateTangentSpaceVector(
const Vector3& position1, const Vector3& position2, const Vector3& position3,
Real u1, Real v1, Real u2, Real v2, Real u3, Real v3)
{
//side0 is the vector along one side of the triangle of vertices passed in,
//and side1 is the vector along another side. Taking the cross product of these returns the normal.
Vector3 side0 = position1 - position2;
Vector3 side1 = position3 - position1;
//Calculate face normal
Vector3 normal = side1.crossProduct(side0);
normal.normalise();
//Now we use a formula to calculate the tangent.
Real deltaV0 = v1 - v2;
Real deltaV1 = v3 - v1;
Vector3 tangent = deltaV1 * side0 - deltaV0 * side1;
tangent.normalise();
//Calculate binormal
Real deltaU0 = u1 - u2;
Real deltaU1 = u3 - u1;
Vector3 binormal = deltaU1 * side0 - deltaU0 * side1;
binormal.normalise();
//Now, we take the cross product of the tangents to get a vector which
//should point in the same direction as our normal calculated above.
//If it points in the opposite direction (the dot product between the normals is less than zero),
//then we need to reverse the s and t tangents.
//This is because the triangle has been mirrored when going from tangent space to object space.
//reverse tangents if necessary
Vector3 tangentCross = tangent.crossProduct(binormal);
if (tangentCross.dotProduct(normal) < 0.0f)
{
tangent = -tangent;
binormal = -binormal;
}
return tangent;
}
分享到:
相关推荐
It computes the tangent space at every point by computing the d-first principal components in each local neighborhood. It then optimizes to find an embedding that aligns the tangent spaces.
OriginLab也可以安装Tangent 插件 免费下载 请点赞
Tangent.rar
originlab tangent插件,在origin8.0做图表的时候,经常需要给所画的曲线添加切线,在这里为大家提供一种画切线的简便方法。
tangent,用于origin中做某一点切线,非常使用的一个小插件,1M不到。为大家助力科研,只需要2积分就可以下载啦,感恩!!!!
origin插件,辅助曲线画切线工具 双击线上点即可
tangent circles draw.py
parser with the tangent method
内含Design of Tangent Vector Fields论文 自己实现的代码, 对论文的解释PPT 代码介绍: VS2005 写的,用IBFV显示,可以读入三维Obj模型。 需要安装taucs库,及openGL. 三个月前写的,现在忙,没时间详细描述。 ...
使用Tangent将您的位置保存在浏览器中,并在准备再次使用它们时调出所有标签。 您每天都在从事多个项目,只是您没有那样想。 工作,研究,社交网络,流媒体,博客和其他任务都是单独的项目。 Tangent可帮助您保存...
天正T20系列软件和谐补丁,各专业通用
Ionized gas clouds near the Sagittarius Arm tangent.pdf
Local Tangent Space Alignment (LTSA) Conformal Eigenmaps (extension of LLE) Maximum Variance Unfolding (extension of LLE) Landmark MVU (LandmarkMVU) Fast Maximum Variance Unfolding (FastMVU) Kernel ...
和目前已有的机器学习库不同,Tangent 是一个源到源(source-to-source)的系统,利用 Python 函数 f 生成一个新的 Python 函数,来计算 f 的梯度。这为用户提供了更好的梯度计算可视化,使用户可以容易地对梯度进行...
Linear Local Tangent Space Alignment Stochastic Proximity Embedding Multilayer autoencoders Local Linear Coordination Manifold charting Coordinated Factor Analysis new...
切线消除了维护多个浏览器窗口并减少标签混乱的需要。 切线消除了维护多个浏览器窗口并...我们正在黑客入侵,使Tangent更好的每一天。我们很乐意听取您的建议。 请联系我们:listening@dotangent.com 支持语言:English
Graph Neural Tangent Kernel:Fusing Graph Neural Networks with Graph KernelsWhile
针对Gabor小波提取人脸特征存在维数高,计算复杂的问题,引入基于划分的局部切空间排列算法(Partitional Local Tangent Space Alignment)对得到的Gabor幅度特征(Gabor Magnitude Feature,GMF)进行降维,同时将...