Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--[BE Week]Remove shadowmanager/variance shadow map code #2139

Merged
merged 2 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/esp/assets/ResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include <Magnum/MeshTools/Compile.h>
#include <Magnum/MeshTools/Concatenate.h>
#include <Magnum/MeshTools/Copy.h>
#include <Magnum/MeshTools/FilterAttributes.h>
#include <Magnum/MeshTools/Filter.h>
#include <Magnum/MeshTools/Interleave.h>
#include <Magnum/MeshTools/RemoveDuplicates.h>
#include <Magnum/MeshTools/Transform.h>
Expand Down
24 changes: 1 addition & 23 deletions src/esp/assets/ResourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
#include <vector>

#include <Corrade/Containers/EnumSet.h>
#include <Magnum/Trade/AbstractImporter.h>

#include "Asset.h"
#include "MeshMetaData.h"
#include "esp/gfx/Drawable.h"
#include "esp/gfx/ShaderManager.h"
#include "esp/gfx/ShadowMapManager.h"
#include "esp/physics/configure.h"

#include "esp/metadata/attributes/AttributesEnumMaps.h"
Expand Down Expand Up @@ -578,21 +578,6 @@ class ResourceManager {
*/
gfx::ShaderManager& getShaderManager() { return shaderManager_; }

/**
* @brief get the shadow map manager
*/
gfx::ShadowMapManager& getShadowMapManger() { return shadowManager_; }

/**
* @brief get the shadow map keys
*/
std::map<int, std::vector<Magnum::ResourceKey>>& getShadowMapKeys() {
return shadowMapKeys_;
}

static constexpr const char* SHADOW_MAP_KEY_TEMPLATE =
"scene_id={}-light_id={}";

/**
* @brief Build data for a report for semantic mesh connected components based
* on color/id. Returns map of data keyed by SemanticObject index in
Expand Down Expand Up @@ -1255,13 +1240,6 @@ class ResourceManager {

int activePbrIbl_ = ID_UNDEFINED;

/**
* @brief shadow map for point lights
*/
// TODO: directional light shadow maps
gfx::ShadowMapManager shadowManager_;
// scene graph id -> keys for the shadow maps
std::map<int, std::vector<Magnum::ResourceKey>> shadowMapKeys_;
}; // class ResourceManager

} // namespace assets
Expand Down
5 changes: 0 additions & 5 deletions src/esp/gfx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ set(
PbrTextureUnit.h
DepthMapDrawableBase.cpp
DepthMapDrawableBase.h
ShadowMapManager.h
VarianceShadowMapShader.h
VarianceShadowMapShader.cpp
VarianceShadowMapDrawable.h
VarianceShadowMapDrawable.cpp
GaussianFilterShader.h
GaussianFilterShader.cpp
)
Expand Down
84 changes: 7 additions & 77 deletions src/esp/gfx/CubeMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ const Mn::GL::Framebuffer::ColorAttachment rgbaAttachment =
Mn::GL::Framebuffer::ColorAttachment{0};
const Mn::GL::Framebuffer::ColorAttachment objectIdAttachment =
Mn::GL::Framebuffer::ColorAttachment{1};
// vsm = variance shadow map
const Mn::GL::Framebuffer::ColorAttachment vsmAttachment =
Mn::GL::Framebuffer::ColorAttachment{2};

