From 2caa09bebdbd2fd006814f300f0ce4591ff62ada Mon Sep 17 00:00:00 2001 From: Pixelflinger Date: Fri, 20 Mar 2020 17:22:27 -0700 Subject: [PATCH] Fix IBL mip calculation The max mip (i.e. mip at roughness 1) was off by one. --- filament/src/IndirectLight.cpp | 2 +- filament/src/View.cpp | 4 ++-- filament/src/details/IndirectLight.h | 4 ++-- .../include/private/filament/UibGenerator.h | 3 ++- libs/filabridge/src/UibGenerator.cpp | 3 ++- shaders/src/light_indirect.fs | 22 +++++++++---------- 6 files changed, 20 insertions(+), 18 deletions(-) diff --git a/filament/src/IndirectLight.cpp b/filament/src/IndirectLight.cpp index 8af6c5cd19..519198d9a5 100644 --- a/filament/src/IndirectLight.cpp +++ b/filament/src/IndirectLight.cpp @@ -180,7 +180,7 @@ namespace details { FIndirectLight::FIndirectLight(FEngine& engine, const Builder& builder) noexcept { if (builder->mReflectionsMap) { mReflectionsMapHandle = upcast(builder->mReflectionsMap)->getHwHandle(); - mMaxMipLevel = builder->mReflectionsMap->getLevels(); + mLevelCount = builder->mReflectionsMap->getLevels(); } std::copy( diff --git a/filament/src/View.cpp b/filament/src/View.cpp index fd67bce03a..b9d418de3c 100644 --- a/filament/src/View.cpp +++ b/filament/src/View.cpp @@ -367,8 +367,8 @@ void FView::prepareLighting(FEngine& engine, FEngine::DriverApi& driver, ArenaSc } // Set up uniforms and sampler for the IBL, guaranteed to be non-null at this point. - float2 iblMaxMipLevel{ ibl->getMaxMipLevel(), 1u << ibl->getMaxMipLevel() }; - u.setUniform(offsetof(PerViewUib, iblMaxMipLevel), iblMaxMipLevel); + float iblRoughnessOneLevel = ibl->getLevelCount() - 1.0f; + u.setUniform(offsetof(PerViewUib, iblRoughnessOneLevel), iblRoughnessOneLevel); u.setUniform(offsetof(PerViewUib, iblLuminance), intensity * exposure); u.setUniformArray(offsetof(PerViewUib, iblSH), ibl->getSH(), 9); if (ibl->getReflectionMap()) { diff --git a/filament/src/details/IndirectLight.h b/filament/src/details/IndirectLight.h index 998fe3e4a4..327237e469 100644 --- a/filament/src/details/IndirectLight.h +++ b/filament/src/details/IndirectLight.h @@ -50,7 +50,7 @@ public: void setIntensity(float intensity) noexcept { mIntensity = intensity; } void setRotation(math::mat3f const& rotation) noexcept { mRotation = rotation; } const math::mat3f& getRotation() const noexcept { return mRotation; } - size_t getMaxMipLevel() const noexcept { return mMaxMipLevel; } + size_t getLevelCount() const noexcept { return mLevelCount; } math::float3 getDirectionEstimate() const noexcept; math::float4 getColorEstimate(math::float3 direction) const noexcept; static math::float3 getDirectionEstimate(const math::float3 sh[9]) noexcept; @@ -62,7 +62,7 @@ private: std::array mIrradianceCoefs; float mIntensity = DEFAULT_INTENSITY; math::mat3f mRotation; - uint8_t mMaxMipLevel = 0; + uint8_t mLevelCount = 0; }; FILAMENT_UPCAST(IndirectLight) diff --git a/libs/filabridge/include/private/filament/UibGenerator.h b/libs/filabridge/include/private/filament/UibGenerator.h index b68d81ca6e..dc71dcf881 100644 --- a/libs/filabridge/include/private/filament/UibGenerator.h +++ b/libs/filabridge/include/private/filament/UibGenerator.h @@ -85,7 +85,8 @@ struct PerViewUib { // NOLINT(cppcoreguidelines-pro-type-member-init) filament::math::float4 userTime; // time(s), (double)time - (float)time, 0, 0 - filament::math::float2 iblMaxMipLevel; // maxlevel, float(1<