Camera usage in the URP rendering pipeline

Hello everyone, I am Ah Zhao, and I will continue to talk about the URP rendering pipeline.
This time I will talk about the camera usage in the URP rendering pipeline
. As mentioned earlier, there are relatively large changes in the property display of URP cameras and ordinary cameras:
insert image description here

Next, let's explain the usage:

1. Handling changes for multiple cameras

insert image description here

When multiple URP cameras exist at the same time, it is no longer to sort the camera rendering by depth.
From the camera settings, you can see that RenderType is divided into 2 types:
1.Base
2.OverLay
insert image description here

If you create a camera and set the RenderType to Overlay, you will find that there are many things missing in the camera options.
Let me talk about a few main ones:
1. Overlay cameras cannot set anti-aliasing
2. Overlay cameras have an additional option of ClearDepth, but there are no options for OpaqueTexture and DepthTexture
3. Base cameras can specify BackgroundType, also It is the background type, such as skybox or solid color. The Overlay type camera cannot specify the background type.
4. The Base type camera can specify the OutputTexture, which is the output RenderTexture. The Overlay type camera cannot specify the output RenderTexture alone.

Next, we keep the main camera MainCamera as Base type, and then create cam1 and cam2 as Overlay type cameras
insert image description here
insert image description here

Although there are 3 cameras, only one camera is seen from the Game view.
This is because, in a group of cameras, there can only be one Base type, and then multiple Overlay type cameras must be added and specified in the Stack of the Base camera to be rendered.
insert image description here
insert image description here
insert image description here

It can be seen from the above situation that the Base type camera is rendered first, so it is at the bottom layer, then to the Overlay camera in the Stack, and then the order in the Stack will affect the rendering order of the Overlay camera.

2. Use script to control URP camera

1. Modify camera properties

When using URP cameras, some of the corresponding APIs in Unity’s Camera can still work, such as clearFlags, backgroundColor, orthographic, fieldOfView, etc., but many APIs are no longer familiar with URP cameras. To use the script to control the URP camera, you need:
using UnityEngine.Rendering.Universal;
Then get the UniversalAdditionalCameraData data on the camera
UniversalAdditionalCameraData urpData = cam.GetUniversalAdditionalCameraData();
UniversalAdditionalCameraData specific API description:
https://docs.unity3d.com/ Packages/[email protected]/api/UnityEngine.Rendering.Universal.UniversalAdditionalCameraData.html
For example, if you want to add an Overlay camera to the Base camera at runtime, you can do this:
UniversalAdditionalCameraData urpData = cam.GetUniversalAdditionalCameraData();
urpData.cameraStack.Add(subCam);

2. Simultaneous rendering of multiple base cameras

Assuming there are multiple Base cameras in the scene, how to determine the rendering order between them?
insert image description here

In fact, the Priority attribute of the Base camera is the depth attribute of a non-URP camera. This attribute can be used to sort multiple Base cameras, and the API is still camera.depth

3. Render to RenderTexture

insert image description here

If you need to render to RenderTexture through the Base camera, you can set RenderTexture to Output Texture.
If you use code to set it, it is the same as a normal camera, or camera.targetTexture = rt;
but it is worth noting that only the Base camera can specify the output, and if you specify the targetTexture on the Overlay camera, it will cause rendering errors.

3. About anti-aliasing

insert image description here

There is an Anti-aliasing anti-aliasing option on the Base camera, but if you simply set the value inside, there will be no anti-aliasing effect. You must check the PostProcessing post-processing option above to have the anti-aliasing effect. If a Base and multiple Overlay cameras are rendered together, only one of the Base or Overlay cameras has PostProcessing checked, then the anti-aliasing effect selected in the Base camera will also take effect.

Guess you like

Origin blog.csdn.net/liweizhao/article/details/130670957
Recommended