layerMask not working properly with RenderTargetTexture

Hello again,

I’m playing around with this PG https://www.babylonjs-playground.com/#1WROZH#159 and I am having a problem with layerMasks.

There are two cameras in the scene camera (with layerMask === 1) and camera2 (with layerMask === 2). The activeCamera of the RenderTargetTexture is set to camera2.

If I set the layerMask of one of the spheres in the scene to 2, it works as expected (i.e. the sphere is not shown in the main camera [camera], but it is shown in the minimap [camera2]). However, if I set the layerMask of one of the spheres in the scene to 1, it shows it both in the main scene (where it should be) and in the minimap (where it should not be).

Any ideas of what’s going on? Have I missed some flag for the RenderTargetTexture perhaps?

Thanks in advance!

When you set something to rtt.renderList we assume you selected the meshes you want to be rendered, so we don’t check for the layer masking. If you want this check to be performed, you should set rtt.renderList = null. In that case, the system will loop through all meshes of the scene and will apply the layer masking check:

https://www.babylonjs-playground.com/#1WROZH#162

1 Like