Skip to content

Commit

Permalink
--initial commit; Make fallback material noticeable
Browse files Browse the repository at this point in the history
--make material color magenta
--add flag that this material is a fallback for an object lacking any other materials
--remove default phong material function; specifying phong shader to use should be sufficient for depth sensor.
  • Loading branch information
jturner65 committed Nov 27, 2023
1 parent 125be12 commit 7aa576d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
41 changes: 22 additions & 19 deletions src/esp/assets/ResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2162,7 +2162,7 @@ Mn::Trade::MaterialData createUniversalMaterial(
Mn::Trade::MaterialData newMaterialData{flags, std::move(newAttributes)};

return newMaterialData;
} // namespace
} // createUniversalMaterial

} // namespace

Expand All @@ -2181,23 +2181,13 @@ Mn::Trade::MaterialData ResourceManager::buildDefaultMaterial() {
return materialData;
} // ResourceManager::buildDefaultMaterial

// Specifically for building materials that relied on old defaults
Mn::Trade::MaterialData ResourceManager::buildDefaultPhongMaterial() {
Mn::Trade::MaterialData materialData{
Mn::Trade::MaterialType::Phong,
{{Mn::Trade::MaterialAttribute::AmbientColor, Mn::Color4{0.1}},
{Mn::Trade::MaterialAttribute::DiffuseColor, Mn::Color4{0.7 * 0.175}},
{Mn::Trade::MaterialAttribute::SpecularColor, Mn::Color4{0.2 * 0.175}},
{Mn::Trade::MaterialAttribute::Shininess, 80.0f}}};
return materialData;
} // ResourceManager::buildDefaultPhongMaterial

Mn::Trade::MaterialData ResourceManager::setMaterialDefaultUserAttributes(
const Mn::Trade::MaterialData& material,
ObjectInstanceShaderType shaderTypeToUse,
bool hasVertObjID,
bool hasTxtrObjID,
int txtrIdx) const {
int txtrIdx,
bool isFallback) const {
// New material's attributes
Cr::Containers::Array<Mn::Trade::MaterialAttributeData> newAttributes;
arrayAppend(newAttributes, Cr::InPlaceInit, "hasPerVertexObjectId",
Expand All @@ -2209,6 +2199,8 @@ Mn::Trade::MaterialData ResourceManager::setMaterialDefaultUserAttributes(
arrayAppend(newAttributes, Cr::InPlaceInit, "shaderTypeToUse",
static_cast<int>(shaderTypeToUse));

arrayAppend(newAttributes, Cr::InPlaceInit, "isFallbackMaterial", isFallback);

Cr::Containers::Optional<Mn::Trade::MaterialData> finalMaterial =
Mn::MaterialTools::merge(
material, Mn::Trade::MaterialData{{}, std::move(newAttributes), {}});
Expand Down Expand Up @@ -2308,17 +2300,28 @@ void ResourceManager::initDefaultMaterials() {
std::move(vertIdMaterialData));

// Build default material for fallback material
// TODO: Skinning only works with Phong.
Mn::Trade::MaterialData fallbackMaterial = buildDefaultMaterial();
// Make fallback magenta so visibly obvious
fallbackMaterial.mutableAttribute<Mn::Color4>(
Mn::Trade::MaterialAttribute::AmbientColor) =
Mn::Color4{1.0f, 0.0f, 1.0f, 1.0f};
fallbackMaterial.mutableAttribute<Mn::Color4>(
Mn::Trade::MaterialAttribute::DiffuseColor) =
Mn::Color4{1.0f, 0.0f, 1.0f, 1.0f};
fallbackMaterial.mutableAttribute<Mn::Color4>(
Mn::Trade::MaterialAttribute::SpecularColor) =
Mn::Color4{1.0f, 0.0f, 1.0f, 1.0f};
// TODO: Currently skinning only works with Phong.
// The default material is loaded when the simulation is only using
// depth sensors. We set the fallback as Phong to avoid breaking
// skinning with depth sensors.
auto fallBackMaterial = buildDefaultPhongMaterial();
// Set expected user-defined attributes
fallBackMaterial = setMaterialDefaultUserAttributes(
fallBackMaterial, ObjectInstanceShaderType::Phong);
// Set expected user-defined attributes - specify Phong shader to use
fallbackMaterial = setMaterialDefaultUserAttributes(
fallbackMaterial, ObjectInstanceShaderType::Phong, false, false, -1,
true);
// Add to shaderManager as fallback material
shaderManager_.setFallback<Mn::Trade::MaterialData>(
std::move(fallBackMaterial));
std::move(fallbackMaterial));
} // ResourceManager::initDefaultMaterials

void ResourceManager::loadMaterials(Importer& importer,
Expand Down
10 changes: 4 additions & 6 deletions src/esp/assets/ResourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -721,11 +721,6 @@ class ResourceManager {
*/
Mn::Trade::MaterialData buildDefaultMaterial();

/**
* @brief Build a default Phong material.
*/
Mn::Trade::MaterialData buildDefaultPhongMaterial();

/**
* @brief Define and set user-defined attributes for the passed
* @ref Magnum::Trade::MaterialData.
Expand All @@ -739,14 +734,17 @@ class ResourceManager {
* ids for semantics.
* @param txtrIdx The absolute index in the @ref textures_ store for the semantic
* annotation texture.
* @param isFallback This material is default fallback material for missing
* materials.
* @return the updated material
*/
Mn::Trade::MaterialData setMaterialDefaultUserAttributes(
const Mn::Trade::MaterialData& material,
ObjectInstanceShaderType shaderTypeToUse,
bool hasVertObjID = false,
bool hasTxtrObjID = false,
int txtrIdx = -1) const;
int txtrIdx = -1,
bool isFallback = false) const;

/**
* @brief Configure the importerManager_ GL Extensions appropriately based on
Expand Down

0 comments on commit 7aa576d

Please sign in to comment.