0
最近我在某個着色器的某處看到了很少的代碼片段。由矢量組成的旋轉矩陣需要歸一化還是不需要?
的代碼如下(它其實並不重要,着色語言是什麼。)
float2 mv = tex2Dlod(_CameraMotionVectorsTexture, uv).rg * _Amplitude;
// Make a rotation matrix based on the motion vector.
float2x2 rot = float2x2(mv.y, mv.x, -mv.x, mv.y);
// Rotate and scale the body of the arrow.
float2 pos = mul(rot, v.vertex.zy) * _Scale.xy;
// Normalized variant of the motion vector and the rotation matrix.
float2 mv_n = normalize(mv);
float2x2 rot_n = float2x2(mv_n.y, mv_n.x, -mv_n.x, mv_n.y);
// Rotate and scale the head of the arrow.
float2 head = float2(v.vertex.x, -abs(v.vertex.x)) * 0.3;
head *= saturate(color.a);
pos += mul(rot_n, head) * _Scale.xy;
爲你的人看到,那腐爛基質由不規範的運動矢量的。但稱爲rot_n
的第二個旋轉矩陣的兩個軸向量得到了歸一化,而在創建旋轉矩陣之前,它只是在運動向量上進行歸一化。我無法弄清楚爲什麼,爲什麼代碼的作者在製作旋轉矩陣之前無法一直標準化運動矢量?
有人可以幫我擺脫這個問題,我真的很感激它。先進的謝謝你!
'rot'不是一個純旋轉矩陣。它可能包含縮放。這可能是爲了解釋箭頭的範圍,而頭部不應該根據箭頭的長度進行縮放。但不知道輸入是不可能的。 –
@Nico Schertler。嗨,你說得對,只要取消比例尺線性變換就行了 – haoc