Lambert shading!

This commit is contained in:
Eryn Wells 2013-09-11 22:03:50 -07:00
parent 1e39776145
commit e76bf0f444

View file

@ -94,10 +94,6 @@ void
Scene::render()
{
pixels = new Color[width * height];
if (pixels == NULL) {
// TODO: Print an error.
return;
}
Ray primary_ray;
Vector3 o, d;
@ -173,6 +169,20 @@ Scene::trace_ray(const Ray &ray, const int depth)
return Color::Black;
}
// TODO: Lighting.
return intersected_shape->get_material().get_color();
Color out_color = intersected_shape->get_material().get_color();
Vector3 intersection = ray.parameterize(nearest_t);
Vector3 normal = intersected_shape->compute_normal(intersection);
for (Light *l : lights) {
Vector3 light_direction = intersection - l->get_origin();
light_direction.normalize();
float ldotn = light_direction.dot(normal);
out_color.red *= ((ldotn >= 0.0) ? ldotn : 0.0) * l->get_intensity();
out_color.green *= ((ldotn >= 0.0) ? ldotn : 0.0) * l->get_intensity();
out_color.blue *= ((ldotn >= 0.0) ? ldotn : 0.0) * l->get_intensity();
}
return out_color;
}