Nerd Herder

Dean Johnson blogs about life on the XNA platform and tools team

Lights, Camera… Avatar!

Lights, Camera… Avatar!

  • Comments 1

Sometimes you may not want your avatar flawlessly lit from above. What if your game takes place at night? What if the sun in your game is green? What if you need the light to move?

The Avatar APIs expose an ambient light and one directional light. The AvatarRenderer class has properties for AmbientLightColor, LightDirection, and LightColor. All are of the type Vector3.

The APIs also allow the developer to over saturate these values. This allows for some cool lighting effects like the one pictured below. I used the following code to product the results below.

avatarRenderer.LightDirection = new Vector3(1, 1, 0);
avatarRenderer.LightColor = new Vector3(0, 10, 0);
avatarRenderer.AmbientLightColor = new Vector3(1, 0, 0); 

clip_image002

So what happens if you set all of the values to zero? You should get a completely black area in the shape of your avatar correct?

avatarRenderer.LightDirection = new Vector3(0, 0, 0);
avatarRenderer.LightColor = new Vector3(0, 0, 0);
avatarRenderer.AmbientLightColor = new Vector3(0, 0, 0); 

clip_image004

Dark but not totally black. The avatar system uses a rim light also called a back light to create an edge around the avatar. But it is still possible to make the avatar completely black. Just set the ambient values all to a negative number. This will subtract from the final lighting values.

avatarRenderer.LightDirection = new Vector3(0, 0, 0);
avatarRenderer.LightColor = new Vector3(0, 0, 0);
avatarRenderer.AmbientLightColor = new Vector3(-1, -1, -1);

clip_image006

As you can see from the picture above there is still a small amount of light on the avatars shoes. This can be removed with a larger negative number for the ambient light value.

Leave a Comment
  • Please add 2 and 1 and type the answer here:
  • Post
Translate This Page
Search
Archive