3D Game Programming

(C. Jardin) #1
the shine—to three 0.9 values, which is pretty close to all 1.0 values that would
make white.

In other words, we see a little more of the shine:


Always Use Gray or White for Specular Colors
It’s possible to use any color you like for the specular attribute. Nor-
mally, however, it’s best to stick with gray or white. For instance,
the sunlight that we’re shining on our donut is white, but it’s still
possible to make the specular color yellow (change the last number
to 0.0). But that is just weird—white light creating a yellow shine.

We’ve covered emissive and specular; there are two other color-related properties
that we can set on Phong materials: ambient and plain-old color. The ambient
color applies only when using an “ambient” light—a light that is everywhere.
The color property is used only when there are no strong lights nearby. We’ll
stick with emissive and specular in this book—they make cooler-looking
objects.

12.4 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
It requires a lot of work for the computer to be able to draw shad-
ows, 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:

report erratum • discuss

Shadows • 113


Prepared exclusively for Michael Powell

Free download pdf