I'm working on a project in Unity that receives image files over sockets and renders them onto game objects. I have a successful prototype up and running but it creates a noticeable lag every time I call Texture2d.LoadImage. Is there any way to load this texture outside of the main game loop to keep my game from lagging? Alternatively is there a more efficient way of rendering images onto game objects?
Thanks for your help
Pete
Unhappily, no.
Loading of byte data into a texture to upload it then takes its time, the larger it is the worse the problem.
I’ve spent 10 hours on something similar. I have an 640x480 30 FPS image stream (an RGB byte texture) from the Kinect, and so far I have looked into:
-
Convert the texture to Color format and pass it on to Texture2D.SetPixels(…) and then Texture2D.Apply().
FAILED: Too slow
-
Switch Unity to OGL mode and make a DLL upload the texture directly to the GPU from an image pointer. FAILED: Black texture. I confirmed that I got the data through to the DLL by writing it to a file, but with no luck.
-
Load texture as PNG. FAILED: can’t even get it to load PNG’s out of the box. Seriously…
-
Convert texture in unsafe mode, but I couldn’t figure out how to switch over to that. I also looked into sending the data to a DLL, but I couldn’t figure out how to get the right signatures/marshalling done… so, FAILED
-
Upload to a shader. I cannot find any place to send a byte stream to the shader even though I am sure that CG allows it. I’m about to see what I can find out here…
It is absolutely REDICULOUS how hard this is to do with Unity, and they better fix it fast. It is costing my company a lot of money to have me sitting on my ass to solve such a simple problem, and to be honest I’d rather be moving on myself.