{"action":"created","issue":{"url":"https://api.github.com/repos/mrdoob/three.js/issues/5931","labels_url":"https://api.github.com/repos/mrdoob/three.js/issues/5931/labels{/name}","comments_url":"https://api.github.com/repos/mrdoob/three.js/issues/5931/comments","events_url":"https://api.github.com/repos/mrdoob/three.js/issues/5931/events","html_url":"https://github.com/mrdoob/three.js/pull/5931","id":54752625,"number":5931,"title":"Camera Culling Mask (Layers)","user":{"login":"tsone","id":5467191,"avatar_url":"https://avatars.githubusercontent.com/u/5467191?v=3","gravatar_id":"","url":"https://api.github.com/users/tsone","html_url":"https://github.com/tsone","followers_url":"https://api.github.com/users/tsone/followers","following_url":"https://api.github.com/users/tsone/following{/other_user}","gists_url":"https://api.github.com/users/tsone/gists{/gist_id}","starred_url":"https://api.github.com/users/tsone/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tsone/subscriptions","organizations_url":"https://api.github.com/users/tsone/orgs","repos_url":"https://api.github.com/users/tsone/repos","events_url":"https://api.github.com/users/tsone/events{/privacy}","received_events_url":"https://api.github.com/users/tsone/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-01-19T11:23:46Z","updated_at":"2015-01-20T07:46:52Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/mrdoob/three.js/pulls/5931","html_url":"https://github.com/mrdoob/three.js/pull/5931","diff_url":"https://github.com/mrdoob/three.js/pull/5931.diff","patch_url":"https://github.com/mrdoob/three.js/pull/5931.patch"},"body":"Answers feature request #5562 , but with bare-bones functionality (no bitmask/field API). The implementation here should work with lights, cubemap camera and shadow maps. Please inform me if there's some functionality I missed that would benefit from this.\r\n\r\nThe new example `webgl_shadowmap_layerbits` demonstrates the usage with shadow maps. I also modified the example `webgl_materials_cubemap_dynamic2` to demostrate the use with `CubeCamera`. (The sphere is now hidden using layers.) No other examples were modified.\r\n\r\nThe new `Camera.cullingMask` property is a bitmask where the set bits indicate visible layers to the camera. Unset bits mark invisible (=hidden, culled) layers. Default value is `0xFFFFFFFF`, i.e. all layers are visible. The new `Object3D.layerBits` property is a bitfield where the set bits indicates the layers where object is on. Object can be on multiple layers. Default value is `0xFFFFFFFF`, i.e. object is on all layers.\r\n\r\nAn object (and its branch) is culled if `( object.layerBits & camera.cullingMask ) === 0`. This culling affects __all kinds of objects in the scene graph__ -- be it `Scene`, `Light`, `Mesh`, `Camera`, etc. It does not affect the scene hierarchical transformations, but it does for example affect light allocation.\r\n\r\nThe actual culling test is done in the function `Object3D.isVisible( camera )`. In practice, what I did was to replace all `object.visible` checks with this function. In my opinion all of the checks I found were regards to some camera, so I think the function could have as well been in `Camera` instead of the `Object3D` (i.e. `Camera.isVisible( object )`).\r\n\r\nIn `WebGLRenderer`, I needed to use the `_currentCamera` quite extensively to cull the lights properly. I needed to set this more early than it was (in `setProgram()`) because so much depended on it. I am not 100% sure if this is correct, but it seems so.\r\n\r\nPlease comment. One thing I'm not sure is if the name `layerBits` is actually good as Unity uses `layerMask` and this feature is modeled after Unity. Which one is better?"},"comment":{"url":"https://api.github.com/repos/mrdoob/three.js/issues/comments/70616029","html_url":"https://github.com/mrdoob/three.js/pull/5931#issuecomment-70616029","issue_url":"https://api.github.com/repos/mrdoob/three.js/issues/5931","id":70616029,"user":{"login":"WestLangley","id":1000017,"avatar_url":"https://avatars.githubusercontent.com/u/1000017?v=3","gravatar_id":"","url":"https://api.github.com/users/WestLangley","html_url":"https://github.com/WestLangley","followers_url":"https://api.github.com/users/WestLangley/followers","following_url":"https://api.github.com/users/WestLangley/following{/other_user}","gists_url":"https://api.github.com/users/WestLangley/gists{/gist_id}","starred_url":"https://api.github.com/users/WestLangley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/WestLangley/subscriptions","organizations_url":"https://api.github.com/users/WestLangley/orgs","repos_url":"https://api.github.com/users/WestLangley/repos","events_url":"https://api.github.com/users/WestLangley/events{/privacy}","received_events_url":"https://api.github.com/users/WestLangley/received_events","type":"User","site_admin":false},"created_at":"2015-01-20T07:46:52Z","updated_at":"2015-01-20T07:46:52Z","body":"> I don't think it's a good idea to have layerMask to serve many purposes depending on the object type\r\n\r\nThat is true.  However, in my proposal (which was a trial-ballon, BTW), the `layerMask` just identifies what layer the object is \"in\". I was describing what being \"in a layer\" means for various objects. The proposal is simpler than what is proposed in this PR.\r\n\r\n> Like I explained above, light's layerMask property is used directly as the shadow camera's cullingMask. \r\n\r\nAnd what is the shadow camera's `layerMask` used for in this PR?\r\n\r\nWhy does it make sense for a camera to have both a `layerMask` and a `cullingMask`?\r\n"}}