diff --git a/samples/app/IBL.cpp b/samples/app/IBL.cpp index dd26fb1ec7..4fa750916d 100644 --- a/samples/app/IBL.cpp +++ b/samples/app/IBL.cpp @@ -52,9 +52,9 @@ bool IBL::loadFromDirectory(const utils::Path& path) { shReader >> std::skipws; std::string line; - for (size_t i = 0; i < 9; i++) { + for (float3& band : mBands) { std::getline(shReader, line); - int n = sscanf(line.c_str(), "(%f,%f,%f)", &mBands[i].r, &mBands[i].g, &mBands[i].b); + int n = sscanf(line.c_str(), "(%f,%f,%f)", &band.r, &band.g, &band.b); // NOLINT(cert-err34-c) if (n != 3) return false; } } else { @@ -62,11 +62,11 @@ bool IBL::loadFromDirectory(const utils::Path& path) { } // Read mip-mapped cubemap - if (!loadCubemapLevel(&mTexture, path, 0, "m0_")) return false; + const std::string prefix = "m"; + if (!loadCubemapLevel(&mTexture, path, 0, prefix + "0_")) return false; size_t numLevels = mTexture->getLevels(); for (size_t i = 1; i 0.0) { + float NoH = dot(n, h); float LoH = max(dot(l, h), 0.0); - float NoH = cosTheta; // PDF inverse (we must use D_GGX() here, which is used to generate samples) float ipdf = (4.0 * LoH) / (D_GGX(linearRoughness, NoH, h) * NoH); - // See: "Real-time Shading with Filtered Importance Sampling", Jaroslav Krivanek - // Prefiltering doesn't work with anisotropy - float omegaS = invNumSamples * ipdf; - float mipLevel = clamp(log2(K * omegaS * invOmegaP) * 0.5, 0.0, IBL_MAX_MIP_LEVEL); + float mipLevel = prefilteredImportanceSampling(ipdf); + + // we use texture() instead of textureLod() to take advantage of mipmapping + vec3 L = decodeDataForIBL(texture(light_iblSpecular, l, mipLevel)); float D = distribution(linearRoughness, NoH, h); float V = visibility(pixel.roughness, linearRoughness, NoV, NoL, LoH); vec3 F = fresnel(pixel.f0, LoH); + vec3 Fr = F * (D * V * NoL * ipdf * invNumSamples); - vec3 Fr = F * (D * V * ipdf * NoL); - - // we use texture() instead of textureLod() to take advantage of mipmapping - vec3 env = decodeDataForIBL(texture(light_iblSpecular, l, mipLevel)); - indirectSpecular += (Fr * env) * invNumSamples; + indirectSpecular += (Fr * L); } }