Search Unity

  1. Unity 2020.2 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

A way to modify pixels every frame with good performance?

Discussion in 'Scripting' started by ZowPac, Mar 27, 2012.

  1. ZowPac


    Sep 25, 2009
    Okay, so I have a very strong suspicion that Unity is not the tool for this job (is that heresy?), but it wouldn't hurt to ask and see what brilliance is out there that wouldn't have occurred to me...

    Basically I need to be able to change any pixel on the screen - easy, right? A Texture2D turned toward the camera... the problem is that many - perhaps sometimes even all - the pixels will change from frame to frame based upon a mathematical formula (something that doesn't break down in a way I could do it in chunks easily).

    SetPixel() is not very fast, but even if I use a huge Color array with SetPixels() instead there's still a big delay, which I figure is, in part, from reloading the texture into the graphics hardware.

    How to do this in a more Unity-like way? Maybe something like a stripped down SpriteManager, where the texture doesn't change (some gradient presumably), but we're talking hundreds of thousands of GameObjects, into the millions on larger screens, and that can't be good, right?

    I can look into compiling in extensions to address screen pixels, but that's not going to very portable

    I'm sure there are some improvements or approaches I'm not thinking of, but is there any reason to even think I can get reasonable performance out of Unity on this one?
  2. Eric5h5


    Volunteer Moderator Moderator

    Jul 19, 2006
    Sounds like you should be using a shader.