2021年10月26日 星期二
2021年10月25日 星期一
如何根據uv計算出頂點的Tangent
https://photos.app.goo.gl/1Nj8ojgitocw5iSu7
下面是詳細過程
三角形的頂點是A、C、B、對映到的uv座標是a、b、c
uv座標的2個軸是u-axis、v-axis向量
a= (a.u,a.v) 代表
從uv座標的原點 o=(0,0)出發
沿著u-axis軸移動 a.u 長度、再沿著v-axis軸移動a.v長度,會到達點a
o + u-axis✖️a.u + v-axis✖️a.v = a
b和c也是類似的
o + u-axis✖️b.u + v-axis✖️b.v = b
o + u-axis✖️c.u + v-axis✖️c.v = c
這有什麼用呢?
現在換看頂點ACB
想像ACB會在同1個平面上P,然後再想像P上會有1個原點D
一開始我們不知道D的實際位置
但我們可以模仿uv空間
o + u-axis✖️a.u + v-axis✖️a.v = a
寫出
D + T✖️a.u + BN✖️a.v = A
D + T✖️b.u + BN✖️b.v = B
D + T✖️c.u + BN✖️c.v = C
再來只要解上面3個聯立方程式,就能找出tangent了
https://photos.app.goo.gl/1UVE8M3LQBSwupPm8
T.w就是Peek tangent in Unity裡的w
建模軟體要怎麼判定tangent.w的正負?連結
2017年5月18日 星期四
Why Object having NormalMap material can do mirror in Unity 5
4 case (make 3 real-axis look like match right hand rule)
它們都做了奇數次的鏡射(odd times mirror)
3 case (make 3 real-axis still match left hand rule)
它們都做了偶數次的鏡射(even times mirror)
在奇數次的鏡射的情況(in odd times mirror)
要再多改變一次tangent的方向(swap y again)
Unity乘上unity_WorldTransformParams.w應該就是這個原因
但Unity怎麼計算出unity_WorldTransformParams.w?
我猜可能像這樣...
方法(1)
transform has LossyScale(the global scale of object)
unity_WorldTransformParams.w=sign(LossyScaleX*LossyScaleY*LossyScaleZ)
方法(2)
transform has right ,
up , forward
但是right,up ,forward並不會反應出scale設為負值後的方向改變
所以必須乘上lossyScale
(也就是光看right,up,forward看不出3軸有沒有match right hand rule )
檢查cross(real_right ,real_up)和real_forward
是不是同向,決定[鏡射因子]
Vector3 real_right=LossyScaleX*right;Vector3 real_up=LossyScaleY*up;Vector3 real_forward=LossyScaleZ*forward;unity_WorldTransformParams.w=sign(dot(cross(real_right,real_up),real_forward));
2017年5月16日 星期二
Peek tangent in Unity
Unity use cross(v.Normal,v.tangent)*v.tanget.w
to find biNormal
I guess v.tanget.w=-1 in general situation
and v.tangetw=1 in mirror situation
then I try some test
in 3dsmax (general situation)
in Unity w of tangent is -1
Normal Direction : red ball to green ball
Tangent Direction : red ball to blue ball
in 3dsmax (mirror situation)
in Unity w of tangent is 1
PS:
set Absolute Mode to see the UV
coordinate
訂閱:
文章 (Atom)








