Sign in to follow this  
gboxentertainment

Jittered Soft Shadows

Recommended Posts

I've been able to implement a fast approximated soft shadows algorithm into my engine by using a noise texture for jittered sampling and then a screen-space gaussian blur rendered into a quad. I then render this into my forward renderer by sampling using gl_FragCoord.xy/vec2(screenwidth,screenheight):

 

[attachment=17707:giboxshadows0.jpg]

 

Looks plausible at first, but there are some artifacts which occur - such as light bleeding at intersecting edges:

 

[attachment=17706:giboxshadows1.jpg]

 

There's also the light bleeding at the edges caused by the gaussian blurring of the screen-space shadow texture:

 

[attachment=17705:giboxshadows2.jpg]

 

I have tried addressing the second issue by using edge detection to prevent gaussian blurring of the edges, which had very little effect.

 

The only idea I can think of for resolving the first issue is to use ambient occlusion. I wonder if there is a faster alternative?

 

Is there a way of rendering a shadowmap that fades after a certain distance away from the occluder? Maybe I can use this to hide the artifacts?

Share this post


Link to post
Share on other sites
Regarding the first issue, do you know what the cause is? Is it taking samples that are 'inside' some solid geo?
When you render you depth maps, do you draw back or front faces.

Regarding the second issue, this should definitely be fixable. "Bilateral blurring" is very common for smoothing out noisy shadow data. IIRC I've done this in the past by measuring the difference in screen depth between the central sample and the each blur sample, then weighting the samples by 1/depth_diff.
How do you implement the 'edge detection'?

Share this post


Link to post
Share on other sites

Thanks for the reply.

Actually, I managed to solve the second problem by using a laplacian filter to get the edges in screen-space (based on a different value assigned to each object in model space):

 

[attachment=17708:giboxshadows3-1.jpg][attachment=17709:giboxshadows3-2.jpg]

 

Then I apply a gaussian blur in screen-space to only the values in the edge texture that are zero, so edges of objects do not get blurred:

 

[attachment=17710:giboxshadows3-3.jpg][attachment=17711:giboxshadows3-4.jpg]

 

However, I've still got the first problem, which can't seemed to be resolved with a simple edge method.

 

 

Regarding the first issue, do you know what the cause is? Is it taking samples that are 'inside' some solid geo?
When you render you depth maps, do you draw back or front faces.

 

 

I cull the front faces - not doing this resolves the leaking problem but then leads to overshadowing in the wrong areas:

 

[attachment=17712:giboxshadows4.jpg]

 

The cause must be something to do with the jittering, but im not sure why it causes light leaking only when objects intersect.

Share this post


Link to post
Share on other sites

Okay, so I've figured out that the light leaking when objects intersect is because when I cull the front faces when rendering the depth map, the intersecting face no longer becomes visible when it intersects - thus leading to that part not being occluded.

 

 

If I don't cull the front faces, shadow acne occurs. For a non-jittered shadowmap, adding a depth bias eliminates it, but it doesn't work well for a jittered shadow.

Edited by gboxentertainment

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this