Soft Shadows

Started by
8 comments, last by Unreal 20 years, 8 months ago
Hello guys! Its time to "put" shadows in my 3dengine. I find stencil shadows better than shadow maps. What you prefer? How can I implement soft shadows? any idea? I use ARB_fragment_program thank you
Advertisement
Well, stencil shadows are good for scenes that don''t need alpha masked objects and have point lights (shadow maps are nasty for point lights). So, indoor Doom III style scenes.

Shadow maps are often better for outdoor scenes where you have a primary light (sun) and alpha masked objects (eg tree leaves / bushes etc), as the alpha shape comes out in the map.

So, choose depending on your scene.

percentage-closest filtered shadow depth maps give you soft(ish) edged shadows, and standard stencil shadows give you perfectly hard shadows.

You can blur the result of the stencil shadow algorithm, and select the amount of blur based on pixel depth, but this is only really practical for high-end cards (Radeon 9700 etc).

Here are some screenshots of the blurred stencil shadows algorithm:

http://www.mhalpin.34sp.com/images/Image1.jpg
http://www.mhalpin.34sp.com/images/Image2.jpg
http://www.mhalpin.34sp.com/images/glareHiRes1.jpg
http://www.mhalpin.34sp.com/images/glareHiRes2.jpg

HTH

Matt Halpin
there were documents introduced in siggraph 2003 about softening the shadows using the umbra and penumbra.but they require more geometry analydsis which cause a load on the CPU.also it uses more than 200 instructions pixel shader (reduced to 69 instructions after optimazation) which is somewhat a slow technique to use in a game.you can search in google for siggraph2003 papers .I found it that way.
quote:Original post by Matt Halpin

You can blur the result of the stencil shadow algorithm, and select the amount of blur based on pixel depth, but this is only really practical for high-end cards (Radeon 9700 etc).

Matt Halpin


How you do that?using accumulation buffer or something else?

quote:Original post by Unreal
quote:Original post by Matt Halpin

You can blur the result of the stencil shadow algorithm, and select the amount of blur based on pixel depth, but this is only really practical for high-end cards (Radeon 9700 etc).

Matt Halpin


How you do that?using accumulation buffer or something else?



nah, you don''t need an accumulation buffer:

Firstly, create a render target that has 4 different blur levels of the shadow mask in each channel (ie, no blur in alpha, 1 blur pass in red, etc) - use colorwriteenable to do that.

Then render the scene with a texture interpolator interpolating the depth. Feed this depth value into a 1d texture. The 1d texture has a,r,g,b weights given the depth. ie, at u==0, a,r,g,b = 0,0,0,1. at u==.333, a,r,g,b = 0,0,1,0. at u==1, a,r,g,b = 1,0,0,0. etc. ie, 3 linear interpolations each with a range of .3333 in u.

Now, render a quad that does the 4d dot-product between the blurred shadow render-target and the result of the 1d texture lookup. Basically this interpolates between the 4 amounts of blur. btw, building the weights based on depth can be done in a few arithmetic instructions instead of a 1d texture lookup but it probably doesn''t make a huge difference.

btw, this will work on lower shader versions. If you''re going for ps.2.0 or equivalent, then you can directly use the interpolated depth in the blur pass to push out the blur samples. Similar to the ps.2.0 dof shaders.

HTH,

Matt Halpin
Matt: Nice screenies. What depth value do you use for the blur lookup? Is it the camera-space depth, or depth w.r.t. the lightsource? Or something else?

Whichever it is, the results are impressive.
Just uploaded new pics of projected shadows using cubemaps and ambient lighting, page 17. Proj. shadows aren''t in the editor yet. One can do all kinds of neat things with them. This guy has couple of shadowing algos and demos http://users.ox.ac.uk/~univ1234/index.htm. I also like depth buffers for outdoor scenes but having them look good is complicated from what I understand.

Forged3D world editor
quote:Original post by treething
Matt: Nice screenies. What depth value do you use for the blur lookup? Is it the camera-space depth, or depth w.r.t. the lightsource? Or something else?

Whichever it is, the results are impressive.




It''s camera-space depth. Basically it''s to simulate perspective on the shadow boundary. A hard boundary in the distance becomes a soft boundary close up, but the stencil shadows don''t give you that, so you need to do it yourself.

HTH

Matt Halpin
but shadows shouldnt be softer near the camera, the softness has nothing to do with camera position, but to the distance fom the occluder, it might be possibile to alter your technique to make it take the depth from another texture, which stores the depth from the occluder. maybe something like that:

render the scene from the light position and store the depth in a texture, and then project it on the scene and take the depth from there. this will give distance from light though.
quote:Original post by pickups
but shadows shouldnt be softer near the camera, the softness has nothing to do with camera position, but to the distance fom the occluder, it might be possibile to alter your technique to make it take the depth from another texture, which stores the depth from the occluder. maybe something like that:

render the scene from the light position and store the depth in a texture, and then project it on the scene and take the depth from there. this will give distance from light though.


yeah sure, shadows shouldn''t get softer in *world* space wrt camera distance, but that''s not what the blurring deals with. The blurring deals with simulating the perspective divide.

What we end up with after the standard stencil algorithm is a on/off shadow mask. ie, the boundary between in and out of shadow is 1 pixel thick in *screen* space. But, if the width of a boundary in *screen* space is equal for all depths from the camera, then that means it''s *world* space thickness must be greater for pixels in the distance (for the perspective transform to have achieved equal widths in *screen* space). This is obviously incorrect, as you state - the boundary width should be equal in *world* space.

Hence the need to blur the discrete shadow mask in order to simulate the effect of the perspective transform.

I hope that''s more clear. Shadow softness should obviously also depend on distance from light to occluder and distance from occluder to receiver etc, but it''s more tricky than just rendering a depth map with the light. Firstly that means you need to solve the same mapping problems as you have to for standard shadow maps, and receiver geometry outside of shadows are still affected by near-by shadows (umbra-penumbra regions).

HTH

Matt Halpin

This topic is closed to new replies.

Advertisement