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()) {
|
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;
|
||||||
|
|
Loading…
Reference in a new issue