- Home /
Capturing the real-time output of multiple cameras in a scene
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
Prepare:
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?