Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
3
Question by BlobbyPops · May 07, 2010 at 01:55 PM · 2dtexturegraphicsdrawingblitting

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

5 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by Jens Fursund · May 08, 2010 at 04:16 PM

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image BlobbyPops · May 09, 2010 at 04:06 AM 0
Share

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

avatar image
3

Answer by Magnus Wolffelt · Aug 17, 2010 at 12:01 PM

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DaveA · Sep 13, 2011 at 11:20 PM 0
Share

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

avatar image
2

Answer by Eric5h5 · May 07, 2010 at 04:27 PM

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

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image BlobbyPops · May 07, 2010 at 11:49 PM 0
Share

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

avatar image Eric5h5 · May 08, 2010 at 12:12 AM 0
Share

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

avatar image
-1

Answer by N1nja · May 22, 2010 at 04:39 PM

Write a shader!

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Benproductions1 · Mar 21, 2013 at 04:11 AM 0
Share

good answer! "$$anonymous$$ASSIVE SARCAS$$anonymous$$ QUOTES"

avatar image
0

Answer by Mike 3 · May 07, 2010 at 02:22 PM

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

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image BlobbyPops · May 07, 2010 at 03:09 PM 0
Share

Hi $$anonymous$$ike, 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.

avatar image Mike 3 · May 07, 2010 at 03:38 PM 0
Share

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 :)

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

2D car track method 1 Answer

Changing texture type to "Advanced" stops it from being affected when changing Quality Settings. Any way to get around this? 0 Answers

Unity 5.6 Creating a Distortion in Sprites? 1 Answer

Draw to Texture Without Pro? (perhaps something on the asset store)? 2 Answers

Why do I get those green lines? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges