<p>Getting high quality shadows from Cascade Shadow maps with (relatively) low resolution shadow maps is a process. I recommend taking on different aspects one at a time.</p>
<p>Here are few generic suggestions...
Shadow transitions between cascade zones can be handled by allowing the cascades to overlap by a small amount then computing a lerp value for each zone. The zone near the camera goes from 1 to 0 inside the overlap region and the next zone goes from 0 to 1 inside the overlap region. Then tweaking the size of overlap to get the best visuals to performance.</p>
<p>Allow the number of cascades to vary depending on the region, and/or quality setting. Once you have the basic algorithm working, changing the number of cascades (usually between 3 and 6) can help and isn't to hard to add. This is especially helpful with large open world areas.</p>
<p>PCSS can be implemented reasonably easily with cascade maps, enabling hardware interpolation and hardware bias settings will help and can get you down to the minimum samples while still getting good performance. This is another place that a quality setting can be handy.</p>
<p>Computing a best fit for the cascade frustums can help considerably, but there are as many ways to do this as there are people writing cascade shadow maps.</p>
<p>Here is a link to a <a href="https://docs.microsoft.com/en-us/windows/win32/dxtecharts/common-techniques-to-improve-shadow-depth-maps" rel="nofollow noreferrer">Microsoft web</a> site that has some good tips on dealing with aliasing issues.</p>
<p>Also, I recommend asking specific question regarding specific issues with some of the techniques described above (or others that you find). It's hard to give a good answer to such a broad question.</p>

