If there are 20 cameras in a scene and I need to capture the outputs of those cameras with different resolutions at least 15 fps. What would the best solution?
In other words, if I have a powerful enough machine, can Unity render multiple outputs at the same time? What are the constrains?
Preferably I don't want to split my screen and show the camera outputs next to each other and get the camera outputs, because in that case I am limiting my self to the screen size.
The other way, would be capturing each output in one frame, for example, if the scene is rendered 150 fps. I can get 10 cameras' output, each in a frame.
But all the mentioned solutions are not applicable for me. I even don't need to display the outputs. as far as I can store the outputs in the memory or file, it solves my problem.
Answer by Paulius-Liekis
May 29, 2012 at 08:20 AM
Assign RenderTargets to each camera
Set desired resolution on each render target
Then in each frame do a loop through all cameras and perform this:
Set render target active (or camera active?)
Create new texture the same size as render target. This will tell next step which camera is should read.
Do Texture2D.ReadPixels. This steps copies pixes from render target to the texture
Optional: Texture2D.EncodeToPNG and then write them to disk, but this will slow down things a lot.
In general capturing one camera to disk is a slow thing, so capturing many will be a problem. Capturing to memory might be better, but you will fill your memory fast, unless your resolutions are small.
I believe, we can use Texture2D.ReadPixels to read the pixels from the screen, not from the texture. even though you are going to pass the dimensions of the render texture to this function, that's not going to work.
There is another function Texture2D.LoadRawTextureData(IntPtr data, int size) where the data which is passed can get from the render texture using GetNativeTexturePtr() function.
I have used this approach for capturing multiple camera outputs simultaneously.But the problem is Texture2D.LoadRawTextureData(IntPtr data, int size) is causing exception.i am not sure about the reason.
I am trying this on the free version.is this approach working for anybody?
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
6 People are following this question.
Two outputs, one camera?
Two camera rendering an object differents textures
Post processing effect on depth only camera.
How do I prevent my camera from looking through objects?
Is there any way to create a fade effect in order to hide what isn't rendered by the camera?