# How to convert depthmap from depth renderer to a static texture?

**URL:** https://forum.babylonjs.com/t/how-to-convert-depthmap-from-depth-renderer-to-a-static-texture/27522
**Category:** Questions
**Tags:** material
**Created:** [February 10, 2022, 8:29am UTC](https://forum.babylonjs.com/t/how-to-convert-depthmap-from-depth-renderer-to-a-static-texture/27522 "2022-02-10T08:29:34Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Pythonix](https://avatars.discourse-cdn.com/v4/letter/p/b3f665/32.png) [@Pythonix](https://forum.babylonjs.com/u/Pythonix)
#### Post date: [February 10, 2022, 8:29am UTC](https://forum.babylonjs.com/t/how-to-convert-depthmap-from-depth-renderer-to-a-static-texture/27522/1 "2022-02-10T08:29:34Z")

</div>

Hello everyone,  
As depth renderer is binding with the scene camera, the depthmap texture retrieved using `getDepthMap` is dynamic, I want to save the depthmap from depth renderer at some moments to a Texture. I am now coding like below to implement this:

```auto
// at some moment
var depth_arr = await depth_renderer.getDepthMap().readPixels(); // a float32 array
var depth_texture = RawTexture.CreateRTexture(depth_arr, 1920, 1080, this.scene, false, false, Texture.BILINEAR_SAMPLINGMODE, Engine.TEXTURETYPE_FLOAT);

```

the depth\_texture constructed by CreateRTexture is strange:

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/8/d/8d9183a91c225e345c5a5abd1b57be84669afe9f.png)

Is there something wrong with my code?

Thanks for your help in advance!

---

<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: [February 10, 2022, 10:36am UTC](https://forum.babylonjs.com/t/how-to-convert-depthmap-from-depth-renderer-to-a-static-texture/27522/2 "2022-02-10T10:36:34Z")

</div>

Welcome aboard!

In WebGL, `Texture.readPixels` always return RGBA data. So, you should either use `CreateRGBATexture` instead of `CreateRTexture` of create a new buffer from `depth_arr` that will only contain the r component.

- first case: [https://playground.babylonjs.com/#1PHYB0#140](https://playground.babylonjs.com/#1PHYB0#140)
- second case: [https://playground.babylonjs.com/#1PHYB0#141](https://playground.babylonjs.com/#1PHYB0#141)

You can call `doit()` in the console of the browser to create the texture and see it in the inspector.
