Phong fixed.
This commit is contained in:
parent
f44de665e0
commit
958b086de8
1 changed files with 5 additions and 5 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue