【问题标题】:how can i reproduce the 'Unity_Matrix_VP' value我怎样才能重现'Unity_Matrix_VP'值
【发布时间】:2017-06-16 06:14:35
【问题描述】:

我不想在 C# 代码中计算 Unity_Matrix_VP。

但是,我总是得到不正确的结果。我的代码如下:

     Matrix4x4 V = camera1.worldToCameraMatrix;
     Matrix4x4 P = camera1.projectionMatrix;
     var N = new Matrix4x4();
     N.SetRow(0, new Vector4(1.0f, 0.0f, 0.0f, 0.0f));
     N.SetRow(1, new Vector4(0.0f, 1.0f, 0.0f, 0.0f));
     N.SetRow(2, new Vector4(0.0f, 0.0f, -1.0f, 0.0f));
     N.SetRow(3, new Vector4(0f, 0f, 0f, 0f));
     Debug.Log("testCamera");
     Debug.Log(N);
     Debug.Log(P * N * V);

我的代码结果是:

0.97384 -0.02902 0.00304 3.04939 0.05073 1.72168 0.18231 179.67620 0.00624 0.10518 -0.99504 -990.16710 0.00623 0.10512 -0.99444 -989.57320

但是,FrameDebugger 中 Unity_Matrix_VP 的值是另一个值:

Frame Debugger Result

真是太神奇了。 Unity 是否可以通过其他方法计算 unity_Matrix_VP 值?

【问题讨论】:

    标签: c# unity3d camera shader transform


    【解决方案1】:

    我知道了:

    因为 Unity C# 使用 OpenGL 标准,而我在 Windows 上运行 Unity。

    所以它会将 Matrix_PV 转换为 DirectX。

    可以通过'GL.GetGPUProjectionMatrix'的API修复跨平台。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-06
      • 1970-01-01
      • 2011-06-04
      • 2018-03-16
      • 1970-01-01
      • 2023-01-28
      • 1970-01-01
      • 2017-02-02
      相关资源
      最近更新 更多