# Manually trigger render of interdependant CustomProceduralTextures

**URL:** <https://forum.babylonjs.com/t/manually-trigger-render-of-interdependant-customproceduraltextures/50377>\
**Category:** Questions\
**Tags:** dynamic-texture\
**Created:** [May 8, 2024, 8:18am UTC](https://forum.babylonjs.com/t/manually-trigger-render-of-interdependant-customproceduraltextures/50377 "2024-05-08T08:18:17Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ilja](https://avatars.discourse-cdn.com/v4/letter/i/8baadc/32.png) [@ilja](https://forum.babylonjs.com/u/ilja)\
**Post date:** [May 8, 2024, 8:18am UTC](https://forum.babylonjs.com/t/manually-trigger-render-of-interdependant-customproceduraltextures/50377/1 "2024-05-08T08:18:17Z")

</div>

> **[Babylon.js Playground](https://playground.babylonjs.com/#E85UCM%2326)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

In this playground there are 3 textures:

- texture1 = red color
- texture2 = texture1 + green color → yellow color
- texture3 = texture2 + blue color → white color

All textures have refreshrate = 0

If I instantiate the textures in order 1, 2, 3, the sphere has a white color.

However, I instantiate the textures in order 3, 2, 1 on purpose → the sphere has a blue color.

How can I manually trigger a render of the 3 textures in the order I want (1, 2, 3) to get a white sphere?

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [May 8, 2024, 9:11am UTC](https://forum.babylonjs.com/t/manually-trigger-render-of-interdependant-customproceduraltextures/50377/2 "2024-05-08T09:11:51Z")

</div>

Maybe there is a cleaner solution, but you could always render them once, after they are ready - [CustomProceduralTextures render order | Babylon.js Playground (babylonjs.com)](https://playground.babylonjs.com/#E85UCM#28)

---

<div class="post-metadata">

**Author:** ![Tricotou](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tricotou/32/5844_2.png) [@Tricotou](https://forum.babylonjs.com/u/Tricotou)\
**Post date:** [May 8, 2024, 9:33am UTC](https://forum.babylonjs.com/t/manually-trigger-render-of-interdependant-customproceduraltextures/50377/3 "2024-05-08T09:33:20Z")

</div>

I was trying to provide a similar fix but I was struggling with an inconstancy problem.  
Same appear in your playground : reload multiple times : sometimes (random) result is cyan (RGB = 0,1,1) 🤔

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [May 8, 2024, 9:42am UTC](https://forum.babylonjs.com/t/manually-trigger-render-of-interdependant-customproceduraltextures/50377/4 "2024-05-08T09:42:32Z")

</div>

there is an interesting issue if you set loadJson to false as well, which I was trying to fully understand. I what you are mentioning is a race condition between the isReady() settings of the 3 textures (but I can’t 100% be sure of that…)

Oh, and i just noticed the rendering order in my PG is switched (because I was experimenting a bit). I don’t get cyan anmore after setting them in the right order. - [CustomProceduralTextures render order | Babylon.js Playground (babylonjs.com)](https://playground.babylonjs.com/#E85UCM#29))

---

<div class="post-metadata">

**Author:** ![Tricotou](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tricotou/32/5844_2.png) [@Tricotou](https://forum.babylonjs.com/u/Tricotou)\
**Post date:** [May 8, 2024, 9:47am UTC](https://forum.babylonjs.com/t/manually-trigger-render-of-interdependant-customproceduraltextures/50377/5 "2024-05-08T09:47:00Z")

</div>

By the way, the test setup is not ideal since if you deactivate all texture calls, the result is white (default material) which is the intented result 😁

---

<div class="post-metadata">

**Author:** ![ilja](https://avatars.discourse-cdn.com/v4/letter/i/8baadc/32.png) [@ilja](https://forum.babylonjs.com/u/ilja)\
**Post date:** [May 8, 2024, 10:03am UTC](https://forum.babylonjs.com/t/manually-trigger-render-of-interdependant-customproceduraltextures/50377/6 "2024-05-08T10:03:49Z")

</div>

good point, i lowered the color values to 0.5, so the prefered result is grey 🙂 )

---

<div class="post-metadata">

**Author:** ![ilja](https://avatars.discourse-cdn.com/v4/letter/i/8baadc/32.png) [@ilja](https://forum.babylonjs.com/u/ilja)\
**Post date:** [May 8, 2024, 10:11am UTC](https://forum.babylonjs.com/t/manually-trigger-render-of-interdependant-customproceduraltextures/50377/7 "2024-05-08T10:11:27Z")

</div>

I tested your solution, but sadly the render calls in onBeforeRenderObservable aren’t executed.

You can test this by only assigning the samplers in onBeforeRenderObservable:

> ```
> scene.onBeforeRenderObservable.add(() => {
> if (updateTextures && texture1.isReady() && texture2.isReady() && texture3.isReady()) {
> texture2.setTexture("previousTexture", texture1);
> texture3.setTexture("previousTexture", texture2); 
> texture1.render();
> texture2.render();
> texture3.render();
> updateTextures = false;
> }
> });
> 
> ```

→ blue sphere

I have the impression CustomProceduralTextures follow their own refreshrate logic and ignore any other render calls.

---

<div class="post-metadata">

**Author:** ![RaananW](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/raananw/32/28955_2.png) [@RaananW](https://forum.babylonjs.com/u/RaananW)\
**Post date:** [May 8, 2024, 10:35am UTC](https://forum.babylonjs.com/t/manually-trigger-render-of-interdependant-customproceduraltextures/50377/8 "2024-05-08T10:35:33Z")

</div>

i’ll be honest and say I haven’t debugged the behavior or know exactly why it behaves this way, but you need to render on the 2nd frame to get that to work - [CustomProceduralTextures render order | Babylon.js Playground (babylonjs.com)](https://playground.babylonjs.com/#E85UCM#64). I’ll find time later to understand what happens there
