Unity:用于特定显示的Texture2D ReadPixels [英] Unity: Texture2D ReadPixels for specific Display

查看:235
本文介绍了Unity:用于特定显示的Texture2D ReadPixels的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Unity一段时间以来已经支持多个显示输出(最多8个).

Unity has had support for multiple display outputs for a while now (up to 8).

使用 ReadPixels 函数,您可以指定要读取的区域以及原点坐标.但是我不能指定显示编号来执行朗读.

With the ReadPixels function, you can specify an area to read from, and an origin coordinate. But I cannot specify a display number to perform the read on.

我需要能够从具有特定区域和原点的特定显示器(1-8)读取像素.

I need to be able to read pixels from a specific display (1-8) with a specific area and origin point.

请问我该怎么做?

推荐答案

可以实现特定屏幕/显示的ReadPixels.您必须执行以下操作:

You can achieve ReadPixels for a specific screen/display. You have to do the following:

在开始之前,我假设您有许多摄像机,每个摄像机都渲染到不同的显示器.摄像机必须没有附加RenderTexture才能输出到显示器.

定义一个执行以下操作的函数:

Define a function which does the following:

  1. 为所需的摄像机分配一个临时的RenderTexture
  2. 使用 RenderTexture.active = *临时渲染纹理* 使当前活动的渲染纹理等于您刚创建的临时纹理
  3. 使用 ReadPixels 通过适当的 Rect 将像素读入临时的 texture2d 中.这将从当前处于活动状态的 RenderTexture
  4. 中读取
  5. texture2d
  6. 上调用 Apply()
  7. RenderTexture.active 和相机 RenderTexture 设置为 null
  1. Assign the desired camera a temporary RenderTexture
  2. Use RenderTexture.active = *temporary render texture* to make the currently active rendertexture equal the temporary one you just created
  3. Use ReadPixels to read in pixels into a temporary texture2d using an appropriate Rect. This will read from the currently active RenderTexture
  4. Call Apply() on the texture2d
  5. Set the RenderTexture.active and camera RenderTexture to null

想法是ReadPixels可以在当前的Active RenderTexture上运行.

The idea is that ReadPixels works on the currently Active RenderTexture.

代码应如下所示:

    outputCam.targetTexture = outputCamRenderTexture;
    RenderTexture.active = outputCamRenderTexture;
    outputCam.Render ();
    tempResidualTex.ReadPixels (screenRect, 0, 0);
    tempResidualTex.Apply ();

    RenderTexture.active = null;
    outputCam.targetTexture = null;

这篇关于Unity:用于特定显示的Texture2D ReadPixels的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