How to compute camera culling mask via script to show two layers

Hi,

scratching my head around setting camera's culling mask.

I want to change the culling mask of the camera to render 2 layers, problem is I found only example on how to render one layer

1 << 8

but I fail to find how to for example render layout 8 AND layer 11 for example

How would I achieve this?

note: shame on me, right now, I looked at the actual value when I use the editor, but really I would like to learn how to set it up via script :)

myLayer = 1 << 8 | 1 << 11;

The culling mask is a 32 bit (binary) field, thus bit 1 = 1, bit 2 = 2, bit 3 = 4, bit 4 = 8. bit 5 = 16 etc. So to convert a layer index into an integer you use the left bitshift command ( << ).

To combine any number of layers you need to use the bitwise OR function (ie. the | symbol) to 'combine' layers into a single value (integer).

e.g myLayer = 1 << 8 | 1 << 11 | 1 << 20;