简体   繁体   中英

Fast way to set byte array to unity texture2d

In unity3d I get image from camera (color camera device) as byte array from a plugin , and I want show image in real-time in screen .

If i use Texture2D.SetPixels32 for making a texture, it decrease fps dramatically ( from 80 to 10).

//First convert byte[] to color[]
  colorr = GetColor(imageBuffer);

  imageColor.SetPixels32(colorr);
  imageColor.Apply();   // fps reduced here

I guess I need to do this with a shader on GPU .

So what is solution to do this faster ? If answer is using shader , can give a sample .

Thx.

I have done it with using openGL. Just write a plugin for unity and get Texture2D NativeID from unity and send that to the plugin then use openGL to set bytes to the texture ! It was amazing ! FPS increased from 10 to 50 !!! also you need to know that you have to run games in OpenGL mode, with "-force-opengl" to use opengl functions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM