Math cleanup.

This commit is contained in:
Tobias 2022-12-01 11:15:34 +01:00
parent 373ebda28d
commit ca47d4a84b

View file

@ -14,10 +14,10 @@ Color PhongShader::shade(Scene const &scene, Ray const &ray) const {
for (auto &light: scene.lights()) {
auto illum = light->illuminate(scene, ray);
Vector3d reflection = illum.direction - 2 * dotProduct(illum.direction, ray.normal) * ray.normal;
Vector3d reflection = 2 * dotProduct(illum.direction, ray.normal) * ray.normal - illum.direction;
Color diffuse = diffuseCoefficient * dotProduct(illum.direction, -ray.normal) * diffuseColor;
Color specular = specularCoefficient * specularColor
* std::pow(dotProduct(ray.direction, -reflection), shininessExponent);
* std::pow(dotProduct(ray.direction, reflection), shininessExponent);
fragmentColor += illum.color * diffuse + illum.color * specular;
}