cloudy-raytracer/shader/lambertshader.cpp

20 lines
632 B
C++
Raw Permalink Normal View History

2022-11-25 14:58:29 +01:00
#include "light/light.h"
#include "scene/scene.h"
#include "shader/lambertshader.h"
LambertShader::LambertShader(Color const &diffuseColor) : diffuseColor(diffuseColor) {}
Color LambertShader::shade(Scene const &scene, Ray const &ray) const {
Color fragmentColor;
2022-12-06 13:48:21 +01:00
// Accumulate the light over all light sources
for (const auto &light : scene.lights()) {
Light::Illumination const illum = light->illuminate(scene, ray);
// Diffuse term
Color const diffuse = this->diffuseColor * std::max(dotProduct(-illum.direction, ray.normal), 0.0f);
fragmentColor += diffuse * illum.color;
}
2022-11-25 14:58:29 +01:00
return fragmentColor;
}