Original Post
Hi,
I am trying to do my own lighting routines and facing some issues with it. I am trying to follow Foley to do the lighting. But it does not seem to be correct. I am trying to get a something similar to the default GL lighting.
As from Foley I understand that intensity
quote:Now I setup a structure to get r, g, b, and a value using the following structure
I = IaKa + IdKdcos(phi) and cos(phi) = DotProduct(Surface_Normal, Light_Direction) Hence I = IaKa + IdKd * DotProduct(Surface_Normal, Light_Direction)
// vector4 is a class having x, y, z, w as floats
// vector3 is a class having x, y, z as floats
typedef struct {
vector4 ambient, diffuse; // ambient and diffuse components
float ambFactor, diffFactor; // coefficents
vector4 normals;
vector4 finalColor; // final color to be used
} Light;
Then I went and did the calculations for the final color doing the following
vector4 SetLight(vector3 position, Light &light)
{
light.finalColor.set(0, 0, 0, 1);
light.ambient.set(0, 0, 0, 1);
light.ambFactor = 1.0f;
light.ambient *= light.ambFactor;
light.diffuse.set(1, 1, 1, 0);
light.diffFactor = 1.0f;
light.diffuse *= light.diffFactor;
light.position.set(0, 0, 1, 0);
vector4 pos(position);
vector4 dir = light.position - pos;
vector3 n = Normalized(position);
vector4 normal(n);
float theta = DotProduct(normal, dir.normalize());
light.diffuse *= theta;
light.finalColor += light.ambient + light.diffuse;
return light.finalColor;
}
It however does not seem to be doing it right. I am not sure if I am doing the calculations right of if my undertsanding of doing the lighting calculations is flawed. I would like to know if my calculations are right or not or if something needs to be done differently ?
Thank you.