fixed merge issues
This commit is contained in:
parent
c5cfe34861
commit
728b324c5b
1 changed files with 33 additions and 60 deletions
|
@ -19,14 +19,17 @@ float CookTorranceShader::F(float VdotH) const {
|
||||||
return F0 + (1.0f - F0) * powf(1.0f - VdotH, 5);
|
return F0 + (1.0f - F0) * powf(1.0f - VdotH, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
float CookTorranceShader::G(float NdotH, float NdotV, float VdotH, float NdotL) const { return std::min(1.0f, std::min(2.0f * NdotH * NdotV / VdotH, 2.0f * NdotH * NdotL / VdotH)); }
|
float CookTorranceShader::G(float NdotH, float NdotV, float VdotH, float NdotL) const {
|
||||||
|
return std::min(1.0f, std::min(
|
||||||
|
2.0f * NdotH * NdotV / VdotH, 2.0f * NdotH * NdotL / VdotH));
|
||||||
|
}
|
||||||
|
|
||||||
Color CookTorranceShader::shade(Scene const &scene, Ray const &ray) const {
|
Color CookTorranceShader::shade(Scene const &scene, Ray const &ray) const {
|
||||||
Color fragmentColor;
|
Color fragmentColor;
|
||||||
|
|
||||||
if (m >= 0.0f) {
|
if (m >= 0.0f) {
|
||||||
// Accumulate the light over all light sources
|
// Accumulate the light over all light sources
|
||||||
for (const auto &light : scene.lights()) {
|
for (const auto &light: scene.lights()) {
|
||||||
Light::Illumination illum;
|
Light::Illumination illum;
|
||||||
illum = light->illuminate(scene, ray);
|
illum = light->illuminate(scene, ray);
|
||||||
|
|
||||||
|
@ -46,42 +49,12 @@ Color CookTorranceShader::shade(Scene const &scene, Ray const &ray) const {
|
||||||
float const VdotH = std::max(0.0f, dotProduct(-ray.direction, H));
|
float const VdotH = std::max(0.0f, dotProduct(-ray.direction, H));
|
||||||
|
|
||||||
if (NdotV * NdotL > EPSILON) {
|
if (NdotV * NdotL > EPSILON) {
|
||||||
Color const specular = this->ctColor * (F(VdotH) * D(NdotH) * G(NdotH, NdotV, VdotH, NdotL)) / (float(PI) * NdotV * NdotL);
|
Color const specular = this->ctColor * (F(VdotH) * D(NdotH) * G(NdotH, NdotV, VdotH, NdotL)) /
|
||||||
|
(float(PI) * NdotV * NdotL);
|
||||||
|
|
||||||
fragmentColor += specular * NdotL * illum.color;
|
fragmentColor += specular * NdotL * illum.color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto NV = dotProduct(N, V);
|
|
||||||
auto NL = dotProduct(N, L);
|
|
||||||
auto NH = dotProduct(N, H);
|
|
||||||
auto VH = dotProduct(V, H);
|
|
||||||
|
|
||||||
//Cook-Torrance diffuse Term
|
|
||||||
float rhoD = 1.0f / PI;
|
|
||||||
//Cook-Torrance Specular Term
|
|
||||||
//F = Fresnel; D = microfacet Distribution; G = Geometrical factor
|
|
||||||
float rhoS = F(VH) * D(NH) * G(NH, NV, VH, NL) / (4 * NV * NL);
|
|
||||||
//BRDF
|
|
||||||
Color rhoBD = diffuseColor * rhoD + ctColor * rhoS;
|
|
||||||
|
|
||||||
fragmentColor += illum.color * std::abs(NL) * rhoBD;
|
|
||||||
}
|
|
||||||
|
|
||||||
return diffuseColor * fragmentColor;
|
return diffuseColor * fragmentColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
float CookTorranceShader::D(float NdotH) const {
|
|
||||||
float divisor = 4.0f * m * m * std::pow(NdotH, 4.0f);
|
|
||||||
float exponent = (NdotH * NdotH - 1.0f) / (m * m * NdotH * NdotH);
|
|
||||||
return 1 / divisor * std::exp(exponent);
|
|
||||||
}
|
|
||||||
|
|
||||||
float CookTorranceShader::F(float VdotH) const {
|
|
||||||
return F0 + (1.0f - F0) * std::pow(1.0f - VdotH, 5.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
float CookTorranceShader::G(float NdotH, float NdotV, float VdotH, float NdotL) const {
|
|
||||||
return std::min(1.0f, std::min(2 * NdotH * NdotV / VdotH, 2 * NdotH * NdotL / VdotH));
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue