Skip to content

Commit

Permalink
Trivial clean-ups that shouldn't affect the behavior
Browse files Browse the repository at this point in the history
We add an offset to the shadowmap viewport, but in this change
it is always set to (0,0)
  • Loading branch information
pixelflinger committed Jan 13, 2025
1 parent 2b0077e commit 3abf131
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 19 deletions.
14 changes: 9 additions & 5 deletions filament/src/ShadowMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 {
Expand All @@ -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 };
}
}

Expand All @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion filament/src/ShadowMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
16 changes: 4 additions & 12 deletions filament/src/ShadowMapManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
}

Expand Down
3 changes: 2 additions & 1 deletion filament/src/ShadowMapManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <filament/LightManager.h>
#include <filament/Options.h>
#include <filament/Viewport.h>

#include <private/filament/EngineEnums.h>
#include <private/filament/UibStructs.h>
Expand Down

0 comments on commit 3abf131

Please sign in to comment.