How to do it...

To add the PCF technique to the shadow mapping algorithm, use the following steps:

  1. When setting up the FBO for the shadow map, make sure to use linear filtering on the depth texture. Replace the corresponding lines with the following code:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,  
                GL_LINEAR); 
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,      
                GL_LINEAR); 
  1. Use the following code for the shadeWithShadow function within the fragment shader:
subroutine (RenderPassType) void shadeWithShadow() { vec3 ambient = vec3(0.2); vec3 diffSpec = diffAndSpec(); // The sum of the comparisons with nearby texels float sum = 0; // Sum contributions from texels around ShadowCoord sum += textureProjOffset(ShadowMap, ShadowCoord, ...

Get OpenGL 4 Shading Language Cookbook - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.