Phong fixed.

This commit is contained in:
Tobias 2022-11-30 20:30:58 +01:00
parent f44de665e0
commit 958b086de8

View file

@ -14,11 +14,11 @@ Color PhongShader::shade(Scene const &scene, Ray const &ray) const {
for (auto &light: scene.lights()) { for (auto &light: scene.lights()) {
auto illum = light->illuminate(scene, ray); auto illum = light->illuminate(scene, ray);
Vector3d omegaI = normalized(illum.direction); Vector3d reflection = illum.direction - 2 * dotProduct(illum.direction, ray.normal) * ray.normal;
Vector3d omegaR = 2 * dotProduct(omegaI, ray.normal) * ray.normal - omegaI; Color diffuse = diffuseCoefficient * dotProduct(illum.direction, -ray.normal) * diffuseColor;
float cosPsi = std::max(0.0f, dotProduct(ray.direction, omegaR)); Color specular = specularCoefficient * specularColor
fragmentColor += illum.color * diffuseCoefficient * diffuseColor / PI * std::pow(dotProduct(ray.direction, -reflection), shininessExponent);
+ illum.color * specularCoefficient * specularColor * std::pow(cosPsi, shininessExponent); fragmentColor += illum.color * diffuse + illum.color * specular;
} }
return fragmentColor; return fragmentColor;