Jump to content
  • Advertisement
Sign in to follow this  
zurekx

Make shadows smooth by bluring - problem?

This topic is 3862 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have written some code for generating shadows, but shadow volumes and shadow mapping. However, I want to blur the shadows to make them look smooth (and to eliminate some aliasing from the shadow mapping). A gaussian blur-filter seems nice, but I have one question. How can make sure that the bluring doesnt exeed the polygon-edges (i.e. that triangles that are not in shadow at all get's a little darker because they are next to shadow on the scren)? I thought that maybe I could use e normal-buffer and the depth-buffer or something like that. What is the best techique?

Share this post


Link to post
Share on other sites
Advertisement
Honestly you really don't want to blur in screen-space for the reasons that you mentioned. No matter what you do you'll run into problems, not to mention that what you want to be doing is anti-aliasing, not blurring. To that end, look up shadow map filtering techniques like percentage closer filtering (PCF), variance shadow maps (VSM), convolution shadow maps (CSM) and exponential shadow maps (ESM). For shadow volumes, you're unfortunately kind of stuck unless you want to super-sample in screen space.

Share this post


Link to post
Share on other sites
Thanks. Which one is to prefer? I dont really understand how they make shadow mapping look good in games and so on, I think it's so much tweaking and artifacts. But still it's the most used method right?

Share this post


Link to post
Share on other sites
Well I'm naturally a bit partial to variance shadow maps and exponential shadow maps ;) That said what you want to do to get good shadows is to combine a good filtering scheme (like VSM or ESM) together with a good frustum partitioning/warping scheme. I've had a lot of success with Parallel Split Shadow Maps (aka Cascading Shadow Maps) together with Variance Shadow Maps, but feel free to mix and match to suit your application.

Share this post


Link to post
Share on other sites
I think screen space blurs can look fine if done carefully. All soft shadow methods that are fast have some drawbacks, inclusing VSM. It just depends, do you rather buggy-looking VSM (i've never seen it not look buggy, sorry) or somewhat incorrect screen space blur..?

Screen space blurs can be dont nicely and are very simple and straight forward to implement. If you have access to the depth buffer in your final pass you can control edge bleeding a bit by not blurring at places with high depth discontinuities.

If you use a high enough resolution shadow maps with some kind of warping, just standard hardware PCF can almost look good enough...If you do a subtle screen space blur it can be all you need. Remember you cant use VSM with hardware shadow maps.

Share this post


Link to post
Share on other sites
Quote:
Original post by Matt Aufderheide
All soft shadow methods that are fast have some drawbacks, inclusing VSM. It just depends, do you rather buggy-looking VSM (i've never seen it not look buggy, sorry) or somewhat incorrect screen space blur..?

If you're referring to light bleeding, that's certainly a big problem for many scenes. In addition to the light bleeding reduction stuff in GPU Gems 3, however, we now have Exponential Shadow Maps (check out ShaderX6), Layered Variance Shadow Maps and Exponential Variance Shadow Maps (paper that covers these two to be online in a few days - published at GI 2008) that all address light bleeding. In fact with the recent explosion of work in the area I'm fairly confident in saying that an adaptive techniques based on the linear/probabilistic shadow map filtering approaches (VSM/CSM/ESM/EVSM/etc.) are the most promising direction moving forward.

Quote:
Original post by Matt Aufderheide
Screen space blurs can be dont nicely and are very simple and straight forward to implement. If you have access to the depth buffer in your final pass you can control edge bleeding a bit by not blurring at places with high depth discontinuities.

Sure but it's not just the halos that are a problem. You're also blurring in entirely the wrong dimensions. While this isn't necessarily crippling if you're using tiny blurs, you can't use it to get any significant edge softening. In fact I believe World in Conflict uses a similar approach and if you actually zoom in and check out how their shadows behave it's a mess. I mean no offense to the game (it looks quite beautiful in most ways), but the shadows do some really strange and ugly things.

Quote:
Original post by Matt Aufderheide
Remember you cant use VSM with hardware shadow maps.

Sure, but there's no such thing as "hardware shadow maps" anymore. The concept of "lookup with compare" is properly a shader instruction now, and may well be implemented using four lookups/compares. The underlying hardware isn't doing anything magic here, so don't get the impression that you "should be using hardware shadow maps" for some kind of mythical speed gain anymore.

Share this post


Link to post
Share on other sites
Myself, I use standard variance shadow maps. In fact, I had great success with them - no light bleeding, very attractive. I did a demo for Ogre, demonstrating "real-time soft self shadowing shadows" ([lol]) because Ogre had a bit of a crippled shadow demo in terms of shaders (though it did demonstrate stencil/projective shadows well): http://www.ogre3d.org/phpBB2/viewtopic.php?t=39809. It's open source, check it out if you wish.

Share this post


Link to post
Share on other sites
I would say you've not done yourself justice on a few of those screenshots, I would try creating a more light scene which is more open so you can truely see the quality of your shadowing. Its a slight criticism, I think you could demonstrate those a lot better, and lets be right about this, the shadowing looks fantastic!

Share this post


Link to post
Share on other sites
Quote:
Original post by AndyTX
Sure, but there's no such thing as "hardware shadow maps" anymore. The concept of "lookup with compare" is properly a shader instruction now, and may well be implemented using four lookups/compares. The underlying hardware isn't doing anything magic here, so don't get the impression that you "should be using hardware shadow maps" for some kind of mythical speed gain anymore.


This is not accurate in my experience. First, using hardware shadow maps allows you to render to a depth texture, rather than a floating point buffer. In DirectX 9 there is no other way to do it. Depth texture are significantly faster than floating point buffers.

Plus doing the 4 lookups and the filtering in one call is simply faster and easier. So the hardware IS doing something "magical". From the Nvidia GPU programming guide:"Because dedicated transistors exist for hardware shadow mapping, you will lose performance and quality if you try to emulate our shadow mapping algorithm with ps_2_0 of higher."

Maybe you can argue this is marketing hype, but the curcuits are there and they work. Crysis uses hardware shadow maps for eveything but the terrain shadows which opt for VSM as I said. The terain shadows are large and blurry. I imagine under Dx10 the situation may be different, but in Dx9 hardware shadow maps are a clear win. Also, you can do extended PCF by doing more than one hardware fetch which is still fast.

The point of screen-space blurring is not to get proper penumbras but to reduce aliasing. Just because it's physically incorrect doent mattter..shadow mapping is also physically incorrect--light is not a discrete array of photon-pixels. I appreciate your work on VSM, dont get me wrong, and that new stuff you mentioned sounds interesting.

Share this post


Link to post
Share on other sites
Quote:
Original post by Matt Aufderheide
This is not accurate in my experience. First, using hardware shadow maps allows you to render to a depth texture, rather than a floating point buffer.

You can use 32-bit float depth buffers to get all of the same advantages.

Quote:
Original post by Matt Aufderheide
Plus doing the 4 lookups and the filtering in one call is simply faster and easier. So the hardware IS doing something "magical".

Certainly bilinear lookups w/ compare are useful for PCF, but my point is that they don't need to be used with "shadow textures" anymore. They work with any one-component texture format. In fact, there are no special shadow texture types anymore since they don't really do anything "special" as I mentioned. All of the special functions are really just different ways to render and lookup into textures, which are properly generalized now.

Indeed your original point was that "you can't use hardware shadow maps with VSM" and my response is basically "yeah, but that's because you don't need to..." You can use standard bilinear filtering (and mipmapping, etc. etc.) with variance shadow maps which will be at least as fast or faster than SampleCmpLevelZero or similar. Once you consider that achieving similar shadow quality to VSM w/ hardware MSAA would require more than 4x the shadow resolution and at least 4x the PCF samples, VSM starts to look like the more efficient technique, albeit with trade-offs of its own.

Regarding hardware, I suspect NVIDIA still has hardware to do bilinear PCF as you note (so do use SampleCmpLevelZero for PCF, of course!), although AMD cards almost certainly implement it in terms of Fetch4, which is a more general concept.

Quote:
Original post by Matt Aufderheide
The point of screen-space blurring is not to get proper penumbras but to reduce aliasing. Just because it's physically incorrect doent mattter..shadow mapping is also physically incorrect--light is not a discrete array of photon-pixels.

Oh it has nothing to do with physical correctness... as you note none of this is physically correct. My point is actually that blurring - particularly in screen space - is not anti-aliasing and thus doesn't address the problem at all. Indeed if you have something like foliage casting high-frequency shadows on the road in front of you, you get a big aliased mess without filtering, and blurring actually just exacerbates that by giving you a big, flickery, halo-y mess. Check out Crysis actually - since they're not doing any "proper" filtering on their normal shadows, they degenerate badly in these cases. I can get a few shots if necessary but it's very easy to see yourself.

Quote:
Original post by Matt Aufderheide
I appreciate your work on VSM, dont get me wrong, and that new stuff you mentioned sounds interesting.

I'll try to get the new paper online today if possible. It covers Layered VSM and Exponential VSM, the latter being more interesting and practical moving forward I suspect, although the former is quite interesting for quality scaling of VSM.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!