Hey guys, im wondering if my approach is good. I want to have a screen with a grid of pixels, lets say 200x150 pixels. I create it with a single texture using some loops and a SetPixel function. From that point i manipulate SetPixel function to draw lines with mathematical equations every frame. Now when you think about it working with pixels and graphics in general using CPU is horrible(isn’t it?). What do you think? My fps is pretty good around 100fps. But if i want to do some more complex pixel stuff? Should i be working with shaders? Any point or opinion is very much appreciated!
In order from (approximate) worst to best in terms of efficiency, you have:
SetPixel, your current method
SetPixels, which you should absolutely use if you don’t want to get into shader programming (every call to the binary-level functions has some overhead, so a single GetPixels+SetPixels with array manipulation in between is much better than a dozen SetPixel calls.)
RenderTexture, with a special camera setup just to render your line (moves the heavy lifting to the GPU, but involves a lot of overhead. It will probably produce the most visually appealing result with the most straightforward code.)
shader programming (really efficient and lightweight, but difficult to learn how to do)
This question depends heavily on your current hardware and where you intend to deploy to. If you’re making a game for the same kind of hardware that you’re developing on, then who cares? Wait until you actually see a FPS drop, then start optimizing. On the other hand, if you’re developing for phones, you should profile it on the phone to see how much that’s actually costing you.
Thanks for helping me out! Even tho ive been learning programming for quite a while now with CPU and GPU but ive never understood how should i manipulate GPU to create pixel effects for example drawing pixels. Looks like to me the only way is to use CPU with unity. Im deffintely wrong and this is where i want to get my mind clear. Should i be using shaders if i want to create full grid of pixels and for example draw lines following mouse position? I dont mind difficulty of shaders. Im familiar with opengl and such i just need an advice whether i should use shaders to do such things?
Agreed with @StarManta here, but I’d take it one step further: look into the Vectrosity plugin on the Asset Store. LineRenderer is awkward and limited and will give you way more headaches than is worth the simple low price of Vectrosity.
Disclaimer: I didn’t make Vectrosity but I love using it, and the guy who did is really active on these forums.
First of all using LineRenderer isn’t something i want because my lines actually brake and so on, just not smt i want. Second of all im not happy with using plugins from asset store. Anyway im gonna stick with what im doing right now. If i had the time i would defineately do this project using only openGL. Thanks for help