Render target scene camera moves with main scene camera even though it's not supposed to

Hi fellow Babylon.js users,

First of all thanks for this great engine! This is the most pleasant 3D engine I have ever worked with so far. Until now it has been smooth sailing, but now I have my first question.

For some time I have been developing my game and making excellent progress, but right now I’m stumped. I’d like to have Diablo-like life and mana “baubles”, and I’d like to render them in 3D (with all sorts of nice effects :)) and project them as the top-most layer. But when implementing this I was always running into a weird problem, which I’ve isolated (fortunately that was straightforward) in the following two playgrounds:

Babylon.js Playground (the whole setup)
Babylon.js Playground (just the baublesScene)

As you can see, when moving the camera, the projected sphere in the first example moves with the camera, even though it’s supposed to stay still (and there’s supposed to be two on the left and right, not just one in the center). It’s almost like the camera of the baubleScene had its parent set to the main camera.

In the second example you can see what the baubleLayer should actually look like. As you can see, the camera can’t move. I just want the two spheres there to be glued to the screen basically (I hope that makes sense).

When looking at the first demo, you can also see a slight lag in the movement of the projected sphere, which tells me there’s some code there that resets the position/orientation explicitly. But I don’t understand why. Is this a bug or is it actually supposed to work this way?

The problem is exactly the same when using a plane to project on (by setting the emissiveTexture of its material), by the way.

I hope you can help me. Thanks in advance!

Hello, welcome and thanks for your kind words :slight_smile:

In your case I highly recommend to either use two scenes but completely independant like that:
https://playground.babylonjs.com/#BNCG8Y#1

Thanks Deltakosh!

I had no idea you could do that. Thank you! The alpha blending also looks really nice that way.

I’m curious though, why doesn’t this work with a renderTargetTexture? Would be a nice feature, wouldn’t it?

It could work but not with two scenes as the texture must belong to one scene only. The idea would have been to use the texture as opacity and emissive. And also play with two camers with layermasks

So more complex and less efficient:)

More info: Babylon.js Documentation

OK, got it. So this is really more for mirror effects and stuff like that, right?

yes…what you want could work as I mentioned but not with 2 scenes :slight_smile: