From 3abf13106680aa161d5a3d5530de8d2f6a610f5c Mon Sep 17 00:00:00 2001 From: Mathias Agopian Date: Tue, 7 Jan 2025 11:43:39 -0800 Subject: [PATCH] Trivial clean-ups that shouldn't affect the behavior We add an offset to the shadowmap viewport, but in this change it is always set to (0,0) --- filament/src/ShadowMap.cpp | 14 +++++++++----- filament/src/ShadowMap.h | 4 +++- filament/src/ShadowMapManager.cpp | 16 ++++------------ filament/src/ShadowMapManager.h | 3 ++- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/filament/src/ShadowMap.cpp b/filament/src/ShadowMap.cpp index 35fa104dcdc..1115bbcba24 100644 --- a/filament/src/ShadowMap.cpp +++ b/filament/src/ShadowMap.cpp @@ -1296,6 +1296,10 @@ void ShadowMap::updateSceneInfoSpot(mat4f const& Mv, FScene const& scene, } ); } +void ShadowMap::setAllocation(uint8_t layer, backend::Viewport viewport) noexcept { + mLayer = layer; + mOffset = { viewport.left, viewport.bottom }; +} backend::Viewport ShadowMap::getViewport() const noexcept { // We set a viewport with a 1-texel border for when we index outside the texture. @@ -1305,7 +1309,7 @@ backend::Viewport ShadowMap::getViewport() const noexcept { // can work properly if the shadowmap is in an atlas (and we can't rely on h/w clamp). const uint32_t dim = mOptions->mapSize; const uint16_t border = 1u; - return { border, border, dim - 2u * border, dim - 2u * border }; + return { mOffset.x + border, mOffset.y + border, dim - 2u * border, dim - 2u * border }; } backend::Viewport ShadowMap::getScissor() const noexcept { @@ -1319,10 +1323,10 @@ backend::Viewport ShadowMap::getScissor() const noexcept { const uint16_t border = 1u; switch (mShadowType) { case ShadowType::DIRECTIONAL: - return { border, border, dim - 2u * border, dim - 2u * border }; + return { mOffset.x + border, mOffset.y + border, dim - 2u * border, dim - 2u * border }; case ShadowType::SPOT: case ShadowType::POINT: - return { 0, 0, dim, dim }; + return { mOffset.x, mOffset.y, dim, dim }; } } @@ -1345,8 +1349,8 @@ math::float4 ShadowMap::getClampToEdgeCoords(ShadowMapInfo const& shadowMapInfo) float const texel = 1.0f / float(shadowMapInfo.atlasDimension); float const dim = float(mOptions->mapSize); - float const l = border; - float const b = border; + float const l = float(mOffset.x) + border; + float const b = float(mOffset.y) + border; float const w = dim - 2.0f * border; float const h = dim - 2.0f * border; float4 const v = float4{ l, b, l + w, b + h } * texel; diff --git a/filament/src/ShadowMap.h b/filament/src/ShadowMap.h index cf131d4f64d..1da8b10e2b1 100644 --- a/filament/src/ShadowMap.h +++ b/filament/src/ShadowMap.h @@ -179,7 +179,8 @@ class ShadowMap { LightManager::ShadowOptions const* getShadowOptions() const noexcept { return mOptions; } size_t getLightIndex() const { return mLightIndex; } uint16_t getShadowIndex() const { return mShadowIndex; } - void setLayer(uint8_t layer) noexcept { mLayer = layer; } + void setAllocation(uint8_t layer, backend::Viewport viewport) noexcept; + uint8_t getLayer() const noexcept { return mLayer; } backend::Viewport getViewport() const noexcept; backend::Viewport getScissor() const noexcept; @@ -353,6 +354,7 @@ class ShadowMap { ShadowType mShadowType : 2; // :2 bool mHasVisibleShadows : 2; // :2 uint8_t mFace : 3; // :3 + math::ushort2 mOffset{}; // 4 }; } // namespace filament diff --git a/filament/src/ShadowMapManager.cpp b/filament/src/ShadowMapManager.cpp index 158259bdcf3..25e8815280d 100644 --- a/filament/src/ShadowMapManager.cpp +++ b/filament/src/ShadowMapManager.cpp @@ -979,13 +979,13 @@ void ShadowMapManager::calculateTextureRequirements(FEngine& engine, FView& view auto const& options = shadowMap.getShadowOptions(); maxDimension = std::max(maxDimension, options->mapSize); elvsm = elvsm || options->vsm.elvsm; - shadowMap.setLayer(layer++); + shadowMap.setAllocation(layer++, {}); } for (ShadowMap& shadowMap : getSpotShadowMaps()) { auto const& options = shadowMap.getShadowOptions(); maxDimension = std::max(maxDimension, options->mapSize); elvsm = elvsm || options->vsm.elvsm; - shadowMap.setLayer(layer++); + shadowMap.setAllocation(layer++, {}); } const uint8_t layersNeeded = layer; @@ -1003,17 +1003,9 @@ void ShadowMapManager::calculateTextureRequirements(FEngine& engine, FView& view TextureFormat format = TextureFormat::DEPTH16; if (view.hasVSM()) { if (vsmShadowOptions.highPrecision) { - if (elvsm) { - format = TextureFormat::RGBA32F; - } else { - format = TextureFormat::RG32F; - } + format = elvsm ? TextureFormat::RGBA32F : TextureFormat::RG32F; } else { - if (elvsm) { - format = TextureFormat::RGBA16F; - } else { - format = TextureFormat::RG16F; - } + format = elvsm ? TextureFormat::RGBA16F : TextureFormat::RG16F; } } diff --git a/filament/src/ShadowMapManager.h b/filament/src/ShadowMapManager.h index 28df0f73206..964be0d1593 100644 --- a/filament/src/ShadowMapManager.h +++ b/filament/src/ShadowMapManager.h @@ -17,12 +17,13 @@ #ifndef TNT_FILAMENT_DETAILS_SHADOWMAPMANAGER_H #define TNT_FILAMENT_DETAILS_SHADOWMAPMANAGER_H -#include "Culler.h" +#include "AtlasAllocator.h" #include "ShadowMap.h" #include "ds/TypedBuffer.h" #include #include +#include #include #include