- Home /
How to access Camera Viewport raw pixels, and save frames.
When capturing with the camera how can one access the Viewport raw pixels pixels in-memory, and also save the frames to disk?
In addition is there any notification that indicates the Viewport frame has updated?
Answer by whydoidoit · Dec 26, 2012 at 10:34 PM
You can't access them in memory per se - it would be totally different on different hardware configurations. If you have Unity Pro then you can render the camera to a RenderTexture which allows you to access the pixels.
A coroutine that does yield WaitForEndOfFrame is resumed after the scene is rendered.
So would I for example be able to create a 3$$anonymous$$ X 2$$anonymous$$ RGB RenderTexture, and read the pixels with a C++ or C# application? I'm wanting to render, and read pixels, at substantially greater resolutions than would fit onscreen.
Interesting - didn't this question used to be about multipass rendering or did I get confused and answer the wrong question? Because either I had a brain fart or I wouldn't have answered this way. Yes as @Aldonaletto says you can get the whole frame, but not an individual camera (rendering pass) on Indie. Ugh, sorry for any confusion.
And yes, you can make a render texture that is much bigger than the screen and have the camera render to that.
Answer by aldonaletto · Dec 27, 2012 at 12:50 AM
Actually, you can load a rectangle of screen pixels in a texture even in Unity Indie, with Texture2D.ReadPixels - take a look at the EncodeToPNG example, where a screenshot is saved to the disk and also sent over the network. But if you want a higher resolution, or render images that aren't in the screen, you'll need Pro and a RenderTexture as Mike said.
Your answer
Follow this Question
Related Questions
Detecting camera viewport on mouse down? 1 Answer
Prevent objects from disappearing when zooming in on an orthographic scene? 1 Answer
In-game video monitor without render-to-texture 0 Answers
WorldToViewportPoint and WorldToScreenPoint give wrong positions when VR is enabled 1 Answer
Move the camera in 2D when target reaches bounds. Is there a better way? 0 Answers