Original Post
I've finally got of my fat ass and am writing the "proper" version of my cel-shading article (the one that's on GD.net at the moment was an alpha version which I sent to dave for comments/suggestions and he put the damn thing up!) and I'm having a little trouble with the lighting calcuations.
I've managed to work out the calculations for Positional Lighting with Vertex Normals and Positions, but I now need to somehow add the light's direction to it.
Here's the code for Light Position with Vertex Position/Normal:
Knowing my luck those formulae are wrong anyway
(please tell me if they are).
If you know how to get the light's direction in there I would greatly appreciate it.
Thanks in advance
Edited by - MENTAL on December 23, 2001 11:08:46 AM
if (Lights[i].UseDirection == false && Lights[i].UsePosition == true)
{
RotateVector (Matrix, Vertices[i].Normal, RotatedNormal);
//
RotatedNormal.Normalize ();
//
RotateVector (Matrix, Vertices[i].Position, RotatedPosition);
//
LightVector.X = RotatedPosition.X - Lights[i].Position.X;
LightVector.Y = RotatedPosition.Y - Lights[i].Position.Y;
LightVector.Z = RotatedPosition.Z - Lights[i].Position.Z;
//
LightVector.Normalize ();
//
ShadeValue = RotatedNormal.DotProduct (LightVector);
//
if (ShadeValue < 0.0f)
ShadeValue = 0.0f;
//
if (ShadeValue > Vertices[i].ShadeValue)
Vertices[i].ShadeValue = ShadeValue;
}
|