I am trying to implement the phong lightning model in this cpp framework.
The Diffusion works fine but the specular seems to lightning the sphere corners...im not really sure why, because the formular seems to be correct. Has someone an idea?
Actually Output:
My Code looks like this:
Material *material = obj->material; //the hit objects material
Point hit = ray.at(min_t); //the hit point
Vector N = obj->normal(hit); //the normal at hit point
Vector V = -ray.D; //the view vector
Color color = material->color;
double colorFactor = material->ka;
for( size_t i = 0; i < numLights ; ++i)
{
Vector lightsVector = hit - lights[i]->position;
lightsVector.normalize();
Vector vectorReflection = (2*(N.dot(lightsVector))*N) - lightsVector;
vectorReflection.normalize();
double diffusion = std::max<double>(0.0,-material->kd*(lightsVector.dot(N)));
double specular = material->ks*pow(std::max<double>(0.0,vectorReflection.dot(V.normalized())),material->n);
std::cout << specular << std::endl;
colorFactor += diffusion + specular;
}
color *=colorFactor;
i am very thankful for any hint you can give me...