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 May 8, 2024
1 parent 7403422 commit 9acedd2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
20 changes: 17 additions & 3 deletions src/esp/assets/ResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2141,7 +2141,8 @@ Mn::Trade::MaterialData ResourceManager::setMaterialDefaultUserAttributes(
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 @@ -2153,6 +2154,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 @@ -2253,9 +2256,20 @@ void ResourceManager::initDefaultMaterials() {

// Build default material for fallback material
Mn::Trade::MaterialData fallbackMaterial = buildDefaultMaterial();
// Set expected user-defined attributes
// 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};
// Set expected user-defined attributes - specify Phong shader to use
fallbackMaterial = setMaterialDefaultUserAttributes(
fallbackMaterial, ObjectInstanceShaderType::Flat);
fallbackMaterial, ObjectInstanceShaderType::Phong, false, false, -1,
true);
// Add to shaderManager as fallback material
shaderManager_.setFallback<Mn::Trade::MaterialData>(
std::move(fallbackMaterial));
Expand Down
5 changes: 4 additions & 1 deletion src/esp/assets/ResourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -751,14 +751,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 9acedd2

Please sign in to comment.