x


How can I draw an array of data (640x480) very fast ?

Hello all,

I have an array of values from a Cellular Automata simulation (640x480 grid) that I would like to draw straight to screen. My understanding is that these are the only options available:

  • Make a Texture2D on every frame then draw it as a GUI texture and unfortunately take a bad hit on the framerate because of Apply().
  • Draw it as particles but that many particles (307200) would kick the framerate in the face.
  • Draw it as openGl calls but there's no GL_POINTS and it would be slow anyway.
  • Draw it as an Image Effect/Graphics.blit but passing the data to the shader would have to also be as a Texture2D so same problem with Apply().

So... how can I draw/blit all that 2D pixel data the fastest way possible?

ANY trick, option or alternative would be most welcome. Thanks in advance.

more ▼

asked May 07 '10 at 01:55 PM

BlobbyPops gravatar image

BlobbyPops
91 3 3 11

(comments are locked)
10|3000 characters needed characters left

5 answers: sort voted first

A little more advanced, but you could also rewrite the cellular automata simulation to evaluate inside a shader. This would be done by applying the shader on a fullscreen quad. If you need information about the previous state of the cells when evaluating, you could this by making two rendertexture's and ping-pong between the two. Something like this:

  • Set rendertextureOne active
  • Set rendertextureTwo as a texture in the material with the cellular automata shader
  • Draw fullscreen quad with the cellular automata material
    • Use information from rendertextureTwo to calculate next step

---- Next frame ----

  • Set rendertextureTwo active
  • Set rendertextureOne as a texture in the material with the cellular automata shader
  • Draw fullscreen quad with the cellular automata material
    • Use information from rendertextureOne to calculate next step

If you can't fit all the information into one texture, you can always use more of these ping-pong's. This technique would definitely speed up your calculations quite a bit, given they are applicable to this kind of parallel processing.

more ▼

answered May 08 '10 at 04:16 PM

Jens Fursund gravatar image

Jens Fursund
381 3 4 11

A double buffered shader using render textures to avoid Apply(). How cool. Would you have an example of this being used by any chance ?

May 09 '10 at 04:06 AM BlobbyPops
(comments are locked)
10|3000 characters needed characters left

It is actually possible, on OSX, to blit textures very fast by having a plugin access the OpenGL texture "handle", and write the data directly from there.

This has been used successfully for putting high-resolution quicktime movies into Unity.

The big issue is that it doesn't work on Windows, because Unity is using Direct3D there, and it appears to be quite complex to update D3D textures from plugins. Any ideas or pointers welcome.

more ▼

answered Aug 17 '10 at 12:01 PM

Magnus Wolffelt gravatar image

Magnus Wolffelt
457 9 11 26

Update: you can force Windows to use OpenGL with a command-line param

Sep 13 '11 at 11:20 PM DaveA
(comments are locked)
10|3000 characters needed characters left

You could divide that into a grid of smaller textures, and then update only the textures that actually change.

more ▼

answered May 07 '10 at 04:27 PM

Eric5h5 gravatar image

Eric5h5
80.2k 41 132 519

So you reckon that there's no faster way to blit than having to go through a texture Update?

May 07 '10 at 11:49 PM BlobbyPops

@BlobbyPops: I can't think of a way, no.

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

i'd just use your first idea and update the texture every 0.1s or so in a coroutine - it should still look plenty good enough without killing your frame rate

more ▼

answered May 07 '10 at 02:22 PM

Mike 3 gravatar image

Mike 3
30.5k 10 65 253

Hi Mike, thanks for your reply. Unfortunately a coroutine is not a thread and it would actually block the graphics pipeline as the texture needs to be uploaded. Also 0.1s would only make 10fps and the point of my question was to get a maximum framerate.

May 07 '10 at 03:09 PM BlobbyPops

Indeed - you can't Apply from a thread without thread errors being spammed back at you. If the texture is the only thing you're interested in drawing, then yes, 10 fps probably won't be much good; i assumed you were trying to keep a decent framerate for other things while you drew this :)

May 07 '10 at 03:38 PM Mike 3
(comments are locked)
10|3000 characters needed characters left

Write a shader!

more ▼

answered May 22 '10 at 04:39 PM

N1nja gravatar image

N1nja
445 22 28 37

good answer! "MASSIVE SARCASM QUOTES"

Mar 21 at 04:11 AM Benproductions1
(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:

x2196
x1035
x491
x65
x5

asked: May 07 '10 at 01:55 PM

Seen: 3128 times

Last Updated: Mar 21 at 04:11 AM