View Full Version : emulating nvidia's pcf for shadow maps
05-29-2007, 11:34 AM
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.
05-29-2007, 11:57 AM
(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.
05-29-2007, 03:00 PM
i know that i have to use the results of the comparisons :) how would i perform bilinear filtering in a fp? simply taking multiple samples and averaging them does not get rid of the blockiness.
05-29-2007, 03:09 PM
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.
05-29-2007, 03:28 PM
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 :)
05-31-2007, 08:51 AM
thanks for the links :) 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 (http://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?
05-31-2007, 09:00 AM
4 is enough, you will have to cross edges, and I don't really know how to handle corners...
05-31-2007, 01:17 PM
found an article in shaderX² that does exactly what i need - and it works :D thanks for your patience, though!
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.