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()) {
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;