Is using multiple cameras, culling masks, and layers expensive on mobile?
I have an endless runner game.
I have my background layer which has a bunch of scrolling art elements. This is culled with a background only camera on its own layer. It has a depth of -1.
I have a foreground layer which has a bunch of scrolling art elements. This is culled with a foreground only camera and its own layer as well. It has a depth of 1.
Then, my main camera is where the gameplay layer is, and it renders all that stuff together. It is set to a depth of 0.
This way, I can have an elegant little background art scrolling system on one layer, an elegant little foreground art layer on another, and worry about the complexities of the game-camera and gameplay on its own layer.
This method seems like an excellent workflow, but I am wondering how much of a performance impact this is on mobile? Should I just find a way to do all of those things using one camera, or is separating it like so the way to go?
Answer by Abhiroop-Tandon · Mar 30, 2016 at 11:36 AM
Everything comes with their own cost. You have three cameras rendering the same scene. It depends on the complexities of rendering. If you have high quality images all over the place and the scenes are long then yeah the phone can get laggy. You can try optimizing the quality of your gameObjects if you really need to have three cameras. What people usually try to do (at least i do sometimes) is have two cameras, one for the foreground and other for the background (for parallax effect). What i would suggest is if you can try reducing the number of cameras thats good, if you simply cannot then try optimizing your images and textures.
Hm, is it really rendering the scene 3 times?
The objects that the cameras are looking at are fairly basic.
The background contains a background plane that has a scrolling texture offset. It also contains a few objects that move down the screen and warp back up to the top to loop.
The foreground camera looks at some objects that also scroll from top to bottom, and a screen based rain effect.
The reason I separated them like this is that my gameplay camera is moving upwards constantly, and I didn't want to attach all those scrolling systems to my main camera. Ins$$anonymous$$d, i felt it would be more economical and elegant to just have them statically doing their thing, and culled by separate cameras.
Not sure if this is the optimal solution now, though.
Ummm what i found was the cameras dont run on separate threads (which would make it efficient). So having less cameras is more efficient unless you really need something like a $$anonymous$$imap or something. Try finding another way to achieve what you want.
To be honest if you are too crazy about the efficiency of the game and all try reducing them, if its a small game and you dont care much about the efficiency just leave them there but the answer to your question according to me will be having less cameras is more efficient
Thanks for the information. I am fascinated with this because I am reading conflicting information from various sources. In this article
http://blog.theknightsofunity.com/using-multiple-unity-cameras-why-this-may-be-important/
It clearly states:
"The conclusion is that different cameras can render different objects. This is important information even if you don’t know yet how to use it in practice. It also means that adding second camera will not re-draw your scene two times. Only objects visible to the second camera will be rendered. $$anonymous$$nowing this having multiple cameras rendering different layers will result in similar efficiency as rendering all these layers using only one camera."
But other people are saying it does render multiple passes.
Well then go with your gut feeling hahah what else should i say !!