Spotlights and Sunlight

So far, we’ve seen two types of lights:

  • Point, which acts like a light bulb
  • Ambient, which provides a small amount of light everywhere

Two other lights are worth a quick look:

  • Spotlight, which is great for focusing light at a single position
  • Directional, which makes shadows like sunlight does

The difference between the lights is easier to see with objects in motion. So, down in the animate() function, add the following code to change the donut’s position.

​ donut.rotation.​set​(t, 2*t, 0);
»donut.position.z = 200 * Math.sin(t);

This moves the donut back and forward, even as it continues to spin.

Let’s also dim the point light a bit, since we’ll have more than one light shining on our donut.

»​var​ point ...

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