4
$\begingroup$

I am trying to make use of free hardware PCF sampling with sampler2DShadow and extend it to more samples.

So far I am sampling shadow map (sampler2D) in ESM way and extending this to PCF and it works. So I have no acne (thanks to ESM) and soft result, but I need a lot of PCF samples:

float shadowMapSize = 512.0;
float c = 5000.0;
float receiver = lightCoords.z;
float shadow = 0.0;
for(int i = 0; i < SAMPLE_NUM; ++i)
{
    vec2 off = (POISSON_SAMPLES[i])/shadowMapSize;
    float occluder = texture(shadowmap, lightCoords.xy+off).r;
    shadow += exp(c*(occluder-receiver));
}
shadow /= SAMPLE_NUM;

shadow = clamp(shadow, 0.0, 1.0);

But I wanted to use sampler2DShadow and get 4 PCF tabs for free and extend this to 16 taps for almost free with only 4 poisson samples like that:

float shadowMapSize = 512.0;
float c = 5000.0;
float receiver = lightCoords.z;
float shadow = 0.0;
for(int i = 0; i < SAMPLE_NUM; ++i)
{
    vec2 off = (POISSON_SAMPLES[i])/shadowMapSize;
    float occluder = texture(shadowmap, vec3(lightCoords.xy+off, receiver)).r;
    shadow += exp(c*(occluder-receiver));
}
shadow /= SAMPLE_NUM;
shadow = clamp(shadow, 0.0, 1.0);

But unfortunately it doesnt work as expected:

enter image description here

Is there a way to make it work (in ESM way, not traditional due to acne) or due to sampler2DShadow specification it is rather impossible? In traditional way it is possible.

$\endgroup$
3
$\begingroup$

PCF does N shadow tests, where each test returns 1 (in light) or 0 (in shadow), and returns the average of the results. sampler2DShadow is a special sampler where PCF is applied to the nearest texels to a sample, based on the depth coordinate provided. So you can't use it with ESM.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.