Using a shadow map for fixed shadows

In Chapter 5, Lights and Custom Shaders we will show you a number of recipes that deal with lights and shadows. It is, however, also possible to fake shadows using a texture. This kind of texture is called a shadow map or a light map. In this recipe, we explain how you can use such a texture in Three.js.

Getting ready

For this recipe, we first need a shadow map. There are different ways to create shadow maps, but that is outside the scope of this recipe. If you're interested in creating your own shadow maps, you can follow this tutorial from the Blender site: http://wiki.blender.org/index.php/Doc:2.4/Tutorials/Game_Engine/YoFrankie/Baking_Shadow_Maps.

In the sources for this book, in the assets/textures folder, ...

Get Three.js Cookbook 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.