From f83eb114bcd0db4949e5fae70dbe05fc4d0cb34f Mon Sep 17 00:00:00 2001 From: Philip Rideout Date: Wed, 18 Nov 2020 12:31:51 -0800 Subject: [PATCH] Filament should always bind an IBL texture. This prevents a SwiftShader crash and/or a slew of "no texture bound" warnings that would appear when the client provides an IBL without providing reflections texture, which should be a valid thing to do. Note that it is okay to declare a sampler in GLSL that never gets bound, as long as it is never sampled from. Since we always sample from the IBL specular texture, we should always bind something to it. --- filament/src/Engine.cpp | 1 - filament/src/View.cpp | 15 +++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/filament/src/Engine.cpp b/filament/src/Engine.cpp index 42cfbdbcb3..ce9c41c9fb 100644 --- a/filament/src/Engine.cpp +++ b/filament/src/Engine.cpp @@ -237,7 +237,6 @@ void FEngine::init() { // 3 bands = 9 float3 const float sh[9 * 3] = { 0.0f }; mDefaultIbl = upcast(IndirectLight::Builder() - .reflections(mDefaultIblTexture) .irradiance(3, reinterpret_cast(sh)) .build(*this)); diff --git a/filament/src/View.cpp b/filament/src/View.cpp index cbcf7b23bf..88332faa43 100644 --- a/filament/src/View.cpp +++ b/filament/src/View.cpp @@ -301,13 +301,16 @@ void FView::prepareLighting(FEngine& engine, FEngine::DriverApi& driver, ArenaSc u.setUniform(offsetof(PerViewUib, iblRoughnessOneLevel), iblRoughnessOneLevel); u.setUniform(offsetof(PerViewUib, iblLuminance), intensity * exposure); u.setUniformArray(offsetof(PerViewUib, iblSH), ibl->getSH(), 9); - if (ibl->getReflectionHwHandle()) { - mPerViewSb.setSampler(PerViewSib::IBL_SPECULAR, { - ibl->getReflectionHwHandle(), { - .filterMag = SamplerMagFilter::LINEAR, - .filterMin = SamplerMinFilter::LINEAR_MIPMAP_LINEAR - }}); + + // We always sample from the reflection texture, so provide a dummy texture if necessary. + backend::Handle reflection = ibl->getReflectionHwHandle(); + if (!reflection) { + reflection = engine.getDummyCubemap()->getHwHandle(); } + mPerViewSb.setSampler(PerViewSib::IBL_SPECULAR, { reflection, { + .filterMag = SamplerMagFilter::LINEAR, + .filterMin = SamplerMinFilter::LINEAR_MIPMAP_LINEAR + }}); // Directional light (always at index 0) auto& lcm = engine.getLightManager();