Added WIP implementation for cooktorrance

This commit is contained in:
arvid schröder 2022-11-28 20:55:22 +01:00
parent 77bb2835cd
commit 992808b82d

View file

@ -2,12 +2,57 @@
#include "scene/scene.h"
#include "shader/cooktorranceshader.h"
CookTorranceShader::CookTorranceShader(Color const &diffCol, Color const &ctCol, float IOR, float roughness, float diffCoeff, float ctCoeff) : diffuseColor(diffCol * diffCoeff), ctColor(ctCol * ctCoeff), F0(IOR), m(roughness) {}
CookTorranceShader::CookTorranceShader(Color const &diffCol, Color const &ctCol, float IOR, float roughness,
float diffCoeff, float ctCoeff) : diffuseColor(diffCol * diffCoeff),
ctColor(ctCol * ctCoeff), F0(IOR),
m(roughness) {}
Color CookTorranceShader::shade(Scene const &scene, Ray const &ray) const {
Color fragmentColor;
Color fragmentColor;
// IMPLEMENT ME
// IMPLEMENT ME
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;
return fragmentColor;
}
auto NV = dotProduct(N, V);
auto NL = dotProduct(N, L);
auto NH = dotProduct(N, H);
auto VH = dotProduct(V, H);
float rhoD = 1.0f / PI;
auto rhoS = F(VH) * D(NH) * G(NH, NV, VH, NL) / (PI * NV * NL);
auto rhoPD = diffuseColor * rhoD + ctColor * rhoS;
fragmentColor += illum.color * rhoPD;
}
return fragmentColor * diffuseColor;
}
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 CookTorranceShader::F(float VdotH) const {
return 0.1f;
}
float CookTorranceShader::G(float NdotH, float NdotV, float VdotH, float NdotL) const {
return 1;
}