<p>There’s an interesting technique that’s been used in demoscene and Shadertoy projects for a while, and an analogue of which recently made it into Unreal Engine 4: using <a href="https://en.wikipedia.org/wiki/Signed_distance_function" rel="noreferrer">signed-distance fields</a> and raymarching to produce high-quality soft shadows with accurate penumbras.</p>

<p><img src="https://i.sstatic.net/M3eET.jpg" alt="example distance-field shadows in Unreal Engine 4"></p>

<p>There’s a good writeup of the idea, with some visual examples, by Íñigo Quílez <a href="http://www.iquilezles.org/www/articles/rmshadows/rmshadows.htm" rel="noreferrer">here</a>—I’m not sure whether he invented the technique or was just one of the first to write about it:</p>

<blockquote>
  <p>The trick is to think what happens when a shadow ray doesn't hit any object, but was just pretty close to do so. Then, perhaps, you want to put that point you are shading under penumbra. Probably, the closest your point was to hit an object, the darker you want to make it. Also, the closest this happened from the point you are shading, the darker too. Well, it happens that as we raymarched our shadow ray, both these distances were available to us! … So, we can simply compute a penumbra factor for every step point in our marching process and take the darkest of all penumbras.</p>
</blockquote>

<p>The documentation on the corresponding Unreal feature is <a href="https://docs.unrealengine.com/latest/INT/Engine/Rendering/LightingAndShadows/RayTracedDistanceFieldShadowing/" rel="noreferrer">here</a>; their description of the technique is a little vaguer, but still helpful.</p>

<blockquote>
  <p>To calculate shadowing, a ray is traced from the point being shaded through the scene's Signed Distance Fields (SDF) toward each light. The closest distance to an occluding object is used to approximate a cone trace for about the same cost as the ray trace. It allows for high-quality area shadowing from spherical light source shapes.</p>
</blockquote>

<p>The main advantage of this approach is its high visual quality—most other techniques don’t handle varying penumbras well, and it doesn’t suffer as much from the aliasing problems of shadow maps. The main disadvantage is needing a distance-field representation of your scene geometry to trace rays through; unless you built it that way in the first place (there’s a <a href="https://www.youtube.com/watch?v=u9KNtnCZDMI" rel="noreferrer">fascinating talk</a> about how the team behind “Dreams” did exactly that), you’ll need a way to construct the SDFs out of your mesh geometry, which is an expensive and sometimes error-prone operation.</p>

<p>UE4 handles the SDF generation by building them offline beforehand and then stamping them into a volume around the camera at runtime (more information on that <a href="https://docs.unrealengine.com/latest/INT/Engine/Rendering/LightingAndShadows/MeshDistanceFields/index.html" rel="noreferrer">here</a>), but it’s not a cheap process so UE’s approach is only viable on high-end hardware for now. That said, if you <em>do</em> already have your scene geometry in SDF form, it’s quite easy to implement—see <a href="https://www.shadertoy.com/view/MsfGz8" rel="noreferrer">this Shadertoy</a> for an example.</p>

CC BY-SA 3.0
2018-02-07T21:35:18.593Z
This is very interesting indeed, but it seems like it would suffer a lot for varying geometry scenes
Makogan
CC BY-SA 3.0
2018-02-07T21:39:34.217Z
It depends—as long as the transformations you make on individual objects don’t involve deformation (i.e. moving a thing around as opposed to bending it), you can keep using the original volume texture for each object and just apply an appropriate inverse transformation when you’re sampling it. But yes, this approach isn’t as helpful for deformable geometry like animated characters.
Noah Witherspoon
CC BY-SA 3.0
2018-02-07T21:47:34.503Z
That's not the only thing I am thinking of, imagine objects appearing and disapearing from your scene (projectiles for example), this seems like it would have a problematic scaling time for something like that
Makogan
CC BY-SA 3.0
2018-02-08T07:23:51.670Z
You could replace the SDF with a cube map. Nvidia's GPU Gems has a chapter about this. https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch17.html This would result in a lower quality but it is easy to generate and a lot cheaper than SDF to generate, especially when things are animated.
bram0101
CC BY-SA 3.0
2018-02-07T21:03:26.543Z
2018-02-07T21:03:26.543Z
Noah Witherspoon
<p>The three most popular shadowing techniques for real time applications are:</p>

