Unity:用于特定显示的Texture2D ReadPixels [英] Unity: Texture2D ReadPixels for specific Display
问题描述
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:
- 为所需的摄像机分配一个临时的RenderTexture
- 使用
RenderTexture.active = *临时渲染纹理*
使当前活动的渲染纹理等于您刚创建的临时纹理 - 使用
ReadPixels
通过适当的Rect
将像素读入临时的texture2d
中.这将从当前处于活动状态的RenderTexture
中读取 - 在
texture2d
上调用 - 将
RenderTexture.active
和相机RenderTexture
设置为null
Apply()
- Assign the desired camera a temporary RenderTexture
- Use
RenderTexture.active = *temporary render texture*
to make the currently active rendertexture equal the temporary one you just created - Use
ReadPixels
to read in pixels into a temporarytexture2d
using an appropriateRect
. This will read from the currently activeRenderTexture
- Call
Apply()
on thetexture2d
- Set the
RenderTexture.active
and cameraRenderTexture
tonull
想法是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屋!