How to blur a custom shadow map?

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.

I have been following this tutorial: Tutorial 40: Shadow Mapping

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:

](Tutorial 40: Shadow Mapping)

1 Like

You should be looking at Percentage Closer Filtering.

@Deathrey yes, for now I found this article https://learnopengl.com/Advanced-Lig…Shadow-Mapping and I did implemented their ugly solution :stuck_out_tongue:

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:



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;


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

Why would you ever want a custom shadow map? Built-in works many times faster and has everything done already.

@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

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

In that case it makes complete sense.

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 :slight_smile:
r.

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.

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

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

Sorry for the late reply, but I’m taking a look at this article (Through The Wayback Machine) 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.

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