Added WIP Phong implementation
This commit is contained in:
parent
9dcbefe5a5
commit
4e3843a2fc
1 changed files with 16 additions and 5 deletions
|
@ -10,7 +10,18 @@ PhongShader::PhongShader(Color const &diffuseColor, float diffuseCoefficient, Co
|
||||||
Color PhongShader::shade(Scene const &scene, Ray const &ray) const {
|
Color PhongShader::shade(Scene const &scene, Ray const &ray) const {
|
||||||
Color fragmentColor;
|
Color fragmentColor;
|
||||||
|
|
||||||
// IMPLEMENT ME
|
|
||||||
|
for (auto &light: scene.lights()) {
|
||||||
|
auto illum = light->illuminate(scene, ray);
|
||||||
|
|
||||||
|
auto omegaI = normalized(illum.direction);
|
||||||
|
auto omegaR = 2 * dotProduct(omegaI, ray.normal) * ray.normal - omegaI;
|
||||||
|
auto cosPsi = dotProduct(ray.direction, omegaR);
|
||||||
|
auto colorI = diffuseCoefficient * diffuseColor / PI +
|
||||||
|
(specularCoefficient * specularColor * std::pow(cosPsi, shininessExponent));
|
||||||
|
|
||||||
|
fragmentColor += illum.color * colorI;
|
||||||
|
}
|
||||||
|
|
||||||
return fragmentColor;
|
return fragmentColor;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue