From ca47d4a84b87c18dcceb6471222ad655b31f7972 Mon Sep 17 00:00:00 2001 From: Tobias Date: Thu, 1 Dec 2022 11:15:34 +0100 Subject: [PATCH] Math cleanup. --- shader/phongshader.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shader/phongshader.cpp b/shader/phongshader.cpp index aab06cc..10390b4 100644 --- a/shader/phongshader.cpp +++ b/shader/phongshader.cpp @@ -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; }