Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Tearing problems when acquiring texture images with webcameratexture

Discussion in 'Editor & General Support' started by kikoland, Nov 4, 2013.

  1. kikoland

    kikoland

    Joined:
    Nov 4, 2013
    Posts:
    7
    Dear Unity users,

    I'm trying to write a plugin that processes images captured using a camera device. Everything works pretty well with the webcameratexture class, except when using iOS (ipad 3).

    I can observe tearing effects on image that appears when Getting pixels (GetPixels32()). It seems that GetPixels is reading the webcamtexture object while this object is being updated with a new webcam image.

    Here is a code (c#) that demonstrates the problem:

    Code (csharp):
    1.  
    2. IEnumerator Start ()
    3. {
    4.  
    5.     m_WebcamTexture = new WebCamTexture(deviceName, 640,480, 30);
    6.  
    7.     m_data = new Color32[640 * 480];
    8.     m_PixelsHandle = GCHandle.Alloc(m_data, GCHandleType.Pinned);
    9.  
    10.     m_imgTextures = new Texture2D(640, 480, TextureFormat.ARGB32, false);
    11.     gui.texture = m_imgTextures;
    12. }
    13.  
    14. void Update ()
    15. {
    16.     if (m_WebcamTexture.didUpdateThisFrame)
    17.     {
    18.                 m_WebcamTexture.GetPixels32(m_data);
    19.             m_imgTextures.SetPixels32(m_data);
    20.             m_imgTextures.Apply(false);
    21.     }
    22.  
    23. }
    24.  
    25.  
    26.  
    Any idea to ensure that GetPixels32 reads a full frame before it's updated ?