x


Streaming textures possible?

Could anyone possibly show me how to transfer the byte[] of a texture from one client to another (using Unity's built in networking if possible). Essentially I would like to stream the texture from an object on client1 to an object on client 2. I would like to do this for as many frames possible (so compression/decompression would be nice). This is for experimental purposes so I'm not as concerned with bandwidth usage as I am with proof of concept. Any help achieving this affect would be greatly appreciated.

more ▼

asked Jul 12 '11 at 10:08 PM

kaleetos gravatar image

kaleetos
106 5 5 8

Have you tried anything yet? Do you have some code to poke at?

If you haven't already, check out some wiki scripts; they show some streaming implementation (not for textures that I can see, but it'll give you an overview of how unity handles this stuff) that might be useful to you.

http://www.unifycommunity.com/wiki/index.php?title=Special%3ASearch&redirs=0&search=stream&fulltext=Search&ns0=1

Jul 12 '11 at 10:39 PM Chris D

No. Really I'm just trying to figure out if this is even possible. I do see a library called ulib in the asset store that can serialize arbitrary unity components. However before I spend the $75 I want to know if maybe there is a way to do it with Unity's built in networking.

Jul 12 '11 at 10:54 PM kaleetos

Hi. In ULIB you can encode texture to bytearray, compress, encode to string and send over RPC to other user.

May 08 '12 at 11:20 AM McRain
(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

With unity networking, nope, not reasonably as you have to convert all to strings and even there you have size limits. But with regular sockets, there is no reason why it shouldn't work

more ▼

answered Jul 12 '11 at 11:07 PM

Dreamora gravatar image

Dreamora
3.2k 1 4 25

You could even use OnSerializeNetworkView with reliable delta compression and setup your own transfer protocol. There you can stream all kind of data, you just have to make sure that the receiving peer reads the same amount that have been sent.

I use this method for our Hack&Slash game to transfer server snapshots of different sizes but i use unreliable of course ;) You have to serialize always some kind of header so the receiving peer knows what data follows.

So it is possible but i guess it's less limited with sockets. Well, sockets have of course the limitation that you can't open a listening socket in a webplayer while with unity network you can start a server.

Jul 13 '11 at 03:06 AM Bunny83

@Warwick- I don't see how I could send the entire Color[] on a per frame basis (the bitstream does not support Color[] serialization). I could probably split up the Color[] into ints and then (on the other end) reconstruct the Color[] and subsequently read the pixels. However this would mean the texture on client B would would be multiple frames behind the texture on client A. I need a way to send the entire texture once per frame.

@Dreamora- This is what I feared haha. I might I have to brush up on my .NET and get hacking away at the network code.

@Bunny- This seems like an interesting idea. Exactly how would I go about setting up a custom transfer protocol that Unity's networking will accept. Is it possible perhaps to combine Warwick's suggestion and yours(send the Color[] from Texture2D.GetPixels through the OnSerializeNetworkView once per frame). If this is possible, this would be ideal. If I may add-- these are not, by any means, large textures so sending the entire texture once per frame should not be a problem as far as bandwidth goes.

Jul 13 '11 at 01:04 PM kaleetos
(comments are locked)
10|3000 characters needed characters left

You can use Texture2D's GetPixels, then transfer them the same as any other data.

more ▼

answered Jul 12 '11 at 11:05 PM

Waz gravatar image

Waz
6.5k 22 33 71

If you use Texture2D.EncodeToPNG and Texture2D.LoadImage it's at least compressed ;)

Jul 13 '11 at 03:08 AM Bunny83
(comments are locked)
10|3000 characters needed characters left

To those of you who want to know, Dreamora's suggestion was the route I ended up taking. I turned the textures2d.getpixels into bytes[] and sent them over standard udp sockets. Reconstructed the texture on the other side and voila, streaming textures.

more ▼

answered Jul 17 '11 at 02:07 PM

kaleetos gravatar image

kaleetos
106 5 5 8

Just curious: what was the application for this? I'm trying to figure out why you'd want to stream a texture that's constantly changing.

Oct 26 '11 at 09:15 PM Julien.Lynge
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2210
x711
x48

asked: Jul 12 '11 at 10:08 PM

Seen: 2009 times

Last Updated: May 08 '12 at 11:20 AM