Black generated Texture, Android Texture limit, accessing pixel infomation from vuforia

Hello

I’m having the classic, black texture issue with my app on android. I think i know the cause, (the texture size is too large), but it is quite unique, and I can not think of a fix.

I’m running the vuforia plugin on android, which works fine. However when the AR marker is detected, I need to access the pixel information from the webcamtexture vuforia is using. Currently I’m accessing the texture via the material used by the renderer that displays the webcam texture that vuforia uses. It works fine on PC, however on android the accessed pixels are black, resulting in a black texture. (Note that I’m not talking about the webcam background).

This leads me to assume that when I cast the mainTexture on the webcam backdrop to texture2D (so I can access the pixel information) the Texture2D that is returned is black. An example

Texture2D texture = (Texture2D)backdropRenderer.material.mainTexture; // Get the texture assigned to the backdrop as a Texture2D

return texture.GetPixel(15, 50);

This is only an example of the part of the code that I have isolated that causes the problem, as I have confirmed all other parts to work.

So this leads to two questions

  1. is there another means of accessing pixel information from vuforia’s webcamtexture than the above
  2. what is the limit of generating texture2d via script on android

I ran into a similar issue a year or so ago, but I can’t remember exactly why so here are some suggestions:

Try accessing the data at the very end of the frame (yield return new WaitForEndOfFrame)
Don’t cast it as Texture2D. A WebcamTexture has a GetPixel function.
Not sure how possible it is for you, but you could capture the screen itself using Texture2D.ReadPixels

As for your question about generating a texture2D, well you can create them as much as you can create any texture. Depending on device you will have a certain texture size limit (1024x1024 is generally safe to use on android)