<p><strong>Shadow maps</strong></p>

<p>Advantages:</p>

<ul>
<li>Fast</li>
<li>"Simple"</li>
</ul>

<p>Disadvantages:</p>

<ul>
<li>Numerical limitations lead to artifacts and jaggy shadows </li>
<li>You only get the information of the first object hit by the light, not the last (important for more photorealistic effects)</li>
</ul>

<p><strong>Volume shadows</strong></p>

<p>Advantages:</p>

<ul>
<li><p>Almost no numerical instability</p></li>
<li><p>Hardware built-in support through stenciling</p></li>
</ul>

<p>Disadvantages:</p>

<ul>
<li><p>Slower than shadow maps</p></li>
<li><p>Finding the last object that the light hits isn't easy</p></li>
</ul>

<p><strong>Volumetric rendering</strong></p>

<p>Advantages:</p>

<ul>
<li>Analytic precision </li>
<li>Allows for great photorealistic shadows</li>
<li>Finding the last object hit by the light is trivial</li>
</ul>

<p>Disadvantages:</p>

<ul>
<li>SLOW, VERY SLOW</li>
<li>Has an awful asymptotic running time for ray intersection calculations (linear in the number of primitives without hashing)</li>
</ul>

<p>Are there any new experimental shadowing techniques that can improve on the advantages of any of these while eliminating some of the disadvantages?</p>

CC BY-SA 3.0
2018-02-07T00:45:03.020Z
The answer to this is a large list of things, but SSAO algorithms fall into this group. PCF shadow sampling as well (making the sampled shadow maps look nicer).  Purely ray based shadows can give nice soft edges if you take enough samples per pixel.  Another technique is to render a shadow map from a random spot on the light source every frame and let something like temporal anti aliasing integrate the correct result over time.
Alan Wolfe
CC BY-SA 3.0
2018-02-08T16:01:45.160Z
Some minor comments: *Shadow maps*: The main disadvantage is not so much numerical limitations but sampling rate. It's hard to get this above the required Nyquist rate for the final image (without excessively sampling other areas), leading to frequent aliasing artefacts.
*Shadow Volumes*: I don't understand the "finding the last object" problem.  One problem that sometimes crops up is keeping the volume closed when clipping against the front clip plane, but there are several ways to avoid this problem.
Simon F
<lighting><shadow><volumetric>
Experimental real-time shadowing techniques?
Makogan
# Experimental real-time shadowing techniques?

(Asked by: username_0 on 2018-02-06)

The three most popular shadowing techniques for real time applications are:

**Shadow maps**

Advantages:

* Fast
* "Simple"

Disadvantages:

* Numerical limitations lead to artifacts and jaggy shadows
* You only get the information of the first object hit by the light, not the last (important for more photorealistic effects)

**Volume shadows**

Advantages:

* Almost no numerical instability
* Hardware built-in support through stenciling

Disadvantages:

* Slower than shadow maps
* Finding the last object that the light hits isn't easy

**Volumetric rendering**

Advantages:

* Analytic precision
* Allows for great photorealistic shadows
* Finding the last object hit by the light is trivial

Disadvantages:

* SLOW, VERY SLOW
* Has an awful asymptotic running time for ray intersection calculations (linear in the number of primitives without hashing)

Are there any new experimental shadowing techniques that can improve on the advantages of any of these while eliminating some of the disadvantages?

**Tags:** lighting, shadow, volumetric

