Modifying Avatar Lighting (XNA Game Studio 4.0 Programming)

Now that you have been able to load and draw some avatars, it’s time to dig a little deeper so they can better integrate into your game.Your game might take place at night or use some special colors in the lighting of your game.The AvatarRenderer provides the capability to set the ambient light color and one directional light.

Let’s modify the existing sample to update the lighting to use when drawing the avatar. Add the following code to your game’s Draw method before calling the AvatarRenderer.Draw method.

tmp14-144_thumb

First, create a new light direction, which is pointing in the right and up direction. The direction needs to be normalized before setting the LightDirection property on the AvatarRenderer.

Set the color of the directional light to fully green by using the LightColor property.

Finally, set the ambient lighting value to around 25 percent of each color channel by using the AmbientLightColor property.

Running the sample now shows a green light on the avatar’s lower left. It should look similar to Figure 10.5.


Avatar with modified lighting

Figure 10.5 Avatar with modified lighting

Next post:

Previous post: