inline float3 UnityObjectToViewPos(in float3 pos) { return mul(UNITY_MATRIX_V, mul(unity_ObjectToWorld, float4(pos, 1.0))).xyz; } inline float3 UnityObjectToViewPos(in float4 pos) { return UnityObjectToViewPos(pos.xyz); }
定義這個重載版本是爲了當傳遞float4類型參數到UnityObjectToViewPos函數時,避免出現隱式截斷(implicit truncation)的問題。函數
inline float3 UnityWorldToViewPos(in float3 pos) { return mul(UNITY_MATRIX_V, float4(pos, 1.0)).xyz; }
將世界座標空間中的某一點變換到齊次裁剪空間中。code
inline float4 UnityWorldToClipPos(in float3 pos) { return mul(UNITY_MATRIX_VP, float4(pos, 1.0)); }
將觀察座標空間中的某一點變換到齊次裁剪空間中。ip
inline float4 UnityViewToClipPos(in float3 pos) { return mul(UNITY_MATRIX_P, float4(pos, 1.0)); }