# How to blur a custom shadow map?

**URL:** <https://forums.unrealengine.com/t/how-to-blur-a-custom-shadow-map/149181>\
**Category:** Rendering\
**Tags:** unreal-engine\
**Created:** [August 14, 2020, 3:01pm UTC](https://forums.unrealengine.com/t/how-to-blur-a-custom-shadow-map/149181 "2020-08-14T15:01:39Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ZkarmaKun](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/zkarmakun/32/1194545_2.png) [@ZkarmaKun](https://forums.unrealengine.com/u/ZkarmaKun)\
**Post date:** [August 14, 2020, 3:01pm UTC](https://forums.unrealengine.com/t/how-to-blur-a-custom-shadow-map/149181/1 "2020-08-14T15:01:39Z")

</div>

Hello guys

Here is another question, I created a custom shadow map using a scene capture component and a render target to capture depth, so far is working but I dunno how to make the shadow soft, right now the borders are pixelated.

 ![Shadows.PNG.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/3X/0/8/081ade3bbded1c427a97ee3b01031a1173a7fda4.jpeg)

I have been following this tutorial: [Tutorial 40: Shadow Mapping](http://www.rastertek.com/dx11tut40.html)

My Initial idea is create a small kernel, but I think is will be too heavy, do you guy have some insights or thoughts about how to approach this better?

Here is the simple graph for those interested:

 ![ShadowProjectionMaterial.PNG](https://d3kjluh73b9h9o.cloudfront.net/original/3X/c/e/ce78a28465c9bdfa1f70fa756378e9b91c83c7ae.png)]([Tutorial 40: Shadow Mapping](http://www.rastertek.com/dx11tut40.html))

---

<div class="post-metadata">

**Author:** ![Deathrey](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Deathrey](https://forums.unrealengine.com/u/Deathrey)\
**Post date:** [August 14, 2020, 4:10pm UTC](https://forums.unrealengine.com/t/how-to-blur-a-custom-shadow-map/149181/2 "2020-08-14T16:10:16Z")

</div>

You should be looking at Percentage Closer Filtering.

---

<div class="post-metadata">

**Author:** ![ZkarmaKun](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/zkarmakun/32/1194545_2.png) [@ZkarmaKun](https://forums.unrealengine.com/u/ZkarmaKun)\
**Post date:** [August 14, 2020, 5:25pm UTC](https://forums.unrealengine.com/t/how-to-blur-a-custom-shadow-map/149181/3 "2020-08-14T17:25:32Z")

</div>

@Deathrey yes, for now I found this article [https://learnopengl.com/Advanced-Lig…Shadow-Mapping](https://learnopengl.com/Advanced-Lighting/Shadows/Shadow-Mapping) and I did implemented their ugly solution 😛

 ![FilteredShadow.PNG.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/3X/b/1/b13e431350889bddab267536885a008f22e8b44c.jpeg)

It looks just a little bit better, but at the cost for 9 samples per pixel, I am not satisfied at all, I will keep looking for another PCF implementations.

The code I used is the same:

```auto

float shadow = 0.0f;
float2 TexelSize = 1.0 / TextureSize;
for(int x = -1; x <= 1; ++x)
{
    for(int y = -1; y <= 1; ++y)
    {
        float pcfDepth = Texture2DSampleLevel(DepthTexture, DepthTextureSampler, UV.xy + float2(x, y) * TexelSize, 0).r;
        shadow += CurrentDepth > pcfDepth ? 1.0 : 0.0;        
    }    
}
shadow /= 9.0;
return 1.0 - shadow;

```

---

<div class="post-metadata">

**Author:** ![Deathrey](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Deathrey](https://forums.unrealengine.com/u/Deathrey)\
**Post date:** [August 14, 2020, 7:10pm UTC](https://forums.unrealengine.com/t/how-to-blur-a-custom-shadow-map/149181/4 "2020-08-14T19:10:23Z")

</div>

9 taps is pretty low. You might want rotated disk sampling with 20ish-30ish taps.

---

<div class="post-metadata">

**Author:** ![ZkarmaKun](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/zkarmakun/32/1194545_2.png) [@ZkarmaKun](https://forums.unrealengine.com/u/ZkarmaKun)\
**Post date:** [August 17, 2020, 1:06pm UTC](https://forums.unrealengine.com/t/how-to-blur-a-custom-shadow-map/149181/5 "2020-08-17T13:06:38Z")

</div>

@Deathrey hey thanks for the hint, I found something called poisson disk, is it what you meant? it works okish using the 16 taps, here I cranked up to 48 hahaha, amazing smooth result

 ![Shadows2.PNG.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/3X/8/4/84212e6ba30a9fb73932004158a8501e96d6530c.jpeg)

hey @Bits360 I know they do, but I want to learn, authoring shadows will allow me to tint them?, creating outlines in shadows for stylized effects? using channels in the Gbuffer to create super crazy complex effects otherwise not possible? like patters inside a shadow without using forward rendering and per material instance? creating a screen pass so I do not have to modify the engine source? or in my case my final goal is able to create a new type of light for toon shader effects

---

<div class="post-metadata">

**Author:** ![C64debug](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@C64debug](https://forums.unrealengine.com/u/C64debug)\
**Post date:** [December 22, 2020, 10:30pm UTC](https://forums.unrealengine.com/t/how-to-blur-a-custom-shadow-map/149181/6 "2020-12-22T22:30:43Z")

</div>

> [@ZkarmaKun](#):
>
> Here is the simple graph for those interested:

I’d be really interested in checking out your implementation, is this a project you could share? I’m experimenting with a setup with fake dynamic lights.

Thank you for considering it 🙂  
r.

---

<div class="post-metadata">

**Author:** ![MostHost\_LA](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mosthost_la/32/907035_2.png) [@MostHost\_LA](https://forums.unrealengine.com/u/MostHost_LA)\
**Post date:** [December 22, 2020, 10:37pm UTC](https://forums.unrealengine.com/t/how-to-blur-a-custom-shadow-map/149181/7 "2020-12-22T22:37:33Z")

</div>

Out of curiosity.  
how do you plan of getting lights to actually function if you add one to the scene?

im assuming you can make loops in hlsl to get lights and their parameters and affect the object multiple times by adding shadow layers.  
for a 1 time render i can see that being a good thing.

for a live game with a dynamic aspect, arent you going to hit the same limits as the engine anyway?

Ei: limited number of influences, limited color, limited per tris performance etc.

---

<div class="post-metadata">

**Author:** ![ZkarmaKun](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/zkarmakun/32/1194545_2.png) [@ZkarmaKun](https://forums.unrealengine.com/u/ZkarmaKun)\
**Post date:** [December 28, 2020, 8:00pm UTC](https://forums.unrealengine.com/t/how-to-blur-a-custom-shadow-map/149181/8 "2020-12-28T20:00:15Z")

</div>

> [@C64debug](#):
>
> I’d be really interested in checking out your implementation, is this a project you could share? I’m experimenting with a setup with fake dynamic lights.
> 
> Thank you for considering it 🙂  
> r.

I cannot share my code but it is actually not hard at all, I followed this tut: [http://www.rastertek.com/dx11tut40.html](http://www.rastertek.com/dx11tut40.html)

> [@MostHost\_LA](#):
>
> Out of curiosity.  
> how do you plan of getting lights to actually function if you add one to the scene?
> 
> im assuming you can make loops in hlsl to get lights and their parameters and affect the object multiple times by adding shadow layers.  
> for a 1 time render i can see that being a good thing.
> 
> for a live game with a dynamic aspect, arent you going to hit the same limits as the engine anyway?
> 
> Ei: limited number of influences, limited color, limited per tris performance etc.

Mmm I created a manager class then I am generating an instance at the StartupModule of my plugin, this instance class track every editor delegate, like when you create an actor, change level, remove actor, etc, this manager contains a list of every custom light actor and then call a render pass to each one. the screen passes are happening before the atmosphere right after the UE’s light gets calculated, they are generally cheap, like 0.04 ms at full HD, the problem is actually the shadow map, UE’s scene capture component is calculating the whole scene with “aaalll” inside even if you only want the scene depth, It is a known problem but epic seams to be ok with it, since is there since forever. That is super heavy, not worth to do in a game, I haven’t check the problem, but I will fix it at some point

---

<div class="post-metadata">

**Author:** ![KingKrouch](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/kingkrouch/32/936134_2.png) [@KingKrouch](https://forums.unrealengine.com/u/KingKrouch)\
**Post date:** [November 12, 2024, 3:30am UTC](https://forums.unrealengine.com/t/how-to-blur-a-custom-shadow-map/149181/9 "2024-11-12T03:30:56Z")

</div>

> [@ZkarmaKun](#):
>
> I cannot share my code but it is actually not hard at all, I followed this tut: [http://www.rastertek.com/dx11tut40.html](http://www.rastertek.com/dx11tut40.html)

Sorry for the late reply, but I’m taking a look at this article (Through [The Wayback Machine](https://web.archive.org/web/20240116175020/https://www.rastertek.com/dx11tut40.html)) since I’ve been working on trying to recreate a shadow mapping system using render targets on unlit materials, and I’m wondering what the math on the directional lights look like.

At least when I try and use an orthographic camera, my issue is trying to find the right positioning to cover the whole level (or at least where the camera is currently located). Simply trying to put the light in the center and then putting the render target’s output into the material causes the shaded part to not appear in the correct place.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/8/e/c8ebba42ca4e131d034dfc6c8fb9683db635744f.jpeg)

I just don’t see much good Unreal specific documentation on how to approach this issue.
