I have two spheres I need to shade at once in c++ using phong’s reflection model. I also have two light sources. I have already calculated the ambient lighting. How would I go about calculating the diffusion lighting?
For some reason, it will only let me shade one sphere at a time, and I’ve tried adding up all the dot(n, l)’s together – it will still only shade the last sphere added.
This is what I have so far:
for i = 0; i < pointLights.size(); i++ {
for k = 0; k < spheres.size(); k++ {
N = ray.origin + ray.direction * t - spheres[k].center;
N = normalize(N);
L = ray.origin + ray.direction * t - pointLights[i].location;
L = normalize(L)
finalColor += spheres[k].kd * pointLights[i].id * max(dot(N, L), 0.0f);
}
}
I’m not really worried about if N and L are correct because I can find those out. I’m more worried about if I’m iterating correctly to add to the final color.
Anonymous is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.