Spectrum FresnelBlend::f(const Vector &wo, const Vector &wi) const { Spectrum diffuse = (28.f/(23.f*M_PI)) * Rd * (Spectrum(1.) - Rs) * (1 - powf(1 - .5f * fabsf(CosTheta(wi)), 5)) * (1 - powf(1 - .5f * fabsf(CosTheta(wo)), 5)); Vector H = Normalize(wi + wo); Spectrum specular = distribution->D(H) / (8.f * M_PI * AbsDot(wi, H) * max(fabsf(CosTheta(wi)), fabsf(CosTheta(wo)))) * SchlickFresnel(Dot(wi, H)); return diffuse + specular; }
Spectrum FresnelBlend::f(const Vector3f &wo, const Vector3f &wi) const { auto pow5 = [](Float v) { return (v * v) * (v * v) * v; }; Spectrum diffuse = (28.f / (23.f * Pi)) * Rd * (Spectrum(1.f) - Rs) * (1 - pow5(1 - .5f * AbsCosTheta(wi))) * (1 - pow5(1 - .5f * AbsCosTheta(wo))); Vector3f wh = wi + wo; if (wh.x == 0 && wh.y == 0 && wh.z == 0) return Spectrum(0); wh = Normalize(wh); Spectrum specular = distribution->D(wh) / (4 * AbsDot(wi, wh) * std::max(AbsCosTheta(wi), AbsCosTheta(wo))) * SchlickFresnel(Dot(wi, wh)); return diffuse + specular; }