/**
* @brief check if the class instance is created with corresponding texture
Expand Down Expand Up @@ -67,14 +64,6 @@ void textureTypeSanityCheck(const char* functionNameStr,
return;
break;

case CubeMap::TextureType::VarianceShadowMap:
CORRADE_ASSERT(flag & CubeMap::Flag::VarianceShadowMapTexture,
functionNameStr
<< "instance was not created with variance shadow map"
"texture output enabled.", );
return;
break;

case CubeMap::TextureType::Count:
break;
}
Expand All @@ -92,11 +81,10 @@ void mipLevelSanityCheck(const char* msgPrefix,
msgPrefix << "CubeMap is not created with "
"Flag::ManuallyBuildMipmap specified. ", );
// TODO: HDR!!
CORRADE_ASSERT((flags & CubeMap::Flag::ColorTexture) ||
(flags & CubeMap::Flag::VarianceShadowMapTexture),
msgPrefix
<< "CubeMap is not created with Flag::ColorTexture or "
"VarianceShadowMapTexture specified.", );
CORRADE_ASSERT(
(flags & CubeMap::Flag::ColorTexture),
msgPrefix
<< "CubeMap is not created with Flag::ColorTexture specified.", );

CORRADE_ASSERT(mipLevel < mipmapLevels,
msgPrefix << "mip level" << mipLevel
Expand Down Expand Up @@ -134,9 +122,6 @@ const char* getTextureTypeFilenameString(CubeMap::TextureType type) {
case CubeMap::TextureType::ObjectId:
return "objectId";
break;
case CubeMap::TextureType::VarianceShadowMap:
return "varianceShadowMap";
break;
case CubeMap::TextureType::Count:
break;
}
Expand All @@ -158,9 +143,6 @@ Mn::PixelFormat getPixelFormat(CubeMap::TextureType type) {
case CubeMap::TextureType::ObjectId:
return Mn::PixelFormat::R32UI;
break;
case CubeMap::TextureType::VarianceShadowMap:
return Mn::PixelFormat::RG32F;
break;
case CubeMap::TextureType::Count:
break;
}
Expand Down Expand Up @@ -225,26 +207,6 @@ void CubeMap::recreateTexture() {
}
}

// variance shadow map
if (flags_ & Flag::VarianceShadowMapTexture) {
auto& vsmTexture = texture(TextureType::VarianceShadowMap);
vsmTexture = Mn::GL::CubeMapTexture{};
vsmTexture
.setWrapping(Mn::GL::SamplerWrapping::ClampToEdge)
// it is used to store linear depth
.setMinificationFilter(Mn::GL::SamplerFilter::Linear,
Mn::GL::SamplerMipmap::Linear)
.setMagnificationFilter(Mn::GL::SamplerFilter::Linear);

if ((flags_ & Flag::AutoBuildMipmap) ||
(flags_ & Flag::ManuallyBuildMipmap)) {
mipmapLevels_ = Mn::Math::log2(imageSize_) + 1;
vsmTexture.setStorage(mipmapLevels_, Mn::GL::TextureFormat::RG32F, size);
} else {
vsmTexture.setStorage(1, Mn::GL::TextureFormat::RG32F, size);
}
}

// depth texture
if (flags_ & Flag::DepthTexture) {
auto& depthTexture = texture(TextureType::Depth);
Expand Down Expand Up @@ -291,12 +253,6 @@ void CubeMap::attachFramebufferRenderbuffer(unsigned int cubeSideIndex,
int(mipLevel));
}

if (flags_ & Flag::VarianceShadowMapTexture) {
frameBuffer_[cubeSideIndex].attachCubeMapTexture(
vsmAttachment, texture(TextureType::VarianceShadowMap), cubeMapCoord,
int(mipLevel));
}

// does NOT make any sense to talk about mip level for depth or object id
// texture. so the mipLevel is always 0 for both.
if (flags_ & Flag::DepthTexture) {
Expand Down Expand Up @@ -333,7 +289,6 @@ void CubeMap::prepareToDraw(unsigned int cubeSideIndex,
// Note: we ONLY need to map shader output to color attachment when necessary,
// which means in depth texture mode, we do NOT need to do this
if (flags_ & CubeMap::Flag::ColorTexture ||
flags_ & CubeMap::Flag::VarianceShadowMapTexture ||
flags_ & CubeMap::Flag::ObjectIdTexture) {
mapForDraw(cubeSideIndex);
}
Expand Down Expand Up @@ -376,11 +331,7 @@ void CubeMap::mapForDraw(unsigned int index) {
: Mn::GL::Framebuffer::DrawAttachment::None)},
{ObjectIdOutput, (flags_ & CubeMap::Flag::ObjectIdTexture
? objectIdAttachment
: Mn::GL::Framebuffer::DrawAttachment::None)},
{VarianceShadowMapOutput,
(flags_ & CubeMap::Flag::VarianceShadowMapTexture
? vsmAttachment
: Mn::GL::Framebuffer::DrawAttachment::None)}});
: Mn::GL::Framebuffer::DrawAttachment::None)}});
}

Mn::GL::CubeMapTexture& CubeMap::getTexture(TextureType type) {
Expand Down Expand Up @@ -448,11 +399,6 @@ bool CubeMap::saveTexture(TextureType type,
// TODO: save object Id texture
break;
*/
/*
case CubeMap::TextureType::VarianceShadowMap:
// TODO: save vsm texture
break;
*/
case CubeMap::TextureType::Count:
break;

