2

结果

我想从 Unity3d 虚拟相机中捕获帧,然后让它们显示在另一个原始图像上。结果是原始图像屏幕闪烁得很厉害。

using UnityEngine;
using UnityEngine.UI;

public class RawImageVirtualWebCamTexture : MonoBehaviour
{
    private RawImage rawimage;

    void Start()
    {
        GameObject obj = GameObject.Find("RawImageTransform");
        rawimage = obj.GetComponent<RawImage>();
    }

    void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        if (source != null)
        {
            rawimage.texture = source;
        }
        Graphics.Blit(source, destination);
    }
}

我想看到流畅的画面。但是怎么做呢?

4

1 回答 1

6

如果是关于 Unity Camera,则无需捕获任何内容。

只需创建一个新的RenderTexture

Assets-> right click-> Create->RenderTexture

在此处输入图像描述

让您的Camera渲染进入其中,RenderTexture而不是通过简单地引用 created RenderTexturein来渲染游戏视图Target Texture(这使得它Camera不再渲染到 Game View 而是渲染到所引用的RenderTexture

在此处输入图像描述

最后简单地使用created RenderTextureasTextureRawImage

在此处输入图像描述


如果您需要Camera同时渲染到正常的游戏视图,只需Camera在子对象上使用另一个用于上述过程。

在此处输入图像描述


结果

在此处输入图像描述

于 2019-06-27T16:12:59.437 回答