Quantcast
Channel: Answers by "Noise crime"
Viewing all articles
Browse latest Browse all 90

Answer by Noise crime

$
0
0

If you want to continue with the setPixels approach...

Unity does not support native (gpu) non-Power-of-two textures, instead it will convert them all to POT. In fact it will make two copies, one stretched to fit the next POT up and one 'placed' on a next POT. It does this so that it can be used on either meshes or as gui.texture.

So using a 1600x200, becomes a 2048x256 texture and any time you update the texture its being updated by Unity twice!

Far better then for you to create a 2048x256 texture to begin with and simply adjust the uv mapping to display the right area on a plane. This alone can give a substantial boost to performance.

As you've discovered its important to use setPixels over setPixel as it usually offers better performance as you are updating an area of pixels in one go instead of one at a time.

However it can also be beneficial to update only a section of a texture if possible. I suspect, though have not done any tests, that it may be analogous to the opengl glTexSubImage2D function which only updates a portion of an existing texture.

As to other improvements it depends on the type of graph and updates, but as an example.

If you are scrolling a line graph as new data arrives, by shifting the pixel data left/right, requiring substanical amount of data copying/moving then that is obviously going to be slow.

I'd look to use an alternative approach where instead of shifting the pixels you scroll the texture via uv (i.e in the material offset transform) instead. To update the texture you keep track of an offset in the texture as to which column to update. Every time you update a column of pixels in the texture/graph you increment to the next column (wrapping back around at the end) then shift the material offset in the opposite direction.

This method could probably be improved further by storing the graph at 90 degrees (so the texture becomes 256x2048), assuming it normally scrolls left to right. The reason I suggest this is that instead of updating a column of pixels (which will not be sequential in the pixel data) you are able to update a row (which is sequential). Then all you need to do is rotate the texture when displayed to make it horizontal again.

One final improvement, but which requires Unity Pro is to update the texture via direct opengl calls. However this depends upon how much data you are updating, i'm unsure if you manage to just update a single row of the graph each time if it would provide a noticeable performance boost over Unity's functions.


Viewing all articles
Browse latest Browse all 90

Latest Images

Trending Articles





Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>