Introduction to the use of Unity URP camera


foreword

使用URP后,相机组件的面板发生了变化,如下图。接下来简单的介绍下URP下的相机使用

insert image description here


1. RenderType

RenderType has 2 options, Base and Overlay. As shown below
insert image description here

1.1 Overlay

The Overlay camera cannot be displayed alone, and the Game window can be seen to be black
insert image description here

1.2 Base

Base type cameras can be displayed separately, change the RenderType mode to Base, and you can see that the Game window is displayed
insert image description here

1.3 Overlay added to the Base camera

As mentioned earlier, the Overlay camera cannot be displayed alone, so how to display the image of the Overlay camera. The answer is to add it to the stack of the Base camera.
We set Camera1 as Base, Camera2 as Overlay, and then set Camera2 to Camera1's stack. The images from both cameras are displayed. It's easy to understand directly on the picture
insert image description here

1.3.1 Add by code

It is also a very common operation to add the Overlay camera to the stack of the Base camera through code. Next look at adding code

//把UI相机设置为Overlay
uiCamera.GetUniversalAdditionalCameraData().renderType = CameraRenderType.Overlay;

//把UI相机添加到Scene相机上
sceneCamera.GetUniversalAdditionalCameraData().cameraStack.Add(uiCamera);

1.4 The situation where multiple Base cameras exist together

What happens if there are multiple Base cameras. The answer is the one with the highest display priority.
We set both cameras to Base, set the Priority of Camera1 to -1, and the Priority of Camera2 to 0;
we can see that only the picture of Camera2 is displayed
insert image description here

1.5 Realize split screen through ViewPort Rect

As mentioned above, when multiple Base cameras exist, only the one with the highest priority is displayed. Is there any way to show it. There are also, we can realize 2 camera split-screen display by adjusting the Viewport Rect.

Camera1 ( x = 0, y= 0, w = 0.5, h =1) is displayed on the left half of the screen
Camera2 ( x = 0.5, y= 0, w = 0.5, h =1) is displayed on the right half of the screen

You can see that the 2 cameras are displayed together.
insert image description here

Guess you like

Origin blog.csdn.net/aaa27987/article/details/129753424