emulating nvidia's pcf for shadow maps

is there way to emulate nvidia’s bilinear filtering/2x2 pcf for shadow maps - or first of all, what is it actually? it’s often referenced as 2x2 hardware pcf, but actually it’s plain texture filtering, isn’t it?

i’d like to do this for cases in which i cannot use automatic depth comparison via sampler2DShadow ( cube shadow mapping) or when no filtering is performed (ati). shadows otherwise just don’t look good, using multiple samples or not.


(warning, heavy handwaving ahead)

Bilinear filtering for shadow maps must be done after the compare.

In fragment shader, compute the boolean result of comparison of the current depth with each of the 4 nearest texels from shadow map.
Imagine these 4 boolean results are a black&white texture. Now you can do your bilinear filtering.

EDIT: For even smoother shadows, instead of mere 4 samples, do the same with n samples. As if the filter was wider.

i know that i have to use the results of the comparisons :slight_smile: how would i perform bilinear filtering in a fp? simply taking multiple samples and averaging them does not get rid of the blockiness.

This is basic computer graphics stuff.
You need to do a weighted average : the nearer a sample, the bigger the weight.

You will have to adapt it to GLSL (normalised texcoords), but it should not be hard.

Here is the original paper written in 1987 by Reeves (second page, there is a nice diagram) :

EDIT: ok, for the sake of having a proper filename :slight_smile:

thanks for the links :slight_smile: i got it working using skoder’s solution here: www.opengl.org/discussion_boards/ubb/ultimatebb.php?ubb=get_topic;f=3;t=015025#000001

however, i wonder how i can determine if hardware filtering is supported on a machine. i could simply check if it’s an nv or ati card, but that’s probably not sufficient.
plus, i’d like to perform the filtering for cube shadow maps as well. i’m not sure what samples i have teo fetch and how many - only 6? 9? or can i even get away with 4 just like with the 2d texture?

4 is enough, you will have to cross edges, and I don’t really know how to handle corners…

found an article in shaderX² that does exactly what i need - and it works :smiley: thanks for your patience, though!