# SceneCapture Depth as Texture

**URL:** <https://forums.unrealengine.com/t/scenecapture-depth-as-texture/434150>\
**Category:** Asset Creation\
**Tags:** Scene-Capture, depth, unreal-engine, render-target, question\
**Created:** [September 20, 2018, 1:39pm UTC](https://forums.unrealengine.com/t/scenecapture-depth-as-texture/434150 "2018-09-20T13:39:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_c3e69a5a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_c3e69a5a](https://forums.unrealengine.com/u/anonymous_user_c3e69a5a)\
**Post date:** [September 20, 2018, 1:39pm UTC](https://forums.unrealengine.com/t/scenecapture-depth-as-texture/434150/1 "2018-09-20T13:39:58Z")

</div>

Hi, I want to get a depth map from a specific view. And I want it as texture because I want to be able to access the data in C++.

So I did the following setup. I placed a SceneCapture2D in the view I want. In the rendering settings it should render the scene into rgb and the depht into a-channel of a rendertarget:

 ![254214-testsetup-scenecapturesetup.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/0/2/d0253b16837c8749d9ff0e3fe0f344a4c29936eb.jpeg)

When It take a look at the render target, the rgb channels are good:

 ![254215-testsetup-bodyrgb.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/9/1/991424ad8a0e5ecf418692faaba4bfaf0ef16a8d.jpeg)

but the alpha channel does not contain any depth map - it´s just white:

 ![254216-testsetup-bodyalpha.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/d/6/2d68c928f68677e61e27c3ae5c70e94d397621ef.jpeg)

Am I doing something wrong? Or is there another way to do this?  
Thanks in advance!

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_c3e69a5a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_c3e69a5a](https://forums.unrealengine.com/u/anonymous_user_c3e69a5a)\
**Post date:** [September 21, 2018, 11:32am UTC](https://forums.unrealengine.com/t/scenecapture-depth-as-texture/434150/2 "2018-09-21T11:32:40Z")

</div>

Ok after a little research I think I might know what the problem is. The Depth Stream (comming from SceneDepth or PixelDepth or whereelse) is always the distance in cm. So, the every pixel in the depth scene has a value \> 1 because its at least a few cm away - but when you cast this to a color, you just see white.

I have two options now: finding an option in SceneCapture2D where you can set a depth divider (to get the max depth and a value from 0 to 1 - see here: [Scene Depth capture does not work - Rendering - Epic Developer Community Forums](https://answers.unrealengine.com/questions/723922/scene-depth-capture-does-not-work.html))  
Or use some code or blueprint to access the pixel values and divide them manually (or at least see whether I am right anyway).

I´m gonny keep updating

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_c3e69a5a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_c3e69a5a](https://forums.unrealengine.com/u/anonymous_user_c3e69a5a)\
**Post date:** [September 21, 2018, 11:47am UTC](https://forums.unrealengine.com/t/scenecapture-depth-as-texture/434150/3 "2018-09-21T11:47:59Z")

</div>

Ok yes it was the problem with alpha values \> 1 because the depth was \> 1 cm.  
I fixed it by creating a second material using only the alpha channel (where the depth value is written), divide it by my maximum distance I want and LERP to get a _white is close, black is far_ image:

 ![254313-testsetup-depthmaterialfixed.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/c/1/cc17b07e405c4c55a288820c36878580229dcc77.jpeg)

To look at the result, I placed two planes, one using a material with the rgb color, one using the lastly created with depth:

 ![254314-testsetup-scenecapturefixed.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/b/f/bbfdce46160505afa164a2d19467838b365b58b8.jpeg)

Note that the TextureRenderTarget has the format “RTF RGBA32f”.

---

<div class="post-metadata">

**Author:** ![Zeclown](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Zeclown](https://forums.unrealengine.com/u/Zeclown)\
**Post date:** [November 6, 2018, 5:01am UTC](https://forums.unrealengine.com/t/scenecapture-depth-as-texture/434150/4 "2018-11-06T05:01:47Z")

</div>

Thank you so much, I thought I was going crazy!

---

<div class="post-metadata">

**Author:** ![Studio\_Marvin\_3D1](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/studio_marvin_3d1/32/570015_2.png) [@Studio\_Marvin\_3D1](https://forums.unrealengine.com/u/Studio_Marvin_3D1)\
**Post date:** [March 28, 2024, 2:33pm UTC](https://forums.unrealengine.com/t/scenecapture-depth-as-texture/434150/6 "2024-03-28T14:33:14Z")

</div>

Great solution, man! Thanks for sharing! Allow me to make just a little adjust, using a “Remap Value Range” node, instead of “Divide”. It allow us to set the max and min targets.

 ![Captura de tela 2024-03-28 112815](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/8/e/58e877856aa2eb68b5d037a416fa9c6f95863f68.jpeg)
