banner



How To Connect Multiple Cameras To A Computer

From what I observe, many Unity users do non grasp the concept of using multiple Unity cameras on a single scene. "If I desire to wait from only one perspective, why do I need more than one camera?". Saying that it makes perfect sense when more than one camera captures the scene from the same perspective makes information technology even more than confusing. So why even carp? The reason is somewhat complex, but information technology'south actually worth learning. It will aid yous create bang-up visual effects, that are difficult to accomplish with the use of only 1 camera, in an like shooting fish in a barrel way.

What is the Unity camera?

Before we tin go along, you accept to empathize what Unity Camera actually is. When Unity renders the scene it needs much of important information to be set upwardly, but let'southward simplify that list to make information technology easier to empathise. Allow'due south consider:

  • Listing of objects to render
  • Camera'southward perspective (position, rotation, scale, field of view, clipping etc.)

If y'all're already experienced in that affair you might've noticed that I'thou not speaking most matrices. Let'southward just ignore math-related stuff for now.

List of objects to render is a list of all objects on the scene, right?Wrong! Each photographic camera renders only the objects visible to it (field of view, frustum alternative) and those on the layer which actually seen by the camera (Culling Mask.)

camera culling mask

Culling Mask can exist set toEverything, or you lot may prepare which of the layers should exist seen. This is one thing what layers are for.

This camera sees everything.
This camera sees only the Default layer (ground) and the Red layer (red sphere).
This camera sees only the Default layer (basis) and the Carmine layer (red sphere).

The conclusion is that different cameras can render dissimilar objects. This is important information even if y'all don't know still how to use it in do. Information technology also ways that adding second camera will non re-draw your scene two times. Merely objects visible to the second camera will be rendered. Knowing this having multiple cameras rendering unlike layers volition result in similar efficiency as rendering all these layers using only one photographic camera.

Allow's and then answer the main question: Camera is an instruction to render specific list of objects from given perspective.

What practice cameras render?

Look, haven't we simply answered that question?! Well… not exactly. There'due south a visible and an invisible part. What you can see is a consequence image (allow'south call it color buffer). And of course at that place's a thing that you cannot see. This thing is called adepth buffer (chosen also z-buffer).

Depth buffer tin be easily described as a game screen sized greyness-scale image, every pixel of which represents how shut that pixel is to the camera (to exist honest this is non 100% true but let's not think of more complicated cases now.) It is used by the GPU to determine whether to-be-rendered pixel should be processed or rejected from rendering. As a consequence, pixels that are obstructed by other pixels are non going to be visible (just similar in the existent globe.)

depth buffer

Camera club and clearing

Before rendering annihilation intocolor buffer anddepth buffer, camera can articulate both buffers or just the depth buffer. Did y'all observe that the default Unity 5 scene photographic camera clears buffers toSkybox?

clear flags skybox

There are some more than options there:

cb969ef8-2866-4689-9026-e95e0c8c39f2

  • Skybox replaces color buffer with your skybox and completely clear depth buffer
  • Solid color does the same, just color buffer becomes solid color
  • Depth simply leaves color buffer at is, but your depth buffer becomes articulate
  • Don't Clear doesn't clear anything.

What will happen if we volition endeavor to fix the default camera Articulate Flags to Don't Clear? Well, the effect may be interesting (I moved the camera a little later on entering the Play mode).

camera don't clear

Information technology looks like our sphere duplicated itself so many times, that information technology turned into some kind of wired, rounded pipes affair. Besides that there's still 1 red sphere on the scene (note that Bluish layer is notwithstanding not visible to the camera), the game scene image looks valid. There are no graphical artifacts of any kind. Even so we managed to create an effect of many duplicated objects with only one object.

This happened because color buffer was not cleared between frames (colors rendered previously were transferred to the next frame), also the depth buffer. Depth buffer remembered that something has been rendered and it was keeping this information when Unity tried to render another frame. When sphere was about to be rendered behind already rendered sphere epitome, invisible pixels were discarded. The same thing applies when there are many objects on the scene rendering one subsequently some other.

If you withal don't understand what just happened, please cease reading now and try doing it yourself! Make a new scene, add together an object, set camera Articulate Flags to Don't Clear and motility either your object or your camera.

What is it skillful for?

I assume that you lot don't desire this kind of effect in your game, so what'due south the immigration good for? Let's now try to create 2 cameras.

  • Blue Camera
    • Clear Flags: Skybox
    • Culling Mask: Default, Bluish
    • Depth: 0
What Blue Camera sees.
What Blue Camera sees.
  • Red Photographic camera
    • Clear Flags: Don't Articulate
    • Culling Mask: Blood-red
    • Depth: ane
What Red Camera sees.
What Red Camera sees.

At that place's ane new parameter:Depth. Depth defines the order of rendering of the cameras. Camera with lower depth will be rendered before the camera with a higher depth.

Let'south see how Unity will render this scene pace by step (again not 100% accurate, but it'south just to understand the process):

  • (Blue Camera context)
  • Colour buffer is cleared to Skybox
  • Depth buffer is cleared
  • Plane (Default layer) and bluish sphere (Bluish layer) are rendered
  • (King Photographic camera context)
  • Nil is cleared
  • Red sphere (Red layer) is rendered

As the result yous get a scene that looks exactly like rendered using a single camera:

a5d5727e-b210-41a1-b6c8-7e28373c5a02

So why bother? Let'south try one thing. Permit's switch Cherry-red Camera Articulate Flags from Don't Clear to Depth only:

depth only clear

Whoa, do you see that? Since depth buffer has been cleared, the red sphere doesn't know that its pixels are obstructed, then it'southward rendering like there's nothing on the scene. That ways thatclearing the depth buffer brings rendered objects to the front. This may be super-useful when you'd like to render 3D UI elements.

In Skyrim you can see inventory items as 3D objects. These are rendered correctly even if background object appears closer to the camera.
In Skyrim you tin see inventory items equally 3D objects. These are rendered correctly fifty-fifty if background object appears closer to the photographic camera.

Another interesting selection is applying camera furnishings merely to specific layers. Allow's try to apply blur to the Bluish Camera, just similar on the screenshot below:

camera blur effect

Allow's now switch  Red Camera Clear Flags dorsum to Don't Clear and apply a different effect to the Blueish Photographic camera: Grayscale.

5e5efe4a-6ae5-4877-8027-0969ccc1b002

Finally, keep in mind that if you desire to motion the camera, yous may want to move all cameras at in one case (that'southward why keeping all the cameras every bit a child of 1 game object is quite common.) Simply moving only one photographic camera may be somewhat desired…

moving two cameras

Source: https://blog.theknightsofunity.com/using-multiple-unity-cameras-why-this-may-be-important/

Posted by: hernandezmakentance.blogspot.com

0 Response to "How To Connect Multiple Cameras To A Computer"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel