# Get the depth map of a set of meshes

**URL:** <https://forum.babylonjs.com/t/get-the-depth-map-of-a-set-of-meshes/42368>\
**Category:** Questions\
**Tags:** documentation, gui, camera, mesh\
**Created:** [July 12, 2023, 11:32pm UTC](https://forum.babylonjs.com/t/get-the-depth-map-of-a-set-of-meshes/42368 "2023-07-12T23:32:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chen\_Chen](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Chen\_Chen](https://forum.babylonjs.com/u/Chen_Chen)\
**Post date:** [July 12, 2023, 11:32pm UTC](https://forum.babylonjs.com/t/get-the-depth-map-of-a-set-of-meshes/42368/1 "2023-07-12T23:32:40Z")

</div>

Hi Everyone,

We are trying to get the depth map of a set of meshes, and running into couple of problems.

**(1) Getting the depth map of a set of meshes.**

We realized that using following code could get the depth map:

```auto
    var depthRender = scene.enableDepthRenderer(camera, true);
    var renderDepthTexture = depthRender.getDepthMap();

```

However, it seems that the depth map include all objects in the scene. Is there any possibility of get the depth map of a customized set of meshes (instead of all meshes)?

It seems that there is a `setMaterialForRendering` method for `TargetRenderer`, however it looks like it doesn’t work as expected?

I quickly created a playground: [https://playground.babylonjs.com/#KHIVV1#1](https://playground.babylonjs.com/#KHIVV1#1). And I am wondering that is there anyway to get the depth map, but only for the sphere (not the ground).

**(2) How to normalize the depth map, to augment the details of the meshes?**

There are a couple of notes (such as [this one](https://forum.babylonjs.com/t/why-depth-renderer-texture-only-gave-me-0-and-1/24636/3)) that indicate that by adjusting the clipping planes of camera (`camera.minZ`, and `camera.maxZ`), we could augment the details of the depth map. However, making the clipping distance smaller will also create challenge for the meshes to be navigated in the 3D canvas.

I am wondering if there is anyway to simply set the `minZ` as the shortest distance to the selected meshes, and `maxZ` as the longest distance to the selected meshes?

We have tried to augment the pixel with following pseudo code:

```auto
renderDepthTexture.readPixels(undefined, undefined, undefined, false, false).then((data) => {                    
    Tools.DumpData(
        renderDepthTexture.getRenderWidth(), 
        renderDepthTexture.getRenderHeight(), 
        data, (dataUrl) => {
               // min_pixel = minimal value of pixel except 0
               // max_pixel = maximum value of pixel except 255
               // each_pixel = 255 * (read_pixel - min_pixel) / (max_pixel - min_pixel)                   
        });
    });
});

```

Thank you so much! All suggestions are welcome!

---

<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:** [July 13, 2023, 8:28am UTC](https://forum.babylonjs.com/t/get-the-depth-map-of-a-set-of-meshes/42368/2 "2023-07-13T08:28:57Z")

</div>

You can use the `renderList` property of `renderDepthTexture` to render only the meshes you want:

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

Regarding 2, if the camera can move inside the scene (and even more if the meshes themselves can move), you don’t really have a shortest/longest distance to a mesh. If the camera and the meshes don’t move at all, then you can use the bounding boxes of the meshes to calculate the minimal / maximal distances you are after.
