# Multiple cameras to generate multiple textures at the same time

**URL:** <https://forum.babylonjs.com/t/multiple-cameras-to-generate-multiple-textures-at-the-same-time/20295>\
**Category:** Questions\
**Created:** [April 25, 2021, 5:39am UTC](https://forum.babylonjs.com/t/multiple-cameras-to-generate-multiple-textures-at-the-same-time/20295 "2021-04-25T05:39:42Z")\
**Posts on this page:** 9\
**Page:** 2

<div class="post-metadata">

**Author:** ![Mescalina](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mescalina/32/15512_2.png) [@Mescalina](https://forum.babylonjs.com/u/Mescalina)\
**Post date:** [May 4, 2021, 6:00pm UTC](https://forum.babylonjs.com/t/multiple-cameras-to-generate-multiple-textures-at-the-same-time/20295/21 "2021-05-04T18:00:00Z")

</div>

Thanks.  
I get an error saying:  
tx.readPixels(…).then is not a function

Looks like I can’t use it as a promise, is it because I’m using a texture generated with RenderTargetTexture and not a regular texture as in your example?

The readPixels() returns an array but the .then method is not available

---

<div class="post-metadata">

**Author:** ![Mescalina](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mescalina/32/15512_2.png) [@Mescalina](https://forum.babylonjs.com/u/Mescalina)\
**Post date:** [May 4, 2021, 6:41pm UTC](https://forum.babylonjs.com/t/multiple-cameras-to-generate-multiple-textures-at-the-same-time/20295/22 "2021-05-04T18:41:48Z")

</div>

I managed to make it work using await tx.readPixels() instead of the promise style.  
Thanks a lot 🙂

Is there a method to know when a texture generate with RenderTargetTexture from a camera is filled?  
If I use it straight away even if the isReady parameter is true the resulting texture is black. If I use a setTimeout with 50 milliseconds I get the proper image.  
I’m not confident using a setTimeout cause if it runs on a slower machine or the machine is busier and it takes longer it will result in a black texture.

If I use the tx.onAfterRenderObservable to wait I get a texture that is grey and not anymore black but without the full rendered image in it

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [May 4, 2021, 8:13pm UTC](https://forum.babylonjs.com/t/multiple-cameras-to-generate-multiple-textures-at-the-same-time/20295/23 "2021-05-04T20:13:33Z")

</div>

> [@Mescalina](#):
>
> I managed to make it work using await tx.readPixels() instead of the promise style.  
> Thanks a lot 🙂

That’s because I think you are using 4.2 and in 4.2 `readPixels` is synchronous and returns an `ArrayBufferView`, not a `Promise<ArrayBufferView>`.

> [@Mescalina](#):
>
> Is there a method to know when a texture generate with RenderTargetTexture from a camera is filled?

I think you should be able to use `RenderTargetTexture.onAfterUnbind`.

---

<div class="post-metadata">

**Author:** ![Mescalina](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mescalina/32/15512_2.png) [@Mescalina](https://forum.babylonjs.com/u/Mescalina)\
**Post date:** [May 4, 2021, 9:40pm UTC](https://forum.babylonjs.com/t/multiple-cameras-to-generate-multiple-textures-at-the-same-time/20295/24 "2021-05-04T21:40:50Z")

</div>

Thank you,  
onAfterUnbind seemed to work but after some more testing it appears that once every 10 times (it’s not a fixed amount just a variable observed statistic) the textures is not filled. Any idea if it should be working 100% of the times or if it is a possibility?

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [May 5, 2021, 10:29am UTC](https://forum.babylonjs.com/t/multiple-cameras-to-generate-multiple-textures-at-the-same-time/20295/25 "2021-05-05T10:29:48Z")

</div>

Hum, I think to be on the safe side you should use `engine.onEndFrameObservable` instead.

Another solution that should work is to use `Tools.DumpFramebuffer(width, height, engine, successCallback, mimeType, fileName);` in the `onAfterRenderObservable` observer. `DumpFrameBuffer` will read the data from the currently bound texture, which is still the RTT at this point.

---

<div class="post-metadata">

**Author:** ![Mescalina](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mescalina/32/15512_2.png) [@Mescalina](https://forum.babylonjs.com/u/Mescalina)\
**Post date:** [May 5, 2021, 12:23pm UTC](https://forum.babylonjs.com/t/multiple-cameras-to-generate-multiple-textures-at-the-same-time/20295/26 "2021-05-05T12:23:13Z")

</div>

You are amazing Evgeni, it’s so cool to learn this amazing library knowing that I can rely on somebody like you.  
engine.onEndFrameObservable seems to be reliable 100% of times.  
Thanks so much 🙂

---

<div class="post-metadata">

**Author:** ![Mescalina](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mescalina/32/15512_2.png) [@Mescalina](https://forum.babylonjs.com/u/Mescalina)\
**Post date:** [May 6, 2021, 7:02am UTC](https://forum.babylonjs.com/t/multiple-cameras-to-generate-multiple-textures-at-the-same-time/20295/27 "2021-05-06T07:02:19Z")

</div>

Hi, I’m back with the question of the day 🙂  
Now everything works perfectly but I have a small issue with the Sampling Mode.  
When I use BABYLON.Texture.NEAREST\_NEAREST with low res textures to achieve a pixelated effect I always have an artifact, a thin line in the middle of the textures. I’ve tried all similar sampling modes but the issue is always there. Even if I set it in the constructor instead of later using tx.updateSamplingMode.

Any idea where that artifact is coming from?

EDIT: I found a working solution using non power of 2 sizes for the RenderTargetTexture, it results in slightly less defined textures but the artifact is gone, i guess thanks to the internal texture resampling. But still, if possible, I would like to understand what’s causing the artifact in the first place.

Thanks as usual

![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/9/917b6053b7aa5278bc0ecac8be4d793cf6046027.png)  
 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/2X/b/bd909fd8b43a939f6c2ba784fa7c347dcd69581e.png)

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [May 6, 2021, 7:42am UTC](https://forum.babylonjs.com/t/multiple-cameras-to-generate-multiple-textures-at-the-same-time/20295/28 "2021-05-06T07:42:59Z")

</div>

Hard to say without a repro. Have you tried to set the wrap mode to clamp?

---

<div class="post-metadata">

**Author:** ![Mescalina](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mescalina/32/15512_2.png) [@Mescalina](https://forum.babylonjs.com/u/Mescalina)\
**Post date:** [May 6, 2021, 9:35am UTC](https://forum.babylonjs.com/t/multiple-cameras-to-generate-multiple-textures-at-the-same-time/20295/29 "2021-05-06T09:35:55Z")

</div>

Using tx.wrapR = BABYLON.Texture.CLAMP\_ADDRESSMODE totally fixed the issue.  
I virtually hug you 🙂  
Bless

[Previous page](https://forum.babylonjs.com/t/multiple-cameras-to-generate-multiple-textures-at-the-same-time/20295.md?page=1)
