<p>This is just a visualisation. Type the command vis scenedepthz uv0 to see the actual depth buffer used. UE4 uses a "reversed" depth buffer for the scene.</p>

CC BY-SA 3.0
2017-09-14T14:39:43.210Z
2017-09-14T14:39:43.210Z
Syntac_
<p>While I have no idea how UnrealEngine handle depth I have thought of a technique which would result in that kind of depth output.</p>

<p>The idea is to better manage Z-fighting by rendering multiple (stacked) frustums with shorter distance between ner and far planes. Each step in the cascade would represent one of those frustums. Using near/far plane clipping, stencil masking and optional vf-culling you can easily render the cascade front-to-back, or each frustum to each own framebuffer and consolidate afterwards, with only minor hit in performance.</p>

<p>This should scale better than increasing depth buffer bit depth which has diminishing returns. Besides not all platforms support high bit depth. OpenGL ES require only 16 bits!</p>

<p>It is just a theory though :-)</p>

CC BY-SA 3.0
2017-09-14T13:53:26.893Z
That could work. IMO it will require too much extra work and maybe the performance won't be that great! Reversed depth FTW :3
Nacho
CC BY-SA 3.0
2017-09-13T17:56:57.697Z
2017-09-13T17:56:57.697Z
Andreas
<p>Today I found something really interesting (I've never seen something like that). While debugging the buffers used in lightning, I see that the depth information is stored in what looks like cascades of depth.</p>

<p><a href="https://i.sstatic.net/brV9I.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/brV9I.png" alt="UE4 Depth Buffer"></a></p>

<p>What's going on there? Is that a technique to improve depth precision?</p>

<p>Thanks!</p>

CC BY-SA 3.0
2017-08-10T10:38:25.367Z
I've only seen something like this when someone has interpreted the bottom 8 bits of a 16- or 24-bit depth buffer as an image channel. How did you generate this image?
Dan Hulme
CC BY-SA 3.0
2017-08-10T10:44:15.077Z
@DanHulme With the buffer visualiser: https://docs.unrealengine.com/latest/INT/Engine/UI/LevelEditor/Viewports/ViewModes/#buffervisualization
Nacho
CC BY-SA 3.0
2017-08-11T02:43:03.517Z
It could be a visualisation aid, instead of showing the depth as 1 gradient you can scale it to fit inside 3 steeper gradients. This is especially helpful for objects near the camera which have less variation in terms of depth.
PaulHK
CC BY-SA 3.0
2017-08-11T08:32:20.533Z
@PaulHK yeah it could be, I mean, it actually repeats more than 3 times, it repeats indefinitely!
Nacho
CC BY-SA 3.0
2017-08-11T11:12:28.520Z
the upper 2 bytes would have a resolution of 256*256 = 65536. If the depth buffer is 32 bits then that increases to 16777216. That may seem indefinite at first glance.
ratchet freak
<lighting><depth-map>
How does UnrealEngine handle depth?
Nacho
# How does UnrealEngine handle depth?

(Asked by: username_0 on 2017-08-10)

Today I found something really interesting (I've never seen something like that). While debugging the buffers used in lightning, I see that the depth information is stored in what looks like cascades of depth.

[![UE4 Depth Buffer](https://i.sstatic.net/brV9I.png)](https://i.sstatic.net/brV9I.png)

What's going on there? Is that a technique to improve depth precision?

Thanks!

**Tags:** lighting, depth-map

> **Comments:**
> **username_1**: I've only seen something like this when someone has interpreted the bottom 8 bits of a 16- or 24-bit depth buffer as an image channel. How did you generate this image?  
> **username_0**: @username_1 With the buffer visualiser: https://docs.unrealengine.com/latest/INT/Engine/UI/LevelEditor/Viewports/ViewModes/#buffervisualization  
> **username_2**: It could be a visualisation aid, instead of showing the depth as 1 gradient you can scale it to fit inside 3 steeper gradients. This is especially helpful for objects near the camera which have less variation in terms of depth.  
> **username_0**: @username_2 yeah it could be, I mean, it actually repeats more than 3 times, it repeats indefinitely!  
> **username_3**: the upper 2 bytes would have a resolution of 256*256 = 65536. If the depth buffer is 32 bits then that increases to 16777216. That may seem indefinite at first glance.  

---

## 2 answers

### Answer by username_4 on 2017-09-14. Score: 1

This is just a visualisation. Type the command vis scenedepthz uv0 to see the actual depth buffer used. UE4 uses a "reversed" depth buffer for the scene.


---

### Answer by username_5 on 2017-09-13. Score: -1

While I have no idea how UnrealEngine handle depth I have thought of a technique which would result in that kind of depth output.

The idea is to better manage Z-fighting by rendering multiple (stacked) frustums with shorter distance between ner and far planes. Each step in the cascade would represent one of those frustums. Using near/far plane clipping, stencil masking and optional vf-culling you can easily render the cascade front-to-back, or each frustum to each own framebuffer and consolidate afterwards, with only minor hit in performance.

This should scale better than increasing depth buffer bit depth which has diminishing returns. Besides not all platforms support high bit depth. OpenGL ES require only 16 bits!

It is just a theory though :-)

> **Comments:**
> **username_0**: That could work. IMO it will require too much extra work and maybe the performance won't be that great! Reversed depth FTW :3  

---

