# How to capture scene depth into an image and then sample it?

**URL:** <https://forums.unrealengine.com/t/how-to-capture-scene-depth-into-an-image-and-then-sample-it/573213>\
**Category:** Rendering\
**Tags:** Render, unreal-engine, Rendering, Shaders, question, UE4-27\
**Created:** [June 3, 2022, 1:29pm UTC](https://forums.unrealengine.com/t/how-to-capture-scene-depth-into-an-image-and-then-sample-it/573213 "2022-06-03T13:29:26Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![motorsep](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/motorsep/32/918698_2.png) [@motorsep](https://forums.unrealengine.com/u/motorsep)\
**Post date:** [June 3, 2022, 1:29pm UTC](https://forums.unrealengine.com/t/how-to-capture-scene-depth-into-an-image-and-then-sample-it/573213/1 "2022-06-03T13:29:26Z")

</div>

I need to capture scene depth for my level, top down view. I am using Scene Capture 2D component placed on the level and this is what I am getting:

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/0/9/209fb8afc82bacd08a8c40e1f55fd5c6a4d27edc.jpeg "2022 06 02 21 40 11") ](https://www.youtube.com/watch?v=PkQpupwp-g0)

When I worked with depth in other engines and 3D apps, it was always a grayscale image with smooth transitions (kinda like a heightmap). I am not quite sure why it’s coming out like a stencil mask in UE4. If I capture scene color, the image comes out the way it suppose to come out.  
So that’s the first issue I need to resolve.

The second question is once I have a proper depth image, how do I sample it in BPs or Niagara 's Sketch ? I need to get world Z value for the depth pixels.

I am using UE 4.27.2, forward rendering.

Thanks!

---

<div class="post-metadata">

**Author:** ![Arkiras](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/arkiras/32/1008648_2.png) [@Arkiras](https://forums.unrealengine.com/u/Arkiras)\
**Post date:** [June 3, 2022, 2:26pm UTC](https://forums.unrealengine.com/t/how-to-capture-scene-depth-into-an-image-and-then-sample-it/573213/2 "2022-06-03T14:26:22Z")

</div>

This is expected. Unreals base unit is centimeters, which means 0-1 (the maximum range that can be displayed on your monitor) is only 1 centimeter. It’s not meant to be human readable. Almost the entirety of the scene is outside the visible range, but assuming you are using a 16+ bit render target the data is still there.

> [@motorsep](#):
>
> The second question is once I have a proper depth image, how do I sample it in BPs or Niagara 's Sketch ? I need to get world Z value for the depth pixels.

Textures can be sampled from Blueprint using the node (I think it’s called) `ReadRenderTargetPixel`. It is _insanely_ slow, and not suitable for realtime.

Niagara has a texture sampling module, you can open it up and look at it. Sampling textures can only be done in GPU emitters.

---

<div class="post-metadata">

**Author:** ![motorsep](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/motorsep/32/918698_2.png) [@motorsep](https://forums.unrealengine.com/u/motorsep)\
**Post date:** [June 3, 2022, 2:32pm UTC](https://forums.unrealengine.com/t/how-to-capture-scene-depth-into-an-image-and-then-sample-it/573213/3 "2022-06-03T14:32:51Z")

</div>

> [@Arkiras](#):
>
> This is expected. Unreals base unit is centimeters, which means 0-1 (the maximum range that can be displayed on your monitor) is only 1 centimeter. It’s not meant to be human readable. Almost the entirety of the scene is outside the visible range, but assuming you are using a 16+ bit render target the data is still there.

I am using I am using 16 bit Red channel only render target. When I export it to HDR and open it in GIMP (which works with 32bit images), Red channel is just plain white.  
My level is 5km^2 large. What settings in the Scene Capture 2D do I need to use to capture depth properly (I only need to capture it once, in the Editor or PIE and then sample that render target in runtime) ?

---

<div class="post-metadata">

**Author:** ![Arkiras](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/arkiras/32/1008648_2.png) [@Arkiras](https://forums.unrealengine.com/u/Arkiras)\
**Post date:** [June 3, 2022, 2:38pm UTC](https://forums.unrealengine.com/t/how-to-capture-scene-depth-into-an-image-and-then-sample-it/573213/4 "2022-06-03T14:38:31Z")

</div>

> [@motorsep](#):
>
> I am using I am using 16 bit Red channel only render target

Yes, and the output is correct. Again, it’s not meant to be human readable. You can’t export it and expect it to look right, all the values are still too high to be displayed.

If you want to bring it into a visible range then you will have to divide it by a large number. This is useful for debugging but completely unnecessary for sampling it:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/2/9/429d53d78d6feae1378706c3a464eec9ee84291f.jpeg)

---

<div class="post-metadata">

**Author:** ![motorsep](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/motorsep/32/918698_2.png) [@motorsep](https://forums.unrealengine.com/u/motorsep)\
**Post date:** [June 3, 2022, 6:45pm UTC](https://forums.unrealengine.com/t/how-to-capture-scene-depth-into-an-image-and-then-sample-it/573213/5 "2022-06-03T18:45:12Z")

</div>

> [@Arkiras](#):
>
> Textures can be sampled from Blueprint using the node (I think it’s called) `ReadRenderTargetPixel`. It is _insanely_ slow, and not suitable for realtime.

Maybe I can use this data to construct blocking volumes (not sure if I can “spawn” a volume in Construction script)

> [@Arkiras](#):
>
> Niagara has a texture sampling module, you can open it up and look at it. Sampling textures can only be done in GPU emitters.

GPU-only, ouch ☹ Do you happen to know how it works ? Basically, I need to get value of a pixel that is closest to a given particle in the world coordinates.

---

<div class="post-metadata">

**Author:** ![Arkiras](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/arkiras/32/1008648_2.png) [@Arkiras](https://forums.unrealengine.com/u/Arkiras)\
**Post date:** [June 3, 2022, 8:39pm UTC](https://forums.unrealengine.com/t/how-to-capture-scene-depth-into-an-image-and-then-sample-it/573213/6 "2022-06-03T20:39:50Z")

</div>

> [@motorsep](#):
>
> GPU-only, ouch ☹ Do you happen to know how it works ? Basically, I need to get value of a pixel that is closest to a given particle in the world coordinates.

It returns the sampled color given a UV coordinate. Assuming this is a top-down projection of your entire level you should be able to just divide the particle XY coordinate by the length/width of the capture area (in world units) and then adding 0.5

It’s been a while since I’ve worked with it but there are examples of this in the Niagara maps in the Content Examples

---

<div class="post-metadata">

**Author:** ![motorsep](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/motorsep/32/918698_2.png) [@motorsep](https://forums.unrealengine.com/u/motorsep)\
**Post date:** [June 4, 2022, 11:43pm UTC](https://forums.unrealengine.com/t/how-to-capture-scene-depth-into-an-image-and-then-sample-it/573213/7 "2022-06-04T23:43:20Z")

</div>

> [@Arkiras](#):
>
> If you want to bring it into a visible range then you will have to divide it by a large number. This is useful for debugging but completely unnecessary for sampling it:
> 
> ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/2/9/429d53d78d6feae1378706c3a464eec9ee84291f.jpeg)

~~Unfortunately that doesn’t work for me - my material that should show render target shows solid gray color (and when I change denominator, it just goes from white to gray to black).~~

Finally got it working (those faint dots are trees 🙂 )!

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/5/6/e56f6ddacbaac7b5990963f147b127a3a4a4646f.jpeg)

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/c/8/1c806c73c4f5fe84406d9937d1e06f64e683acf9.jpeg "2022 06 04 20 24 28") ](https://www.youtube.com/watch?v=lcYXqJtoy6U)

Had to use 32f instead of 16f.

---

<div class="post-metadata">

**Author:** ![Anthony\_Attwood](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Anthony\_Attwood](https://forums.unrealengine.com/u/Anthony_Attwood)\
**Post date:** [May 17, 2024, 9:00pm UTC](https://forums.unrealengine.com/t/how-to-capture-scene-depth-into-an-image-and-then-sample-it/573213/8 "2024-05-17T21:00:43Z")

</div>

how? lol

---

<div class="post-metadata">

**Author:** ![Anonymous\_d7b5747480e1702fc3dbbbcc1d18eb95](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Anonymous\_d7b5747480e1702fc3dbbbcc1d18eb95](https://forums.unrealengine.com/u/Anonymous_d7b5747480e1702fc3dbbbcc1d18eb95)\
**Post date:** [September 23, 2026, 9:15am UTC](https://forums.unrealengine.com/t/how-to-capture-scene-depth-into-an-image-and-then-sample-it/573213/9 "2026-09-23T09:15:58Z")

</div>

I tried it but it didn’t work; please tell me exactly how to do it.