> **Comments:**
> **username_1**: The answer to this is a large list of things, but SSAO algorithms fall into this group. PCF shadow sampling as well (making the sampled shadow maps look nicer).  Purely ray based shadows can give nice soft edges if you take enough samples per pixel.  Another technique is to render a shadow map from a random spot on the light source every frame and let something like temporal anti aliasing integrate the correct result over time.  
> **username_2**: Some minor comments: *Shadow maps*: The main disadvantage is not so much numerical limitations but sampling rate. It's hard to get this above the required Nyquist rate for the final image (without excessively sampling other areas), leading to frequent aliasing artefacts. *Shadow Volumes*: I don't understand the "finding the last object" problem.  One problem that sometimes crops up is keeping the volume closed when clipping against the front clip plane, but there are several ways to avoid this problem.  

---

## 1 answers

### Answer by username_3 on 2018-02-07. Score: 7 | Accepted answer

There’s an interesting technique that’s been used in demoscene and Shadertoy projects for a while, and an analogue of which recently made it into Unreal Engine 4: using [signed-distance fields](https://en.wikipedia.org/wiki/Signed_distance_function) and raymarching to produce high-quality soft shadows with accurate penumbras.

![example distance-field shadows in Unreal Engine 4](https://i.sstatic.net/M3eET.jpg)

There’s a good writeup of the idea, with some visual examples, by Íñigo Quílez [here](http://www.iquilezles.org/www/articles/rmshadows/rmshadows.htm)—I’m not sure whether he invented the technique or was just one of the first to write about it:

> The trick is to think what happens when a shadow ray doesn't hit any object, but was just pretty close to do so. Then, perhaps, you want to put that point you are shading under penumbra. Probably, the closest your point was to hit an object, the darker you want to make it. Also, the closest this happened from the point you are shading, the darker too. Well, it happens that as we raymarched our shadow ray, both these distances were available to us! … So, we can simply compute a penumbra factor for every step point in our marching process and take the darkest of all penumbras.

The documentation on the corresponding Unreal feature is [here](https://docs.unrealengine.com/latest/INT/Engine/Rendering/LightingAndShadows/RayTracedDistanceFieldShadowing/); their description of the technique is a little vaguer, but still helpful.

> To calculate shadowing, a ray is traced from the point being shaded through the scene's Signed Distance Fields (SDF) toward each light. The closest distance to an occluding object is used to approximate a cone trace for about the same cost as the ray trace. It allows for high-quality area shadowing from spherical light source shapes.

The main advantage of this approach is its high visual quality—most other techniques don’t handle varying penumbras well, and it doesn’t suffer as much from the aliasing problems of shadow maps. The main disadvantage is needing a distance-field representation of your scene geometry to trace rays through; unless you built it that way in the first place (there’s a [fascinating talk](https://www.youtube.com/watch?v=u9KNtnCZDMI) about how the team behind “Dreams” did exactly that), you’ll need a way to construct the SDFs out of your mesh geometry, which is an expensive and sometimes error-prone operation.

UE4 handles the SDF generation by building them offline beforehand and then stamping them into a volume around the camera at runtime (more information on that [here](https://docs.unrealengine.com/latest/INT/Engine/Rendering/LightingAndShadows/MeshDistanceFields/index.html)), but it’s not a cheap process so UE’s approach is only viable on high-end hardware for now. That said, if you *do* already have your scene geometry in SDF form, it’s quite easy to implement—see [this Shadertoy](https://www.shadertoy.com/view/MsfGz8) for an example.

> **Comments:**
> **username_0**: This is very interesting indeed, but it seems like it would suffer a lot for varying geometry scenes  
> **username_3**: It depends—as long as the transformations you make on individual objects don’t involve deformation (i.e. moving a thing around as opposed to bending it), you can keep using the original volume texture for each object and just apply an appropriate inverse transformation when you’re sampling it. But yes, this approach isn’t as helpful for deformable geometry like animated characters.  
> **username_0**: That's not the only thing I am thinking of, imagine objects appearing and disapearing from your scene (projectiles for example), this seems like it would have a problematic scaling time for something like that  
> **username_4**: You could replace the SDF with a cube map. Nvidia's GPU Gems has a chapter about this. https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch17.html This would result in a lower quality but it is easy to generate and a lot cheaper than SDF to generate, especially when things are animated.  

---

