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.
This commit is contained in:
Philip Rideout
2020-11-18 12:31:51 -08:00
parent 9c20294e4b
commit f83eb114bc
2 changed files with 9 additions and 7 deletions

View File

@@ -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<const float3*>(sh))
.build(*this));

View File

@@ -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<backend::HwTexture> 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();