# How to tint stencil using postprocess

**URL:** <https://forum.babylonjs.com/t/how-to-tint-stencil-using-postprocess/49461>\
**Category:** Questions\
**Tags:** postprocessing\
**Created:** [April 8, 2024, 10:11am UTC](https://forum.babylonjs.com/t/how-to-tint-stencil-using-postprocess/49461 "2024-04-08T10:11:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Starryi](https://avatars.discourse-cdn.com/v4/letter/s/fbc32d/32.png) [@Starryi](https://forum.babylonjs.com/u/Starryi)\
**Post date:** [April 8, 2024, 10:11am UTC](https://forum.babylonjs.com/t/how-to-tint-stencil-using-postprocess/49461/1 "2024-04-08T10:11:10Z")

</div>

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

I use an postproces to tint stencil template, but it doesnot work.

It is expected that two meshes will be red.

---

<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:** [April 9, 2024, 9:15am UTC](https://forum.babylonjs.com/t/how-to-tint-stencil-using-postprocess/49461/2 "2024-04-09T09:15:13Z")

</div>

Assigned @Evgeni\_Popov on April 9, 2024, 9:15am UTC



---

<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:** [April 9, 2024, 9:32am UTC](https://forum.babylonjs.com/t/how-to-tint-stencil-using-postprocess/49461/3 "2024-04-09T09:32:32Z")

</div>

It’s a bit complicated because you have to create the depth/stencil texture for the post-process, so that the stencil part can be reused.

Also, you must create two post-processes, because the render target of the first one will be used as the output for the scene rendering, while the second will be used as the output of your post-process shader. You must reuse the depth/stencil texture of the first post-process when running your shader: this is done thanks to the `_shareDepth` method of `RenderTargetWrapper` (see line 60):

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

As this method is often used, I made a PR so that it is visible by the end-user. I also fixed the `_depthStencilTextureWithStencil` property that should be set automatically by `shareDepth`:

> <https://github.com/BabylonJS/Babylon.js/pull/14961>

When this PR is merged, the code can be simplified a bit to:

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

---

<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:** [April 9, 2024, 9:33am UTC](https://forum.babylonjs.com/t/how-to-tint-stencil-using-postprocess/49461/4 "2024-04-09T09:33:57Z")

</div>

Unassigned @Evgeni\_Popov on April 9, 2024, 9:33am UTC



---

<div class="post-metadata">

**Author:** ![Starryi](https://avatars.discourse-cdn.com/v4/letter/s/fbc32d/32.png) [@Starryi](https://forum.babylonjs.com/u/Starryi)\
**Post date:** [April 11, 2024, 5:24am UTC](https://forum.babylonjs.com/t/how-to-tint-stencil-using-postprocess/49461/5 "2024-04-11T05:24:50Z")

</div>

perfect, thanks a lot.
