【问题标题】:Unity ReadPixels in VRVR 中的 Unity ReadPixels
【发布时间】:2018-08-20 21:03:35
【问题描述】:

我正在尝试使用以下方法将当前屏幕捕获到纹理中:

texture.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0, false);
texture.Apply();

然后使用以下命令直接全屏渲染:

GL.PushMatrix();
GL.LoadOrtho();
GL.LoadProjectionMatrix(matrix); //matrix = Matrix4x4.identity * Matrix4x4.Scale(new Vector3(2, -2, 1)) * Matrix4x4.Translate(new Vector3(-0.5f, -0.5f, 0));
Graphics.DrawTexture(rect, texture, mat); //rect = new Rect(0, 0, 1, 1);
GL.PopMatrix();

这在桌面上测试时非常有效,但是在 Android 上为 VR(谷歌纸板)构建时,纹理会失真。我猜罪魁祸首是 VR SDK 投影矩阵,所以我查看了Camera.SetStereoProjectionMatrix。但是,设置这些似乎不会影响任何事情。

我使用预定义的纹理尝试了代码的第二部分,该纹理在设备上渲染得很好,从而将其缩小到捕获阶段。

有人能解释一下吗?

【问题讨论】:

    标签: unity3d opengl graphics rendering google-cardboard


    【解决方案1】:

    只填充了一半的纹理,我突然想到在 VR 中每只眼睛都需要单独渲染。我对这个管道不够熟悉,但我尝试的第一件事是在创建新纹理和 BAM 时使用 RenderTexture 大小而不是屏幕大小!显然,我为我的纹理分配了错误的(双倍)大小,使其在渲染时显得被挤压。

    RenderTexture curr = RenderTexture.active;
    RenderTexture.active = Camera.main.activeTexture;
    texture = new Texture2D(curr.width, curr.height, TextureFormat.ARGB32, false);
    texture.ReadPixels(new Rect(0, 0, curr.width, curr.height), 0, 0, false);
    texture.Apply();
    RenderTexture.active = curr;
    

    我可能仍然需要考虑 2 只不同的眼睛,从而捕捉 2 种纹理,但那是另一种冒险,干杯!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多