# \`setMaterialForRendering\` of \`renderTargetTexture\` not exist

**URL:** <https://forum.babylonjs.com/t/setmaterialforrendering-of-rendertargettexture-not-exist/24686>\
**Category:** Bugs\
**Created:** [October 19, 2021, 11:38am UTC](https://forum.babylonjs.com/t/setmaterialforrendering-of-rendertargettexture-not-exist/24686 "2021-10-19T11:38:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tanpopo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tanpopo/32/32025_2.png) [@tanpopo](https://forum.babylonjs.com/u/tanpopo)\
**Post date:** [October 19, 2021, 11:38am UTC](https://forum.babylonjs.com/t/setmaterialforrendering-of-rendertargettexture-not-exist/24686/1 "2021-10-19T11:38:40Z")

</div>

Document link: [Render Target Texture With Multiple Passes | Babylon.js Documentation](https://doc.babylonjs.com/divingDeeper/postProcesses/renderTargetTextureMultiPass).  
I just found the function on the document but failed to find it in source code on master branch as well as the issues nor the PR. I noticed that there is only a PR on the document.

---

<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:** [October 19, 2021, 12:10pm UTC](https://forum.babylonjs.com/t/setmaterialforrendering-of-rendertargettexture-not-exist/24686/2 "2021-10-19T12:10:57Z")

</div>

@sebavan , any idea here?

---

<div class="post-metadata">

**Author:** ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)\
**Post date:** [October 19, 2021, 12:58pm UTC](https://forum.babylonjs.com/t/setmaterialforrendering-of-rendertargettexture-not-exist/24686/3 "2021-10-19T12:58:12Z")

</div>

Yup the PR from @Evgeni_Popov containing the code is coming tonight 🙂

> <https://github.com/BabylonJS/Documentation/pull/357>
>
> Also added a "Compute shader" entry under \`WebGPU\`.

---

<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:** [October 19, 2021, 5:17pm UTC](https://forum.babylonjs.com/t/setmaterialforrendering-of-rendertargettexture-not-exist/24686/4 "2021-10-19T17:17:36Z")

</div>

If you want to follow the status:

> <https://github.com/BabylonJS/Babylon.js/pull/11304>
>
> The implementation is not finished yet but the PR is already quite big, so there… will be another one (normally quite smaller!) to account for the missing bits (the biggest one being adding support for submeshes in \`ShaderMaterial\`).
> 
> Some quick numbers before describing the PR:
> \* even if it's a WebGPU PR, some changes also affect WebGL (like the render passes) that improve performances: the JS thread takes between 5% and 20% less time on the PGs I have tested compared to WebGL 4.2 (it's also better than the current WebGL 5.0 code in prod)
> \* WebGPU:
> \* the JS thread takes between 10% and 16% \*\*more\*\* time than in WebGL in the \*compatibility mode\* (that is, with \`engine.compatibilityMode = true\`). It's expected, in this mode we have to use a number of caches that slow things down in WebGPU
> \* the JS thread takes between 14% and 20% \*\*less\*\* time than in WebGL in the \*non compatibility mode\* (that is, with \`engine.compatibilityMode = false\`, the purpose of the PR)
> \* note that the comparison with WebGL is done against the numbers measured \*\*with\*\* this PR for WebGL, not against the WebGL code currently in prod!
> 
> Here's an overview of the PR:
> \* I have added render pass ids, which are simply ids that are assigned to each "render pass". Basically, the main render pass (the one rendering the scene into the framebuffer) is always id #0 and each rendering by a \`RenderTargetTexture\` is using a specific id (or several, if the RTT is a cube or a 2D layer). The id(s) are allocated in the class constructor. This id is used to retrieve the right \`DrawWrapper\` on the submesh that is currently rendered (those wrappers are stored in the \`SubMesh.\_drawWrappers\` array: the index in this array is the render pass id). In WebGPU that allows to have a bundle cached (in \`DrawWrapper.drawContext\`) for each rendering and reusing it when in the \_non compatibility mode\_. However, it's also a perf gain in WebGL because the effects are not recreated/retrieved from the engine each time we execute \`isReadyForSubMesh\` but are retrieved from the \`DrawWrapper\`.
> \* I'm going to create a doc page about render pass ids and how they allow to use a different material depending on the pass (render target) a mesh is rendered into =\> see \`RenderTargetTexture.setMaterialForRendering\` in the current PR, but I have also added this method to the depth renderer (\`DepthRender.setMaterialForRendering\`). I will also update the \`EffectLayer\` class with this feature.
> \* Regarding post processes, I needed to know if one is going to overwrite the \`textureSampler\` texture of the shader. Indeed, the \`PostProcess\` class (in the \`apply\` method) is setting the value with the source input value, but some effects were overwriting it just afterward in a \`postprocess.onApplyObserver\` observer: in WebGPU it kills the bundle cache because it dirtyfies the material context. So, setting \`postprocess.externalTextureSamplerBinding = true\` instructs the \`PostProcess\` class to \*\*not\*\* update the value itself because it will be done by some external code. Note it's an optimization (for WebGPU): if you don't do it it still work, but you will have some bundles recreated each frame that could be avoided.
> \* When in fast mode, if using instances, we use an indirect draw to be able to update the instance count without recreating the cached bundle: we simply need to update the buffer holding the draw parameters (and more precisely the instance count parameter)
