Pastering an external canvas over the scene

Good morning everybody

My goal is to show the result of an external canvas over the BABYLON scene. To simplify, the external canvas and BABYLON canvas has the same size. I’ve been trying 2 approaches:

  1. Custom post processing with a fragment shader
  2. GUI in full screen

The post processing doesn’t work because I think BABYLON doesn’t accept external textures and they default to the canvas the scene is using (engine.externalTexture.ts line 28). This is a example I set up where I can use the canvas 2 as material, but not as post processing:

The GUI is a complete mystery to me. The closest thing is , but it uses BABYLON.GUI.Image which requires an URL

Thanks in advance.

Hi Nasma, and welcome to the forum.

I am not at my computer at the moment (just on my phone) but i have done something like this by overlaying the non-BJS canvas on top (higher z-order) of the BJS canvas using css.
You can get the bounding box of a gui rectangle and even scale and position your non-BJS canvas accordingly. But i don’t know if that will suit your use case.

Hi Mark, thanks, nice to meet you too.

I need to merge them into a single canvas. I understand what you say but is not a solution for my case. The examples I prepared are not what I’m working at, just proofs of concept.

What about using canvas context drawImage HTML canvas drawImage() Method
I have used this approach as well. Once you get the context of the target canvas you can use another canvas as a source.

It is late here and i am just siting on my deck with a few wines throwing out ideas - i will look at your PG tomorrow.:slight_smile:

Was this what you were after:


Hi Mark

Sorry for my late reply, as you it was late last time I wrote, and I just got to see your message.

I’ve just opened your link and it looks like the effect is that, I just didn’t read the code yet. I’ll do today and come back to you.

Thanks :slight_smile:

No worries. If it is what you want then you were oh so close. All I really did was change the [“canvas2”] parameter to be the forth, rather than third, parameter. The third is for non-samplers while the forth is for samplers. Then you don’t need the callback as it is all set.

1 Like

Hi Mark, I’m back

I tested your solution in my project and it works perfectly.

Thanks for your help, if I can buy you a beer please let me know.

Take care.


Just happy to help as part of the community - that’s what we do.

But if we are ever in the same physical location at the same time then we will definitely have a beer :slight_smile:

1 Like