Unity camera clear flags and culling mask properties for a detailed use

Source: Internet
Author: User

Original address: http://blog.csdn.net/tanmengwen/article/details/87982311. Two properties 1.1 clear flags purge mark

Each camera stores color and depth information when it is rendered. The non-drawn portion of the screen is empty, and the Sky box is displayed by default. When you use multiple cameras, each stores its own color and depth information in a buffer and accumulates a large amount of rendering data for each camera. When any particular camera in the scene renders, you can set a clear flag to clear different sets of buffer information. This can be done with one of the following four options:

1.Skybox Sky Box

This is the default setting. The section above the screen will display the Sky box for the current camera. If the current camera does not have a sky box set, it will default to the Sky box selected in the Render settings (in Edit->render settings). Then it will be returned using the background color. In addition, the Sky box assembly can be added to the camera. If you want to create a new Sky box, you can use this guide.

2.Solid Color Solid Color

Any empty part of the screen displays the background color of the current camera.

3.Depth only Depth

If you want to draw a player's gun without letting it get cropped inside the environment, you need to set a camera with a depth of 0 to draw the environment, and another camera with a depth of 1 to draw the weapon separately. The weapon camera's purge mark should be set to depth only. This will keep the environment graphically displayed on the screen, but will discard all information about the location of each object in three-dimensional space. When the gun is drawn, the opaque part will completely cover anything that has been drawn, regardless of how close the gun is to the wall. (This part looks very laborious)

4.Don ' t clear does not erase

This mode does not clear any color or depth caches. The result is that each frame is drawn on top of the next frame, causing the smear effect. This is not a typical way to play a game, preferably with a custom shader.

1.2 Culling mask Culling mask

Culling masks use layers to selectively render a set of objects. Information about the usage layer can be found here.

It is usually good practice to put the user interface on a different layer and then render the UI layer separately with a separate camera.

In order for the UI to appear at the top of other camera views, you also need to set the purge mark to depth only, and make sure that the UI camera's depth is higher than the other camera.

2. Here are a few steps to demonstrate the two properties of the camera:

First create two cameras in the unity scene, named Camera1 and Camera2, respectively;

Then create a cube and sphere as the camera's object in the scene, and allow two cameras to capture two objects.

Then set the camera1 depth for 0,camera2 depth to 1;

You will find that the game window will only show the picture that Camera2 shot;

Visible Camera Depth properties set the camera drawing order , a camera with a larger value will be drawn on top of a camera with a smaller value, in other words, a camera with a depth of 1 will be drawn above a camera with a depth of 0.

Two:

Clear Falgs default Skybox;

Set the Camera2 clear Falgs to depth only;

At this point you can see that the game window will show the CAMERA1 and camera2 simultaneously shot ;

It can be seen that it is very simple to render the images taken by multiple cameras to the same screen, just set their clear falgs to depth only; one condition is that their depth need to be better than the clear The Falgs is a skybox or solid color camera with a high depth so that multiple cameras can be superimposed on the same screen separately.

Three:

Now the problem is that the two cameras shoot the same object, how can I let camera1 only shoot the scene background, and Camera2 only to shoot the set of objects;

Create a plane in the scene, and set the material, filled with camera1 screen, as the background of the scene.

Next, we want to set the layer relationship for the object. The concept of Unity's layer can be analogous to the layers inside PS.

First, add a layer, as shown, and name it object;

Next, set the layer for the object, set the layer of the Sphere object to the object layer, and the layer of the cube as the object layer.

Finally, you will set the culling mask property of two cameras so that the camera renders the specified Layer object.

the cullingmask of the camera defaults to everything, indicating that all layers of objects are rendered.

Camera1: culling mask inside the object layer is removed, culling mask will be shown as mixed ... You will find that the Camera1 window will only display the background picture and the object is not rendered.

Camera2: in the culling mask option, tick nothing, and then tick the object layer, indicating that the camera only renders objects belonging to object, and will not capture other layers.

Finally, the game window to see the two camera overlay screen;

Four:

At this point, we understand the powerful role of the camera's depth, Clear falgs, and culling mask.

Similarly, if you are making a game, you can create an interface camera, render the interface separately, and the other cameras will render the scene. All you need to do is add the UI layer and set the layer of all the interface objects to the culling mask of the Ui,ui camera and just tick the UI layer.

The game window view above is superimposed on the footage taken by three cameras.

Because the picture uploaded by this blog is missing, upload the document: http://download.csdn.net/detail/tanmengwen/5255294
Reprint: http://blog.csdn.net/tanmengwen/article/details/8798231

Unity camera clear flags and culling mask properties for a detailed use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.