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 4, 2024
1 parent 88221ad commit 764d87e
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 @@ -2138,7 +2138,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 @@ -2150,6 +2151,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 @@ -2250,9 +2253,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 764d87e

Please sign in to comment.