unity3d - 如何从多个渲染纹理中读取并设置纹理 2d 值 Unity 3D
问题描述
所以我的想法是在统一的纹理上创建一个实时安全摄像头系统。这个想法是使用分散在场景中的多个统一摄像机,并将它们全部渲染到 RenderTexture。然后将其组合到 1 个 2D 纹理上,然后我可以将其覆盖在屏幕上或附加到场景中的对象上。(很可能只是覆盖屏幕)
所以我的问题就变成了如何从 Unity 脚本中的多个 RenderTexture 中读取数据?然后如何将图像块写入 scipt 中的 texture2D 以及图像片段?
这就是我目前正在做的
public class Cameras : MonoBehaviour
{
public RawImage outText;
public RenderTexture[] cameras;
public int imgWidth;
public int imgHeight;
void Start()
{
Texture2D[] textures = new Texture2D[cameras.length];
for(int i = 0; i < cameras.length; ++i)
{
textures[i] = new Texture2D(cameras[i].width, cameras[i].height, TextureFormat.RGB24, false);
}
Texture2D Combined = new Texture2D(imgWidth, imgHeight, TextureFormat.RGB24, false);
}
void Update()
{
for(int i = 0; i < cameras.length; ++i)
{
//is this a decent way?
RenderTexture.active = cameras[i];
textures[i].ReadPixels (new Rect (0, 0, cameras[i].width, cameras[i].height), 0, 0);
textures[i].Apply ();
RenderTexture.active = null;
Color32[] camPixels= textures[i].GetPixels32(0);
/* someway to combine it?
for(int i = camOffset; i < camBlock.width; ++i)
{
for(int j = camOffset; j < camBlock.height; ++j)
{
Combined.SetPixel(i,j,camPixels);
}
}
*/
}
outText.texture = Combined;
}
}
作为后续问题,假设我想做一些效果。我将如何单独写入组合纹理的红色通道或绿色通道?
我在这里先向您的帮助表示感谢!
解决方案
推荐阅读
- npm - 带有 VSCode 代码段的 NPM 包
- mysql - 在家中为宠物项目托管数据库
- javascript - 如何在节点 js express 中添加密码检查中间件
- android - PreviewView 准备好时如何获取 CameraX 事件
- python - 将 JSON 元素附加到列表
- c# - 使用 HttpClient 发送原始 HTTP 数据包
- c# - 执行插件时出现 System.MethodAccessException(Dynamics 365 在线)
- python - python请求输出中的错误编码(?)
- vue.js - 清单:行:1,列:1,语法错误。清单的公共链接已更改
- sql - SQL 参数化排序