Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use sampler2DShadow when accessing a single shadow map. I create PCF in this way:

result += textureProjOffset(ShadowSampler, ShadowCoord, ivec2(-1,-1)); 
result += textureProjOffset(ShadowSampler, ShadowCoord, ivec2(-1,1)); 
result += textureProjOffset(ShadowSampler, ShadowCoord, ivec2(1,1)); 
result += textureProjOffset(ShadowSampler, ShadowCoord, ivec2(1,-1)); 
result = result * 0.25;

For a cube map I use samplerCubeShadow:

result = texture(ShadowCubeSampler, vec4(normalize(position), depth));

How to adopt above PCF when accessing a cube map ?

share|improve this question
up vote 3 down vote accepted

If you're looking for soft shadows, then you have to go back to the reason why shadows aren't hard in the real world.

Soft shadows are a by-product of lights that have a finite area. In order to handle this properly, you have to actually check how much of a light source is visible; it's not just a binary on/off.

Your 4x4 kernel is a good approximation for soft shadows, but only for directional lights. Each sample is effectively approximating a light of a particular apparent size. And since directional lights are infinitely far away, all objects will see the same apparent size of the light. So a fixed, 4x4 kernel can approximate soft shadows for a particular area of the light.

For a point light, that approximation no longer makes sense. You can't use a fixed kernel to get soft shadows, because the apparent size of the point light changes depending on where you are.

For this, you need to compute the apparent area of the light (based on the light's size), then compute a number of directions within this area which you feel is representative of the area. Or just whatever you feel you can get away with without killing your performance. You use these directions as the normals in your shadow tests. Done.

Now all of this is an approximation (or really just a hack), because they don't really provide soft shadows at all. The problem with these approximations is that they're basically changing the place in the world that they're looking for shadows from, rather than changing the place on the light where they're looking for shadows from. For a directional light, it's really one and the same, but not so for a point light. To get soft shadowing more accurately for point lights, you would need to render multiple shadow maps from multiple different positions.

Or just go with the approximation; it's probably loads cheaper.

share|improve this answer
I know that I get PCF without a texture offset but I wanted to see what happens when I increase a sample number from 4 to 16 using constant offset as above. Now I want to implement PCF with random offsets described here: link Is it also something what I should avoid ? What techniques do you recommend for achieve soft shadows without aliasing artifacts ? – Irbis Oct 30 '12 at 12:29
@Irbis: See my "edit" (which is really a complete rewrite). You should have mentioned you were doing soft shadows in your question. – Nicol Bolas Oct 30 '12 at 16:11
Thanks for the quick reply, but what do you think about the gpu gems article linked above ? Is that a good approximation for a point light ? – Irbis Oct 30 '12 at 16:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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