Expand Down Expand Up @@ -542,11 +488,6 @@ void CubeMap::loadTexture(TextureType type,
CORRADE_INTERNAL_ASSERT_UNREACHABLE();
break;

case TextureType::VarianceShadowMap:
// TODO: vsm texture
CORRADE_INTERNAL_ASSERT_UNREACHABLE();
break;

case TextureType::Count:
CORRADE_INTERNAL_ASSERT_UNREACHABLE();
break;
Expand All @@ -558,13 +499,8 @@ void CubeMap::loadTexture(TextureType type,
}

void CubeMap::generateMipmap(TextureType type) {
CORRADE_INTERNAL_ASSERT(type == TextureType::Color ||
type == TextureType::VarianceShadowMap);
if (type == TextureType::Color) {
CORRADE_INTERNAL_ASSERT(flags_ & Flag::ColorTexture);
} else if (type == TextureType::VarianceShadowMap) {
CORRADE_INTERNAL_ASSERT(flags_ & Flag::VarianceShadowMapTexture);
}
CORRADE_INTERNAL_ASSERT(type == TextureType::Color);
CORRADE_INTERNAL_ASSERT(flags_ & Flag::ColorTexture);
if ((flags_ & Flag::AutoBuildMipmap) ||
(flags_ & Flag::ManuallyBuildMipmap)) {
Mn::GL::CubeMapTexture& tex = texture(type);
Expand Down Expand Up @@ -596,10 +532,6 @@ void CubeMap::copySubImage(unsigned int cubeSideIndex,
frameBuffer_[cubeSideIndex].mapForRead(rgbaAttachment);
break;

case TextureType::VarianceShadowMap:
frameBuffer_[cubeSideIndex].mapForRead(vsmAttachment);
break;

case TextureType::ObjectId:
frameBuffer_[cubeSideIndex].mapForRead(objectIdAttachment);
break;
Expand Down Expand Up @@ -667,8 +599,6 @@ void CubeMap::renderToTexture(CubeMapCamera& camera,
if (flags_ & Flag::AutoBuildMipmap) {
if (flags_ & Flag::ColorTexture) {
texture(TextureType::Color).generateMipmap();
} else if (flags_ & Flag::VarianceShadowMapTexture) {
texture(TextureType::VarianceShadowMap).generateMipmap();
}
}
}
Expand Down
14 changes: 0 additions & 14 deletions src/esp/gfx/CubeMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ class CubeMap {
*/
ObjectId,

/**
* Variance shadow map texture
*/
VarianceShadowMap,

// TODO: HDR color

Count,
Expand All @@ -67,11 +62,6 @@ class CubeMap {
*/
ObjectIdOutput = Magnum::Shaders::GenericGL3D::ObjectIdOutput,

/**
* Variance shadow map shader output
* Expects a two-component floating point (32F) attachment
*/
VarianceShadowMapOutput = ObjectIdOutput + 1u,
};

enum class Flag : Magnum::UnsignedShort {
Expand Down Expand Up @@ -105,10 +95,6 @@ class CubeMap {
*/
ManuallyBuildMipmap = 1 << 4,

/**
* create variance shadow map
*/
VarianceShadowMapTexture = 1 << 5,
};

/**
Expand Down
3 changes: 1 addition & 2 deletions src/esp/gfx/Drawable.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ enum class DrawableType : uint8_t {
None = 0,
Generic = 1,
Pbr = 2,
MeshVisualizer = 3,
VarianceShadowMap = 4,
MeshVisualizer = 3
};

/**
Expand Down
32 changes: 0 additions & 32 deletions src/esp/gfx/PbrDrawable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,25 +481,6 @@ void PbrDrawable::draw(const Mn::Matrix4& transformationMatrix,
pbrIbl_->getPrefilteredMap().getMipmapLevels());
}

if (flags_ >= PbrShader::Flag::ShadowsVSM) {
CORRADE_INTERNAL_ASSERT(shadowMapManger_ && shadowMapKeys_);
CORRADE_ASSERT(shadowMapKeys_->size() <= 3,
"PbrDrawable::draw: the number of shadow maps exceeds the "
"maximum (current it is 3).", );
for (size_t iShadow = 0; iShadow < shadowMapKeys_->size(); ++iShadow) {
Mn::Resource<CubeMap> shadowMap =
(*shadowMapManger_).get<CubeMap>((*shadowMapKeys_)[iShadow]);

CORRADE_INTERNAL_ASSERT(shadowMap);

if (flags_ >= PbrShader::Flag::ShadowsVSM) {
shader_->bindPointShadowMap(
iShadow,
shadowMap->getTexture(CubeMap::TextureType::VarianceShadowMap));
}
}
}

shader_->draw(getMesh());

// Reset winding direction
Expand Down Expand Up @@ -587,18 +568,5 @@ PbrDrawable& PbrDrawable::updateShaderLightDirectionParameters(
return *this;
}

void PbrDrawable::setShadowData(ShadowMapManager& manager,
ShadowMapKeys& keys,
PbrShader::Flag shadowFlag) {
// sanity check first
CORRADE_ASSERT(shadowFlag == PbrShader::Flag::ShadowsVSM,
"PbrDrawable::setShadowData(): the shadow flag can only be "
"ShadowsVSM.", );

shadowMapManger_ = &manager;
shadowMapKeys_ = &keys;
flags_ |= shadowFlag;
}

} // namespace gfx
} // namespace esp
18 changes: 3 additions & 15 deletions src/esp/gfx/PbrDrawable.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "esp/gfx/PbrImageBasedLighting.h"
#include "esp/gfx/PbrShader.h"
#include "esp/gfx/ShaderManager.h"
#include "esp/gfx/ShadowMapManager.h"
namespace esp {
namespace gfx {

Expand Down Expand Up @@ -217,6 +216,9 @@ class PbrDrawable : public Drawable {
} volumeLayer;
};

/// @brief Key template for entry in shader map
static constexpr const char* SHADER_KEY_TEMPLATE = "PBR-lights={}-flags={}";

/**
* @brief Constructor, to create a PbrDrawable for the given object using
* shader and mesh. Adds drawable to given group and uses provided texture,
Expand All @@ -237,18 +239,6 @@ class PbrDrawable : public Drawable {
*/
void setLightSetup(const Mn::ResourceKey& lightSetupKey) override;

/**
* @brief Set the shadow map info
* @param[in] manager, stores the shadow maps
* @param[in] keys, keys to retrieve the shadow maps
* @param[in] shadowFlag, can only be either ShadowsPCF or ShadowsVSM
*/
void setShadowData(ShadowMapManager& manager,
ShadowMapKeys& keys,
PbrShader::Flag shadowFlag);

static constexpr const char* SHADER_KEY_TEMPLATE = "PBR-lights={}-flags={}";

private:
/**
* @brief Internal implementation of material setting, so that it can be
Expand Down Expand Up @@ -322,8 +312,6 @@ class PbrDrawable : public Drawable {
* Material to use to render this PBR drawable
*/
Mn::Resource<Mn::Trade::MaterialData, Mn::Trade::MaterialData> materialData_;
ShadowMapManager* shadowMapManger_ = nullptr;
ShadowMapKeys* shadowMapKeys_ = nullptr;
};

} // namespace gfx
Expand Down
Loading