<p>PCF does N shadow tests, where each test returns 1 (in light) or 0 (in shadow), and returns the average of the results. <code>sampler2DShadow</code> 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.</p>

CC BY-SA 3.0
2016-12-06T17:04:28.847Z
2016-12-06T22:51:40.787Z
2016-12-06T22:51:40.787Z
JarkkoL
<p>I am trying to make use of free hardware PCF sampling with <code>sampler2DShadow</code> and extend it to more samples.</p>

<p>So far I am sampling shadow map (<code>sampler2D</code>) 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:</p>

<pre><code>float shadowMapSize = 512.0;
float c = 5000.0;
float receiver = lightCoords.z;
float shadow = 0.0;
for(int i = 0; i &lt; 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);
</code></pre>

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

<pre><code>float shadowMapSize = 512.0;
float c = 5000.0;
float receiver = lightCoords.z;
float shadow = 0.0;
for(int i = 0; i &lt; 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);
</code></pre>

<p>But unfortunately it doesnt work as expected:</p>

<p><a href="https://i.sstatic.net/qjV7F.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/qjV7F.png" alt="enter image description here"></a></p>

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

<opengl><lighting><glsl><shadow>
Exponential shadow maps sampling with PCF for sampler2DShadow instead of sampler2D
mdkdy
# Exponential shadow maps sampling with PCF for sampler2DShadow instead of sampler2D

(Asked by: username_0 on 2016-12-05)

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](https://i.sstatic.net/qjV7F.png)](https://i.sstatic.net/qjV7F.png)

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.

**Tags:** opengl, lighting, glsl, shadow


---

## 1 answers

### Answer by username_1 on 2016-12-06. Score: 3 | Accepted answer

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.


---

