Shadows

We’re shining a light on our donut, and yet there is no shadow. You can usually skip rendering shadows, but sometimes they really help.

Don’t Overuse Shadows

images/callout-icons/tip.png

It requires a lot of work for the computer to be able to draw shadows, so use them only in spots that they really help. This is a tough choice to make because shadows almost always make games look better. But, as we’ll see, it makes the computer work harder on something besides the main game and it’s a bit of a pain to set up correctly.

First, we need to tell the renderer to expect shadows. Add the line setting the shadowMapEnabled attribute just below the WebGL renderer line:

Get 3D Game Programming for Kids 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.