Unity multi-camera display on the same screen

First understand: the rendering sequence of the camera and Canvas

What is the camera's rendering order ?

Answer: The simple understanding is to use a brush to brush the wall. The first brush will be blocked by the second brush.

For example: camera 01: the sea rendered first, camera 02: the bikini beauty rendered later. Then the effect is: bikini beauty standing in front of the sea.

The way to understand the brush: a blank wall is painted with the pattern of the sea first, and then the pattern of beautiful women is painted on the level of the sea.

Factors that affect the rendering order: ((17 messages) Unity rendering order related learning_unity camera stack_Nickname is so difficult to write blog-CSDN blog )

Rendering priority Camera depth > Sorting Layer > Order in Layer > RenderQueue
It should be noted that RenderQueue 2500 is the key value, which is the dividing point between transparent and opaque
1. camera (the smaller the depth, the earlier the rendering)
2. sorting layer (value The smaller the value, the first to render) (there is also a sortingOrder below, the smaller the value, the earlier to render)
3. Render Queue renderQueue (the smaller the value, the earlier to render)
4. Depth value (the closer to the camera, the smaller the value, the more The farther the value is, the larger.)

But the specific coverage method will also be determined according to the clearFlags of the camera (as shown below)

 2. Understand the Canvas rendering order ( (18 messages) Talking about Canvas and three rendering modes in Unity_unity canvas__Mr. Orange's Blog-CSDN Blog )

1.Screen Space -  Overlay  mode

Canvas covers the screen and is always covered on top of other elements, which means that the UI will block other elements in the scene.

When RenderMode is Screen Space - Overlay, other parameters of Canvas include:

Pixel Perfect: UI elements are accurate to pixel alignment, and the edges are clearer, but there will be a greater amount of calculation during UI adjustment and adaptation (personal understanding)
Sort Order: the depth of Canvas. When multiple Canvas exist, the Canvas with a larger Sort Order value will cover the
Canvas with a smaller Sort Order value
Note: When multiple Canvas depth values ​​are equal, the Canvas behind in the Hierarchy view will be displayed at the bottom, which is different from UI
elements ( Such as the opposite rule of Image)
2.Screen Space - Camera mode

Similar to the Overlay mode, the Canvas covers the entire screen space and the canvas also fills the entire screen space. The difference is that the Canvas is placed in front of the specified camera.

Pixel Perfect: the same as Overlay mode.
Render Camera: The specified camera used to render the Canvas.
Plane Distance: The distance between the Canvas plane and the camera.
Sorting Layer: Indicates the depth of the Canvas, which can be added manually. When there are multiple Canvas in the Screen Space mode
, the Sorting Layer determines the display priority.
Order in Layer: When multiple Canvas have the same Sorting Layer,
the display priority is determined according to the Order in Layer.
3. World Space mode

In this mode, Canvas is no different from other 3D elements in the scene

  • Canvas can adjust the value of RectTransform
  • The camera's translation, rotation, zoom and fov will affect the display of the Canvas
  • EventCamera is required to specify the camera that receives the event

Between Canvas in different modes, the Canvas of Screen Space - Overlay is always displayed at the front, and the
display relationship between Screen Space -Camera and World is determined by the position of the World Canvas from the camera and the Plane Distance of Screen Space - Camera Canvas

The same Screen Space - Overlay Canvas: the display priority is determined by Sort Order

The same Screen Space - Camera: the display priority is determined by Sorting Layer and Order in Layer
 

3. After understanding, enter the topic: multi-camera display on the same screen

1. First create a new scene, create two UI to represent the UI interface

2. Create Cube and Sphere, two cameras, Render Texture under Assets, and create two RawImages under Canvas.

 3. Assign Render Texture to RawImage01 and Camera01 respectively, and the other is the same.

 

 The effect is as follows:

4. Next, we let two cameras appear separately: Cube (rendered by Camera01), Sphere (rendered by Camera02)

Just place the models in front of their respective cameras

Effect:

 

Dome address: (26 messages) Unity multi-camera display on the same screen.zip resource-CSDN library

Guess you like

Origin blog.csdn.net/qq_37524903/article/details/131725727