Unity Camera Settings - Culling Mask

Unity Camera Settings - Culling Mask

Reference document: Camera parameters in Unity—Culling Mask Detailed Explanation_-MCQ-的博客-CSDN Blog_unity camera cullingmask

Introduction

What is Culling Mask? It is a property of Camera that includes or ignores the object layer to be rendered by the camera. Simply put, it is which levels of objects in the scene the camera illuminates.

It is relatively simple to understand, but how to dynamically assign a value is a little more troublesome. After using it once, I will forget it next time, so I will record it here.

insert image description here

Example hierarchy:

insert image description here

use

render nothing

camera.cullingMask = 0;

insert image description here

render all

camera.cullingMask = -1;

insert image description here

render a single layer

camera.cullingMask = 1 << 8;

insert image description here

render multiple layers

camera.cullingMask = 1 << 8 | 1 << 4;

insert image description here

Render all layers except one

camera.cullingMask = ~(1 << 8);
camera.cullingMask = ~(1 << 8 | 1 << 5);

Adding layers to the original base

camera.cullingMask |= 1 << 8; //添加一个
camera.cullingMask |= 1 << 8 | 1 << 5; //添加多个

Original base delete level

camera.cullingMask &= ~(1 << 8); //删除一个
camera.cullingMask &= ~(1 << 8 | 1 << 5); //删除多个

epilogue

If there is something wrong with the writing, you are welcome to criticize and correct me.

Guess you like

Origin blog.csdn.net/yr1102358773/article/details/128339920