Welcome to MSDN Blogs Sign in | Join | Help

Nerd Herder

Dean Johnson’s blog about life on the XNA platform and tools team

Syndication

Lights, Camera… Avatar!

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.

Published Monday, May 18, 2009 10:57 PM by dejohn

Comments

# Lights, Camera??? Avatar! | Microsoft Share Point @ Monday, May 18, 2009 6:06 PM

PingBack from http://microsoft-sharepoint.simplynetdev.com/lights-camera%e2%80%a6-avatar/

Lights, Camera??? Avatar! | Microsoft Share Point

Anonymous comments are disabled
Page view tracker