shadows.c 8.10

This include file contains a small lite-C script for generating PSSM (Parallel Split Shadow Maps) in outdoor levels. In this algorithm, several shadow maps are used for rendering shadows in different resolution, depending on the distance to the camera. The script uses five view stages and two shaders from the code folder, vp_depth.fx and vp_shadow.fx. The shaders are simple enough to understand them with some previous shader knowledge, for instance through the Shader Workshops. If you want to modify the script or the shaders, please edit a copy in your work folder, and not the original files in the include and code folders.

Stencil shadow PSSM shadow

PSSM shadows have some advantages and some disadvantages in comparison to the standard stencil shadow algorithm:

Global parameters

Parameter Default Remarks
Shadow depth bias. Too small values cause "surface acne", too large values cause "peter panning" (displaced shadows). Use the [Tab] console to adjust this variable to the optimal value for your level.
Split scheme, 0..1. A smaller value favors a linear split scheme, a higher value favors a logarithmic split scheme. You can find details about split schemes in GPU Gems 3, chapter 10. Use the [Tab] console to adjust this variable to the optimal value for your level.
Shadow map resolution, either 512, 1024, or 2048. Set this before calling pssm_run.
Shadow darkness factor, 0..1.


Activate or deactivate PSSM shadows.


numsplits - number of shadow maps, 0..4. Every shadow map requires a rendering pass. Good values are 3 for small levels, and 4 for large levels. Use 0 for deactivating PSSM shadows.



#include <default.c>
#include <shadows.c>

function main()
  video_mode = 8;
  shadow_stencil = 8; // activate external shadows
  shadow_lod = 2; // works also for PSSM

// set up a level

// all objects get the SHADOW flag
  for(you = ent_next(NULL); you; you = ent_next(you)) 
// adjust camera and bias, activate PSSM camera.clip_far = 3000; camera.clip_near = 30; pssm_fbias = 0.0005; pssm_run(3); }

See Also:

stencil shadows, SHADOW

► latest version online