Tuesday, June 30, 2009

Light Prepass Cascaded Shadow Mapping, continued

Ah... shadow map filtering, I didn't know before that there's a lot of them. (The screenshot were using a 512x512 resolution shadow map to easy compare the various filtering I implemented.) In my older screenshots, I'm using the 5x5 PCF (middle) ( short for Percentage Closer Filtering) which, of course better in smoothing out the shadows but the heaviest of all implementation I did. The 4 Tap PCF (left) is the fastest but the ugliest, not very nice if your shadow map resolution is low. I also tried Gaussian blur and random filters(not in screenshot). I also tried non PCFiltering like Variance Shadow mapping but considering I'm doing Cascaded Shadow Mapping, VSM has a bigger memory appetite considering it needs two channels to store depth and depth*depth. Which brings me to my own implementation.
Similar to what I've been doing in the past, and sometime good at it... I dub or name stuffs. I dubbed my implementation as 8 Tap O-PCF or Occasional-PCF. It may sound funny but thats only half of the point. My real point or reason why I name such is because how it self-optimized itself. Let me explain: (inhaled intensely)
The square first 4 tap of 8 will have enough information to proceed with the other 4 taps. By dissecting the texel into 3x3, the center is literally ignored due to the fact that the size and amount of the texels sampled are enough already. Sampling is basically 1/3 of the texel around the texel and should not go outside the texel. The wonderful thing about this is that I'm only sampling 8 times but only the first 4 if shadow test failed. If you closely examine its inner penumbra of the shadow, you'll notice the smoothness of the penumbra, almost to that point it appears to be using a higher shadow map resolution. Of course the outer penumbra will still be jagged but hey considering the 3 tones I added, and the edge are lightest, with a good Depth of Field, this will even look like 2048x2048 shadows. I like the flexibility of this filtering, much so that it can fake shadow bleeding already, beating the soft PCFs in terms of speed and control. So there you have it 8 Tap O-PCF... sounds like those nifty items in Monkey Island like Mug O'Grog or Spit O'Matic. Just say, 8-Tap-O'Pac-eF.... (windblowin tumble weed) ...nah that was corny. Ha!
I wouldn't say I'm finish with this topic... cause definitely, I'll be revisiting this when the renderer is formalized. Next stop, Dual Paraboloid Shadow Mapping for our indoor and outdoor shadowing daily needs.


bd said...

Hey - it (O-tap) looks very interesting. Do you have any more information on where to place the samples? I didn't quite understand your description and how it compares to regular PCF.


vidextreme said...

Hi bd,

I'll post a deeper explanation about this eventually.

But the overview explanation is...

Sample the by 1/3 of its size on 8 directions of a texel(North, South, East, West, NW, NE, SW, SE) but not decreasing its sample size.

The O-Tap there is do the diagonal direction first(NW, NE, SW,SE) (or you could use the axis direction N, S, E, W). You do this first for your common shadow test in normal PCF. If PASS, then you do the next 4. If you notice, I ignore the center sample, it is because the the total 8 taps have enough sampling to have the center.

Anyway, I hope to write a short paper on this. Maybe after all of my pending tasks are done.


vidextreme said...

O Btw, I dont shadow-test each samples. Only after the 4 prime samples (multiply by four when shadow testing). So this is even faster than 4 Tap PCF in terms of logic tests.

bd said...

Hmmm - I'm starting to get the pixture, but let me ask a couple more questions. Let's saw I have the following 5x5 texel shadow map:


And if I PCF sample exactly at [2,2] I would get only the center pixel's shadow value, but if I sampled at [2.5,2.5] I would get a quarter of [2,2], [3,2], [2,3], and [3,3].

So, if I understand, you are suggesting I first take four PCF samples, at [1.5, 1.5], [2.5, 1.5], [1.5, 1.5], [1.5, 2.5], and finally [2.5, 2.5]??

And then, based on if I find any shadow coverage, I then add four more samples?


bd said...

Argh - I meant the following as the first four samples:

[1.5, 1.5], [2.5, 1.5], [1.5, 2.5], and finally [2.5, 2.5] (I mistakenly listed [1.5, 1.5] twice!)

vidextreme said...


sorry for the late reply.

Yes, you are correct. The first four offsetted then the 2nd for diagonal to the first.

As you can see, it is self-Optimized. I don't know if you can, but if its possible post your results. I appreciate any feed back on this. Thanks!