From 958b086de876ba37bae5f629547565ffaa4a24dc Mon Sep 17 00:00:00 2001 From: Tobias Date: Wed, 30 Nov 2022 20:30:58 +0100 Subject: [PATCH] Phong fixed. --- shader/phongshader.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/shader/phongshader.cpp b/shader/phongshader.cpp index 3dd8836..aab06cc 100644 --- a/shader/phongshader.cpp +++ b/shader/phongshader.cpp @@ -14,11 +14,11 @@ Color PhongShader::shade(Scene const &scene, Ray const &ray) const { for (auto &light: scene.lights()) { auto illum = light->illuminate(scene, ray); - Vector3d omegaI = normalized(illum.direction); - Vector3d omegaR = 2 * dotProduct(omegaI, ray.normal) * ray.normal - omegaI; - float cosPsi = std::max(0.0f, dotProduct(ray.direction, omegaR)); - fragmentColor += illum.color * diffuseCoefficient * diffuseColor / PI - + illum.color * specularCoefficient * specularColor * std::pow(cosPsi, shininessExponent); + Vector3d reflection = illum.direction - 2 * dotProduct(illum.direction, ray.normal) * ray.normal; + Color diffuse = diffuseCoefficient * dotProduct(illum.direction, -ray.normal) * diffuseColor; + Color specular = specularCoefficient * specularColor + * std::pow(dotProduct(ray.direction, -reflection), shininessExponent); + fragmentColor += illum.color * diffuse + illum.color * specular; } return fragmentColor;