RenderTargetTexture with two cameras and layermasks

Hello guys!

I can’t get working this setup:
Camera1 - rendering only the ground disc which has an emissiveTexture set to an RTT
Camera2 - renders to the RTT the bunny so it should be not visible on Camera1

If I set the layerMask for Camera1 and Ground disc as 1, Camera2 and Bunny meshes as 2 the RTT gets totally distorted. If I don’t use layermasks it is working correctly, however the Bunny meshes are visible?

Semi-working example:

Change the second mask to 0x2… and it will distort the RTT.

const LAYER_MASK_1 = 0x10000000
const LAYER_MASK_2 = 0x10000000

What am I doing wrong?
I’ve found this: Cant get LayerMask to work correctly

Thanks a lot!

You can do it like this:

You need to set both cameras as active cameras in the scene (line 32) and set the outputRenderTarget of camera2 (line 48).


Thanks a lot!