- Home /
How do I draw directly (and quickly) into the rendered frame?
Is there an efficient way to modify the frame post-render? I am talking about quite a few pixels set manually. I tried using OnRenderImage()
to
- first get the frame into a
Texture2D
withReadPixels()
- then modify it with
SetPixel()
Apply()
the changes- finally
Graphics.Blit()
it back into the destination texture
However, even setting no pixels kills the framerate. When I try to draw a dozen random rectangles (just to test the speed), the framerate reaches single figures. It seems that Apply()
is not the only slow thinker here, SetPixel()
is a significant time waster.
Is there a faster way? And I mean much faster.
It seems that calling something like SetPixels at runtime is probably not a good idea. Based on what data are you calling SetPixel? This is likely something that can be done with a post-processing shader -- which would be much faster (assu$$anonymous$$g your target device supports this) -- can you give more details about the data you're working with?
I'm prototyping a GUI system that would not cost a draw call per UI element. The rest can be deduced from this premise. That raises a number of problems, but drawing speed is by far the most important factor.
Answer by Max Kaufmann · Oct 28, 2010 at 02:29 AM
Don't use ReadPixels, just render-to-texture straight from the camera and do your compositing in a shader, then splat that texture on a "canvas" billboard.
I'm afraid a shader would not be able to help. There is a lot of processing to be done, and a shader might not be the best place to do it. See my above comment about the nature of the task.