【问题标题】:Advantages of Unity plugins over the script in Unity Plugin while getting the rendered frames from unityUnity插件相对于Unity插件中脚本的优势,同时从unity获取渲染帧
【发布时间】:2018-04-02 20:57:47
【问题描述】:

假设我使用 Unity Native Plugin 来获取相机渲染的纹理,并且我在我的项目中添加了相同的功能。这两者之间有性能差异吗?

第二个,我刚刚添加了

    RenderTexture currentRT = RenderTexture.active;
    RenderTexture.active = cam.targetTexture;
    cam.Render();
    Texture2D image = new Texture2D(cam.targetTexture.width, cam.targetTexture.height);
    image.ReadPixels(new Rect(0, 0, cam.targetTexture.width, cam.targetTexture.height), 0, 0);
    image.Apply();
    RenderTexture.active = currentRT;
    return image;

对于第一个,我有一个类似这样的本机插件 (https://answers.unity.com/questions/1335556/problem-with-camera-rendering.html?childToView=1488524#answer-1488524) 然后我正在导入插件 .dll 并从代码中调用该函数。 (注意 GL.IssuePluginEvent 可以由“相机”脚本的 OnPostRender 函数调用)

总的来说,我观察到第二种方法会使我的游戏在在线捕获帧时变慢,但在这种情况下使用插件有什么好处吗?

【问题讨论】:

    标签: c# unity3d plugins render


    【解决方案1】:

    非异步 ReadPixels() 调用通过调用 GPU>CPU 内存传输并停止硬件管道而导致帧速率下降。

    在这种情况下使用插件有什么好处吗?

    如果您使用的是 Unity 2017 或更低版本,那么插件是异步传输 GPU 数据的唯一方法。你可以在这里找到一个开源插件GitHub/AsyncTextureReader

    如果您使用的是 Unity 2018(测试版)或更高版本,则可以使用新的 experimental AsyncGPUReadback 类完全避免插件。见这里AsyncGPUReadback

    【讨论】:

      猜你喜欢
      • 2014-02-11
      • 2015-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多