6

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.

mX64
  • 388
  • 1
  • 7
  • 24

2 Answers2

5

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.

mX64
  • 388
  • 1
  • 7
  • 24
  • 1
    how can you access the texture image pixels in this situation? – MobileCushion Jun 25 '13 at 09:04
  • 5
    I know this is dead but thought I would add my 2 cents. Could also, instead of forcing OpenGL, write the plugin to allow OpenGL or DirectX depending on what is being used. No need to force then! – D Hansen Nov 11 '13 at 11:13
  • How do we do that in the case of Metal for iOS? in OpenGL we can pass the texture Id by using bind texture. But then, metal does not allow you to access the memory nor have I seen a function in texture that lets you do it. – Dipak Jul 09 '22 at 15:35
0

This sounds like it would work perfectly for you... http://docs.unity3d.com/Documentation/ScriptReference/WebCamTexture.html

Matt Bond
  • 1,402
  • 12
  • 19
  • ty , but WebCamTexture need That Unity recognize camera device , but im using special camera that unity cant find that . as i said i get image as byte array from a c++ wrapper(plugin) . can i use this class for this case ? – mX64 Nov 17 '12 at 07:11
  • What's special about the camera - is it custom hardware, or a virtual webcam, or something else? – Matt Bond Nov 17 '12 at 08:13
  • If you have drivers installed, doesn't it show up in the WebCamTexture.devices list? (don't have a kinect to test with, but it seems like something like this https://github.com/wildbillcat/KinectCam/ or this http://www.e2esoft.cn/kinect/ might work) – Matt Bond Nov 18 '12 at 14:33