2

the results

I want to capture frames from Unity3d virtual camera and then let them displayed on another raw image.The result is that the raw image screen flickers very much.

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);
    }
}

I want to see smooth pictures. But how to do that?

Harlan Chen
  • 321
  • 5
  • 20

1 Answers1

9

If it is about a Unity Camera you don't have to capture anything.

Simply create a new RenderTexture

Assets -> right click -> Create -> RenderTexture

enter image description here

let your Camera render into that RenderTexture instead of rendering the game view by simply referencing the created RenderTexture in Target Texture (that makes this Camera not render to the Game View anymore but to the referenced RenderTexture)

enter image description here

and finally simply use the created RenderTexture as Texture for the RawImage

enter image description here


If you need that Camera to render to the normal Game View at the same time simply use another Camera on a child object for the process above.

enter image description here


Result

enter image description here

derHugo
  • 83,094
  • 9
  • 75
  • 115