Merge branch 'master' into multithread_renderer
This commit is contained in:
commit
d26e59155d
2 changed files with 19 additions and 21 deletions
|
@ -14,9 +14,9 @@ Color CookTorranceShader::shade(Scene const &scene, Ray const &ray) const {
|
|||
for (auto &light: scene.lights()) {
|
||||
auto illum = light->illuminate(scene, ray);
|
||||
auto N = ray.normal;
|
||||
auto H = Vector3d{};
|
||||
auto V = ray.direction;
|
||||
auto L = illum.direction;
|
||||
auto H = normalized(V + L);
|
||||
|
||||
auto NV = dotProduct(N, V);
|
||||
auto NL = dotProduct(N, L);
|
||||
|
@ -27,32 +27,32 @@ Color CookTorranceShader::shade(Scene const &scene, Ray const &ray) const {
|
|||
|
||||
|
||||
|
||||
auto rhoS = F(VH) * D(NH) * G(NH, NV, VH, NL) / (PI * NV * NL);
|
||||
auto rhoS = F(VH) * D(NH) * G(NH, NV, VH, NL) / (4 * NV * NL);
|
||||
auto rhoPD = diffuseColor * rhoD + ctColor * rhoS;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
fragmentColor += illum.color * rhoPD;
|
||||
fragmentColor += illum.color * std::abs(NL) * rhoPD;
|
||||
}
|
||||
|
||||
return fragmentColor * diffuseColor;
|
||||
return diffuseColor * fragmentColor;
|
||||
}
|
||||
|
||||
float CookTorranceShader::D(float NdotH) const {
|
||||
float divisor = 4.0f * m * m * std::pow(cos(NdotH), 4);
|
||||
float exponent = -std::pow(tan(NdotH) / 2, 2);
|
||||
return 1 / divisor * std::exp(exponent);
|
||||
float exponent = std::pow(tan(NdotH) / m, 2);
|
||||
return 1 / divisor * std::exp(- 1.0f * exponent);
|
||||
}
|
||||
|
||||
float CookTorranceShader::F(float VdotH) const {
|
||||
return 0.1f;
|
||||
return F0 + (1 - F0) * std::pow(1 - VdotH, 5);
|
||||
}
|
||||
|
||||
float CookTorranceShader::G(float NdotH, float NdotV, float VdotH, float NdotL) const {
|
||||
if (std::abs(NdotL) < 0.1f) {
|
||||
return std::min(1.0f, std::min(2 * NdotH * NdotV / VdotH, 2 * NdotH * NdotL / VdotH));
|
||||
} else if (std::abs(NdotV) < 0.1f) {
|
||||
return 2 * NdotH * NdotL / VdotH;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,13 +14,11 @@ Color PhongShader::shade(Scene const &scene, Ray const &ray) const {
|
|||
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;
|
||||
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);
|
||||
}
|
||||
|
||||
return fragmentColor;
|
||||
|
|
Loading…
Reference in a new issue