CC BY-SA 4.0
2021-07-07T05:10:04.843Z
My point light omnidirectional shadows looked way sharper at lower resolutions in comparison to the orthographic projection, so I was just wondering if this was how it was supposed to be or if I was doing something wrong. I was looking into shadow filtering methods and I think I'm going to go with variance shadow maps and linearly interpolate between depth values in the overlap regions. I usually use a gradient with PCF to mitigate shadow acne, but I'm not sure how to use that at the edges of the cascade where the view and orthographic matrices are different
Josh Lakin
CC BY-SA 4.0
2021-07-07T11:33:38.690Z
There are 6 1024 shadow maps for omnidirectional vs 1 shadow map for each cascade region, and that 1 map is covering a much larger area then any 1 of the omni maps. This puts the camera much farther away from the objects so it can "see" the entire area for the map. Play with the area covered by the cascades, usually small changes to the cascade sizes can result in large differences in the aliasing. (especially for a 16:9 aspect ratio).
pmw1234
CC BY-SA 4.0
2021-07-06T14:00:55.350Z
2021-07-06T14:00:55.350Z
pmw1234
<p>The blockiness of the shadows in your screenshot looks to me like the expected results from using the hardware bilinear PCF to sample the shadow map. Unfortunately this is just not a very good filter. It's necessary to use a wider filter to get smooth shadows. This could be as simple as doing multiple bilinear PCF samples at offset locations, and averaging the results. This will blur out the shadows a lot, but you could then apply a sharpening function to the result to obtain sharper shadows with smoother boundaries.</p>
<p>Shadow map filtering is a big topic and can get very complicated (just google &quot;shadow map filtering&quot; and you'll find plenty of reading material).</p>

CC BY-SA 4.0
2021-07-07T04:58:32.620Z
I implemented omnidirectional shadows before I programmed the shadow cascades, and the perspective shadows seemed way sharper at lower resolutions. I just wasn't expecting the orthographic projection to make shadows look this blocky.
Josh Lakin
CC BY-SA 4.0
2021-07-07T00:53:27.620Z
2021-07-07T00:53:27.620Z
Nathan Reed
<p>I've been trying to get my cascaded shadow maps looking right for a while. I managed to fix the shimmering and most of the quantization artifacts, but for some reason the shadows still look really blocky. I'm using a resolution of 1024x1024. Here are images of the bounding boxes used for the orthographic matrices, the camera frustum, and the resulting shadows:</p>
<p><a href="https://i.sstatic.net/e9845.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/e9845.jpg" alt="Bounding boxes for frustum" /></a></p>
<p><a href="https://i.sstatic.net/bpXAc.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/bpXAc.jpg" alt="Camera frustum" /></a></p>
<p><a href="https://i.sstatic.net/MJ3io.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/MJ3io.png" alt="Resulting shadows" /></a></p>
<p>This is a snippet of the code I'm using to generate the bounds for the orthographic matrix:</p>
<pre><code>       for (int i = 0; i &lt; numShadowCascades; i++) {
                //transform camera frustum split corners to world space
                tempShadowBounds[4 * i + 0] = cameraViewToWorld * glm::vec4(cascadedShadowBounds[4*i+0], 1.0f); //upper left
                tempShadowBounds[4 * i + 1] = cameraViewToWorld * glm::vec4(cascadedShadowBounds[4*i+1], 1.0f); //upper right
                tempShadowBounds[4 * i + 2] = cameraViewToWorld * glm::vec4(cascadedShadowBounds[4*i+2], 1.0f); //bottom left
                tempShadowBounds[4 * i + 3] = cameraViewToWorld * glm::vec4(cascadedShadowBounds[4*i+3], 1.0f); //bottom right
                tempShadowBounds[4 * i + 4] = cameraViewToWorld * glm::vec4(cascadedShadowBounds[4*i+4], 1.0f); //next upper left
                tempShadowBounds[4 * i + 5] = cameraViewToWorld * glm::vec4(cascadedShadowBounds[4*i+5], 1.0f); //next upper right
                tempShadowBounds[4 * i + 6] = cameraViewToWorld * glm::vec4(cascadedShadowBounds[4*i+6], 1.0f); //next bottom left
                tempShadowBounds[4 * i + 7] = cameraViewToWorld * glm::vec4(cascadedShadowBounds[4*i+7], 1.0f); //next bottom right
                glm::vec3 frustumCenter = glm::vec3(0.0f);
                for (int j = 4 * i; j &lt; ((4 * i) + 8); j++) {
                    frustumCenter += tempShadowBounds[j];
                }
                frustumCenter /= 8.0f;

                dirLightViews[i] = glm::lookAt(frustumCenter, frustumCenter - lightDir, glm::vec3(0.0f, 1.0f, 0.0f));
                float maxX = std::numeric_limits&lt;float&gt;::lowest(); float maxY = maxX; 
                float maxZ = maxX;
                float minX = std::numeric_limits&lt;float&gt;::max(); float minY = minX; 
                float minZ = minX;
                using std::max; using std::min;
                for (int j = 4 * i; j &lt; ((4 * i) + 8); j++) {
                    glm::vec3 temp = dirLightViews[i] * glm::vec4(tempShadowBounds[j], 1.0f);
                    maxX = max(maxX, temp.x);
                    minX = min(minX, temp.x);
                    maxY = max(maxY, temp.y);
                    minY = min(minY, temp.y);
                    maxZ = max(maxZ, temp.z);
                    minZ = min(minZ, temp.z);
                }

                glm::mat4 cascadedOrtho = glm::ortho(minX, maxX, minY, maxY, minZ, maxZ);
                cascadedShadowMatrices[i] = cascadedOrtho * dirLightViews[i];
       }
</code></pre>
<p>The code is somewhat rough right now, but that's the gist of how I'm generating the bounding boxes. Another big problem is that you can see the transition between the shadow maps as you move the camera, and I'm not sure how to smooth that transition.</p>
<p>The seams seem hard to eliminate. On a side note why don't people divide the world space into directional light chunks where each shadow map is assigned a section of world space, as opposed to cascaded shadow maps? Or am I missing something?</p>

<opengl><c++><shadow-mapping>
Reducing Cascaded Shadow Mapping Artifacts
Josh Lakin
# Reducing Cascaded Shadow Mapping Artifacts

(Asked by: username_0 on 2021-07-06)

I've been trying to get my cascaded shadow maps looking right for a while. I managed to fix the shimmering and most of the quantization artifacts, but for some reason the shadows still look really blocky. I'm using a resolution of 1024x1024. Here are images of the bounding boxes used for the orthographic matrices, the camera frustum, and the resulting shadows:

[![Bounding boxes for frustum](https://i.sstatic.net/e9845.jpg)](https://i.sstatic.net/e9845.jpg)

[![Camera frustum](https://i.sstatic.net/bpXAc.jpg)](https://i.sstatic.net/bpXAc.jpg)

[![Resulting shadows](https://i.sstatic.net/MJ3io.png)](https://i.sstatic.net/MJ3io.png)

This is a snippet of the code I'm using to generate the bounds for the orthographic matrix:

```
       for (int i = 0; i < numShadowCascades; i++) {
                //transform camera frustum split corners to world space
                tempShadowBounds[4 * i + 0] = cameraViewToWorld * glm::vec4(cascadedShadowBounds[4*i+0], 1.0f); //upper left
                tempShadowBounds[4 * i + 1] = cameraViewToWorld * glm::vec4(cascadedShadowBounds[4*i+1], 1.0f); //upper right
                tempShadowBounds[4 * i + 2] = cameraViewToWorld * glm::vec4(cascadedShadowBounds[4*i+2], 1.0f); //bottom left
                tempShadowBounds[4 * i + 3] = cameraViewToWorld * glm::vec4(cascadedShadowBounds[4*i+3], 1.0f); //bottom right
                tempShadowBounds[4 * i + 4] = cameraViewToWorld * glm::vec4(cascadedShadowBounds[4*i+4], 1.0f); //next upper left
                tempShadowBounds[4 * i + 5] = cameraViewToWorld * glm::vec4(cascadedShadowBounds[4*i+5], 1.0f); //next upper right
                tempShadowBounds[4 * i + 6] = cameraViewToWorld * glm::vec4(cascadedShadowBounds[4*i+6], 1.0f); //next bottom left
                tempShadowBounds[4 * i + 7] = cameraViewToWorld * glm::vec4(cascadedShadowBounds[4*i+7], 1.0f); //next bottom right
                glm::vec3 frustumCenter = glm::vec3(0.0f);
                for (int j = 4 * i; j < ((4 * i) + 8); j++) {
                    frustumCenter += tempShadowBounds[j];
                }
                frustumCenter /= 8.0f;

                dirLightViews[i] = glm::lookAt(frustumCenter, frustumCenter - lightDir, glm::vec3(0.0f, 1.0f, 0.0f));
                float maxX = std::numeric_limits<float>::lowest(); float maxY = maxX; 
                float maxZ = maxX;
                float minX = std::numeric_limits<float>::max(); float minY = minX; 
                float minZ = minX;
                using std::max; using std::min;
                for (int j = 4 * i; j < ((4 * i) + 8); j++) {
                    glm::vec3 temp = dirLightViews[i] * glm::vec4(tempShadowBounds[j], 1.0f);
                    maxX = max(maxX, temp.x);
                    minX = min(minX, temp.x);
                    maxY = max(maxY, temp.y);
                    minY = min(minY, temp.y);
                    maxZ = max(maxZ, temp.z);
                    minZ = min(minZ, temp.z);
                }

                glm::mat4 cascadedOrtho = glm::ortho(minX, maxX, minY, maxY, minZ, maxZ);
                cascadedShadowMatrices[i] = cascadedOrtho * dirLightViews[i];
       }

```

The code is somewhat rough right now, but that's the gist of how I'm generating the bounding boxes. Another big problem is that you can see the transition between the shadow maps as you move the camera, and I'm not sure how to smooth that transition.

The seams seem hard to eliminate. On a side note why don't people divide the world space into directional light chunks where each shadow map is assigned a section of world space, as opposed to cascaded shadow maps? Or am I missing something?

**Tags:** opengl, c++, shadow-mapping


---

## 2 answers

### Answer by username_1 on 2021-07-06. Score: 2 | Accepted answer

Getting high quality shadows from Cascade Shadow maps with (relatively) low resolution shadow maps is a process. I recommend taking on different aspects one at a time.

Here are few generic suggestions...
Shadow transitions between cascade zones can be handled by allowing the cascades to overlap by a small amount then computing a lerp value for each zone. The zone near the camera goes from 1 to 0 inside the overlap region and the next zone goes from 0 to 1 inside the overlap region. Then tweaking the size of overlap to get the best visuals to performance.

Allow the number of cascades to vary depending on the region, and/or quality setting. Once you have the basic algorithm working, changing the number of cascades (usually between 3 and 6) can help and isn't to hard to add. This is especially helpful with large open world areas.

PCSS can be implemented reasonably easily with cascade maps, enabling hardware interpolation and hardware bias settings will help and can get you down to the minimum samples while still getting good performance. This is another place that a quality setting can be handy.

Computing a best fit for the cascade frustums can help considerably, but there are as many ways to do this as there are people writing cascade shadow maps.

Here is a link to a [Microsoft web](https://docs.microsoft.com/en-us/windows/win32/dxtecharts/common-techniques-to-improve-shadow-depth-maps) site that has some good tips on dealing with aliasing issues.

Also, I recommend asking specific question regarding specific issues with some of the techniques described above (or others that you find). It's hard to give a good answer to such a broad question.

> **Comments:**
> **username_0**: My point light omnidirectional shadows looked way sharper at lower resolutions in comparison to the orthographic projection, so I was just wondering if this was how it was supposed to be or if I was doing something wrong. I was looking into shadow filtering methods and I think I'm going to go with variance shadow maps and linearly interpolate between depth values in the overlap regions. I usually use a gradient with PCF to mitigate shadow acne, but I'm not sure how to use that at the edges of the cascade where the view and orthographic matrices are different  
> **username_1**: There are 6 1024 shadow maps for omnidirectional vs 1 shadow map for each cascade region, and that 1 map is covering a much larger area then any 1 of the omni maps. This puts the camera much farther away from the objects so it can "see" the entire area for the map. Play with the area covered by the cascades, usually small changes to the cascade sizes can result in large differences in the aliasing. (especially for a 16:9 aspect ratio).  

---

### Answer by username_2 on 2021-07-07. Score: 0

The blockiness of the shadows in your screenshot looks to me like the expected results from using the hardware bilinear PCF to sample the shadow map. Unfortunately this is just not a very good filter. It's necessary to use a wider filter to get smooth shadows. This could be as simple as doing multiple bilinear PCF samples at offset locations, and averaging the results. This will blur out the shadows a lot, but you could then apply a sharpening function to the result to obtain sharper shadows with smoother boundaries.

Shadow map filtering is a big topic and can get very complicated (just google "shadow map filtering" and you'll find plenty of reading material).

> **Comments:**
> **username_0**: I implemented omnidirectional shadows before I programmed the shadow cascades, and the perspective shadows seemed way sharper at lower resolutions. I just wasn't expecting the orthographic projection to make shadows look this blocky.  

---

