fixed merge issues
This commit is contained in:
parent
c5cfe34861
commit
728b324c5b
1 changed files with 33 additions and 60 deletions
|
@ -19,7 +19,10 @@ float CookTorranceShader::F(float VdotH) const {
|
|||
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 fragmentColor;
|
||||
|
@ -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));
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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