Skip to content
Open
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
14 changes: 0 additions & 14 deletions source/MaterialXGraphEditor/RenderView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,6 @@ void applyModifiers(mx::DocumentPtr doc, const DocumentModifiers& modifiers)
}
}

// Remap unsupported texture coordinate indices.
for (mx::ElementPtr elem : doc->traverseTree())
{
mx::NodePtr node = elem->asA<mx::Node>();
if (node && node->getCategory() == "texcoord")
{
mx::InputPtr index = node->getInput("index");
mx::ValuePtr value = index ? index->getValue() : nullptr;
if (value && value->isA<int>() && value->asA<int>() != 0)
{
index->setValue(0);
}
}
}
}

void RenderView::setDocument(mx::DocumentPtr document)
Expand Down
29 changes: 17 additions & 12 deletions source/MaterialXRender/CgltfLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,16 @@ bool CgltfLoader::load(const FilePath& filePath, MeshList& meshList, bool texcoo
{
continue;
}
// Only load one stream of each type for now.
cgltf_int streamIndex = attribute->index;
if (streamIndex != 0)

bool isPositionStream = (attribute->type == cgltf_attribute_type_position);
bool isNormalStream = (attribute->type == cgltf_attribute_type_normal);
bool isTangentStream = (attribute->type == cgltf_attribute_type_tangent);
bool isColorStream = (attribute->type == cgltf_attribute_type_color);
bool isTexCoordStream = (attribute->type == cgltf_attribute_type_texcoord);

// Only positions, normals, and tangents use the primary glTF stream.
if ((isPositionStream || isNormalStream || isTangentStream) && streamIndex != 0)
{
continue;
}
Expand All @@ -288,12 +295,6 @@ bool CgltfLoader::load(const FilePath& filePath, MeshList& meshList, bool texcoo

MeshStreamPtr geomStream = nullptr;

bool isPositionStream = (attribute->type == cgltf_attribute_type_position);
bool isNormalStream = (attribute->type == cgltf_attribute_type_normal);
bool isTangentStream = (attribute->type == cgltf_attribute_type_tangent);
bool isColorStream = (attribute->type == cgltf_attribute_type_color);
bool isTexCoordStream = (attribute->type == cgltf_attribute_type_texcoord);

if (isPositionStream)
{
// Create position stream
Expand Down Expand Up @@ -328,14 +329,18 @@ bool CgltfLoader::load(const FilePath& filePath, MeshList& meshList, bool texcoo
}
else if (isTexCoordStream)
{
texcoordStream = MeshStream::create("i_" + MeshStream::TEXCOORD_ATTRIBUTE + "_0", MeshStream::TEXCOORD_ATTRIBUTE, 0);
mesh->addStream(texcoordStream);
auto tcStream = MeshStream::create("i_" + MeshStream::TEXCOORD_ATTRIBUTE + "_" + std::to_string(streamIndex), MeshStream::TEXCOORD_ATTRIBUTE, streamIndex);
mesh->addStream(tcStream);
if (vectorSize == 2)
{
texcoordStream->setStride(MeshStream::STRIDE_2D);
tcStream->setStride(MeshStream::STRIDE_2D);
desiredVectorSize = 2;
}
geomStream = texcoordStream;
geomStream = tcStream;
if (streamIndex == 0)
{
texcoordStream = tcStream;
}
}
else
{
Expand Down
10 changes: 9 additions & 1 deletion source/MaterialXRenderGlsl/GlslProgram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,15 @@ void GlslProgram::bindAttribute(const GlslProgram::InputMap& inputs, MeshPtr mes
MeshStreamPtr stream = mesh->getStream(input.first);
if (!stream)
{
throw ExceptionRenderError("Geometry buffer could not be retrieved for binding: " + input.first + ". Index: " + std::to_string(index));
// Fall back to the first texcoord stream when the mesh has fewer UV sets than the material.
if (input.first.find("i_texcoord_") != std::string::npos)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should use the existing constant HW::IN_TEXCOORD, rather than adding this hardcoded string? The same approach could be used in MSL and Slang as well.

{
stream = mesh->getStream(MeshStream::TEXCOORD_ATTRIBUTE, 0);
}
if (!stream)
{
throw ExceptionRenderError("Geometry buffer could not be retrieved for binding: " + input.first + ". Index: " + std::to_string(index));
}
}
MeshFloatBuffer& attributeData = stream->getData();
stride = stream->getStride();
Expand Down
5 changes: 5 additions & 0 deletions source/MaterialXRenderMsl/MslPipelineStateObject.mm
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,11 @@ int GetStrideOfMetalType(MTLDataType type)

unsigned int stride = 0;
MeshStreamPtr stream = mesh->getStream(input.first);
// Fall back to the first texcoord stream when the mesh has fewer UV sets than the material.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two updates to GLSL and MSL look great, but I believe we need a corresponding update for Slang as well, in SlangProgram.cpp.

if (!stream && input.first.find("i_texcoord_") != std::string::npos)
{
stream = mesh->getStream(MeshStream::TEXCOORD_ATTRIBUTE, 0);
}
if (!stream)
{
errors.push_back("Geometry buffer could not be retrieved for binding: " + input.first + ". Index: " + std::to_string(index));
Expand Down
14 changes: 0 additions & 14 deletions source/MaterialXView/Viewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,6 @@ void applyModifiers(mx::DocumentPtr doc, const DocumentModifiers& modifiers)
}
}

// Remap unsupported texture coordinate indices.
for (mx::ElementPtr elem : doc->traverseTree())
{
mx::NodePtr node = elem->asA<mx::Node>();
if (node && node->getCategory() == "texcoord")
{
mx::InputPtr index = node->getInput("index");
mx::ValuePtr value = index ? index->getValue() : nullptr;
if (value && value->isA<int>() && value->asA<int>() != 0)
{
index->setValue(0);
}
}
}
}

} // anonymous namespace
Expand Down
Loading