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

--Set default fallback material handling #2265

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
--initial commit; Make fallback material noticeable
--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 Feb 4, 2025
commit c9bb8a64e9e0b7a33c662cbbc80c2ac54e07d1d3
20 changes: 17 additions & 3 deletions src/esp/assets/ResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2140,7 +2140,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 @@ -2152,6 +2153,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 @@ -2252,9 +2255,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