# How to access depth of RenderTargetTexture?

**URL:** <https://forum.babylonjs.com/t/how-to-access-depth-of-rendertargettexture/40637>\
**Category:** Questions\
**Tags:** rendering\
**Created:** [May 9, 2023, 5:33pm UTC](https://forum.babylonjs.com/t/how-to-access-depth-of-rendertargettexture/40637 "2023-05-09T17:33:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MiikaH](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/miikah/32/23054_2.png) [@MiikaH](https://forum.babylonjs.com/u/MiikaH)\
**Post date:** [May 9, 2023, 5:33pm UTC](https://forum.babylonjs.com/t/how-to-access-depth-of-rendertargettexture/40637/1 "2023-05-09T17:33:08Z")

</div>

Any pointers what I am doing wrong here?

This is a very simple setup that renders stuff to RenderTargetTexture and then a node material that just renders the texture back on screen: [https://www.babylonjs-playground.com/#27GIQD#2](https://www.babylonjs-playground.com/#27GIQD#2)

Problem: As soon as I call `opaqueRenderTarget.createDepthStencilTexture()` which to my understanding just results the render target to use a texture as depth buffer, nothing is visible in the rendered texture anymore. And the depth component when rendered is just red (I suppose because the depth exists only in the red / x channel of the texture and with no content is 1.0): [https://www.babylonjs-playground.com/#27GIQD#1](https://www.babylonjs-playground.com/#27GIQD#1)

Why does the rendered content disappear when using depth texture?

---

<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:** [May 9, 2023, 10:46pm UTC](https://forum.babylonjs.com/t/how-to-access-depth-of-rendertargettexture/40637/2 "2023-05-09T22:46:29Z")

</div>

cc @Evgeni_Popov

---

<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 9, 2023, 11:55pm UTC](https://forum.babylonjs.com/t/how-to-access-depth-of-rendertargettexture/40637/3 "2023-05-09T23:55:10Z")

</div>

You can’t use MSAA with a depth texture in WebGL, so you must set samples = 1 when both creating the opaque render target and when creating the depth/stencil texture:

> **[Babylon.js Playground](https://www.babylonjs-playground.com/#27GIQD%237)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

A depth texture has only a red component, that’s why the texture appears red.
