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.
Example hierarchy:
use
render nothing
camera.cullingMask = 0;
render all
camera.cullingMask = -1;
render a single layer
camera.cullingMask = 1 << 8;
render multiple layers
camera.cullingMask = 1 << 8 | 1 << 4;
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.