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

LOOKDEVX-3222 - Expose hardcoded texture paths #3902

Merged
merged 1 commit into from
Sep 18, 2024
Merged
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
10 changes: 10 additions & 0 deletions lib/mayaUsd/render/MaterialXGenOgsXml/OgsFragment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,14 @@ OgsFragment::OgsFragment(mx::ElementPtr element, GLSL_GENERATOR_WRAPPER&& glslGe
for (size_t i = 0; i < uniforms.size(); ++i) {
const mx::ShaderPort* const port = uniforms[i];
if (!port->getNode()) {
if (port->getType()->getSemantic() == mx::TypeDesc::SEMANTIC_FILENAME) {
// Might be an embedded texture. Retrieve the filename.
std::string textureName
= mx::OgsXmlGenerator::samplerToTextureName(port->getVariable());
if (!textureName.empty() && !port->getPath().empty()) {
_embeddedTextures[textureName] = port->getPath();
}
}
continue;
}
std::string path = port->getPath();
Expand Down Expand Up @@ -693,6 +701,8 @@ const std::string& OgsFragment::getLightRigSource() const { return _lightRigSour

const mx::StringMap& OgsFragment::getPathInputMap() const { return _pathInputMap; }

const mx::StringMap& OgsFragment::getEmbeddedTextureMap() const { return _embeddedTextures; }

bool OgsFragment::isElementAShader() const
{
mx::TypedElementPtr typeElement = _element ? _element->asA<mx::TypedElement>() : nullptr;
Expand Down
18 changes: 11 additions & 7 deletions lib/mayaUsd/render/MaterialXGenOgsXml/OgsFragment.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ class MAYAUSD_CORE_PUBLIC OgsFragment
/// Maps XML element paths of MaterialX inputs to their names in the generated shader.
const mx::StringMap& getPathInputMap() const;

/// Maps a generated shader texture input to its library path.
const mx::StringMap& getEmbeddedTextureMap() const;

/// Return whether the element to render represents a surface shader graph
/// as opposed to a texture graph.
bool isElementAShader() const;
Expand Down Expand Up @@ -105,13 +108,14 @@ class MAYAUSD_CORE_PUBLIC OgsFragment
template <typename GLSL_GENERATOR_WRAPPER>
OgsFragment(mx::ElementPtr, GLSL_GENERATOR_WRAPPER&&);

mx::ElementPtr _element; ///< The MaterialX element.
std::string _fragmentName; ///< An automatically generated fragment name.
std::string _fragmentSource; ///< The generated fragment source.
std::string _lightRigName; ///< An automatically generated light rig name.
std::string _lightRigSource; ///< The generated light rig for surface fragments.
mx::StringMap _pathInputMap; ///< Maps MaterialX element paths to fragment input names.
mx::ShaderPtr _glslShader; ///< The MaterialX-generated GLSL shader.
mx::ElementPtr _element; ///< The MaterialX element.
std::string _fragmentName; ///< An automatically generated fragment name.
std::string _fragmentSource; ///< The generated fragment source.
std::string _lightRigName; ///< An automatically generated light rig name.
std::string _lightRigSource; ///< The generated light rig for surface fragments.
mx::StringMap _pathInputMap; ///< Maps MaterialX element paths to fragment input names.
mx::StringMap _embeddedTextures; ///< Maps texture entry points to library paths.
mx::ShaderPtr _glslShader; ///< The MaterialX-generated GLSL shader.
};

} // namespace MaterialXMaya
Expand Down
5 changes: 5 additions & 0 deletions lib/mayaUsdAPI/render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ const MaterialX::StringMap& OgsFragment::getPathInputMap() const
return _imp->_ogsFragment.getPathInputMap();
}

const MaterialX::StringMap& OgsFragment::getEmbeddedTextureMap() const
{
return _imp->_ogsFragment.getEmbeddedTextureMap();
}

std::string OgsFragment::getMatrix4Name(const std::string& matrix3Name)
{
return _imp->_ogsFragment.getMatrix4Name(matrix3Name);
Expand Down
1 change: 1 addition & 0 deletions lib/mayaUsdAPI/render.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class MAYAUSD_API_PUBLIC OgsFragment
const std::string& getFragmentSource() const;
const std::string& getFragmentName() const;
const MaterialX::StringMap& getPathInputMap() const;
const MaterialX::StringMap& getEmbeddedTextureMap() const;
std::string getMatrix4Name(const std::string& matrix3Name);

private:
Expand Down
Loading