Skip to content

Commit 68cee6c

Browse files
committed
Updates based on Toms notes.
1 parent 7042d03 commit 68cee6c

File tree

3 files changed

+45
-47
lines changed

3 files changed

+45
-47
lines changed

pxr/imaging/hdSt/materialXFilter.cpp

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -637,43 +637,36 @@ _GetGlTFSurfaceMaterialTag(HdMaterialNode2 const& terminal)
637637
static const mx::TypeDesc
638638
_GetMxTypeDescription(std::string const& typeName)
639639
{
640-
#if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION==38
641-
// Add whatever is necessary for current codebase:
642-
static const auto _typeLibrary =
643-
std::map<std::string, const mx::TypeDesc*>{
644-
{"float", mx::Type::FLOAT},
645-
{"color3", mx::Type::COLOR3},
646-
{"color4", mx::Type::COLOR4},
647-
{"vector2", mx::Type::VECTOR2},
648-
{"vector3", mx::Type::VECTOR3},
649-
{"vector4", mx::Type::VECTOR4},
650-
{"surfaceshader", mx::Type::SURFACESHADER}
651-
};
652-
653-
const auto typeDescIt = _typeLibrary.find(typeName);
654-
if (typeDescIt != _typeLibrary.end()) {
655-
return *(typeDescIt->second);
656-
}
657-
658-
return *mx::Type::NONE;
640+
#if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION <= 38
641+
using MxTypeDesc = const mx::TypeDesc*;
659642
#else
643+
using MxTypeDesc = const mx::TypeDesc;
644+
#endif
645+
660646
// Add whatever is necessary for current codebase:
661647
static const auto _typeLibrary =
662-
std::map<std::string, const mx::TypeDesc>{
648+
std::map<std::string, MxTypeDesc>{
663649
{"float", mx::Type::FLOAT},
664650
{"color3", mx::Type::COLOR3},
665651
{"color4", mx::Type::COLOR4},
666652
{"vector2", mx::Type::VECTOR2},
667653
{"vector3", mx::Type::VECTOR3},
668654
{"vector4", mx::Type::VECTOR4},
669655
{"surfaceshader", mx::Type::SURFACESHADER}
670-
};
656+
};
671657

672658
const auto typeDescIt = _typeLibrary.find(typeName);
673659
if (typeDescIt != _typeLibrary.end()) {
674-
return typeDescIt->second;
660+
#if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION <= 38
661+
return *typeDescIt->second;
662+
#else
663+
return typeDescIt->second;
664+
#endif
675665
}
676666

667+
#if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION <= 38
668+
return *mx::Type::NONE;
669+
#else
677670
return mx::Type::NONE;
678671
#endif
679672
}

pxr/imaging/hdSt/materialXShaderGen.cpp

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,7 @@ HdStMaterialXShaderGen<Base>::_EmitGlslfxHeader(mx::ShaderStage& mxStage) const
161161
TF_WARN("MaterialX geomprop '%s' has unknown type '%s'",
162162
primvarPair.first.c_str(), primvarPair.second.c_str());
163163
}
164-
165-
#if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION==38
166-
const std::string type = (!mxTypeIsNone(mxType)) ? Base::_syntax->getTypeName(&mxType) : "vec2";
167-
#else
168-
const std::string type = (!mxTypeIsNone(mxType)) ? Base::_syntax->getTypeName(mxType) : "vec2";
169-
#endif
164+
const std::string type = mxGetTypeString(mxType, Base::_syntax);
170165

171166
line += " \"" + primvarPair.first + "\": {\n";
172167
line += " \"type\": \"" + type + "\"\n";
@@ -289,7 +284,7 @@ HdStMaterialXShaderGen<Base>::_EmitMxSurfaceShader(
289284
if (outputConnection) {
290285

291286
std::string finalOutput = outputConnection->getVariable();
292-
#if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION==38
287+
#if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION <= 38
293288
// channels feature removed in MaterialX 1.39
294289
const std::string& channels = outputSocket->getChannels();
295290
if (!channels.empty()) {
@@ -1358,49 +1353,58 @@ HdStMaterialXShaderGenMsl::_EmitMxFunctions(
13581353

13591354
bool mxTypeIsNone(mx::TypeDesc typeDesc)
13601355
{
1361-
#if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION==38
1362-
return typeDesc == *mx::Type::NONE;
1356+
#if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION <= 38
1357+
return typeDesc == *mx::Type::NONE;
13631358
#else
1364-
return typeDesc == mx::Type::NONE;
1359+
return typeDesc == mx::Type::NONE;
13651360
#endif
13661361
}
13671362

13681363
bool mxTypeIsSurfaceShader(mx::TypeDesc typeDesc)
13691364
{
1370-
#if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION==38
1371-
return typeDesc == *mx::Type::SURFACESHADER;
1365+
#if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION <= 38
1366+
return typeDesc == *mx::Type::SURFACESHADER;
13721367
#else
1373-
return typeDesc == mx::Type::SURFACESHADER;
1368+
return typeDesc == mx::Type::SURFACESHADER;
13741369
#endif
13751370
}
13761371

13771372
bool mxTypeDescIsFilename(const mx::TypeDesc typeDesc)
13781373
{
1379-
#if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION==38
1380-
return typeDesc == *mx::Type::FILENAME;
1374+
#if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION <= 38
1375+
return typeDesc == *mx::Type::FILENAME;
13811376
#else
1382-
return typeDesc == mx::Type::FILENAME;
1377+
return typeDesc == mx::Type::FILENAME;
13831378
#endif
13841379
}
13851380

13861381
mx::TypeDesc getMxTypeDesc(const std::string& typeName)
13871382
{
1388-
#if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION==38
1389-
const mx::TypeDesc* mxType = mx::TypeDesc::get(typeName);
1390-
if (mxType)
1391-
return *mxType;
1392-
return *mx::Type::NONE;
1383+
#if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION <= 38
1384+
const mx::TypeDesc* mxType = mx::TypeDesc::get(typeName);
1385+
if (mxType)
1386+
return *mxType;
1387+
return *mx::Type::NONE;
13931388
#else
1394-
return mx::TypeDesc::get(typeName);
1389+
return mx::TypeDesc::get(typeName);
13951390
#endif
13961391
}
13971392

13981393
const MaterialX::TypeDesc getMxTypeDesc(const mx::ShaderPort* port)
13991394
{
1400-
#if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION==38
1401-
return port->getType() ? *(port->getType()) : *mx::Type::NONE;
1395+
#if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION <= 38
1396+
return port->getType() ? *(port->getType()) : *mx::Type::NONE;
1397+
#else
1398+
return port->getType();
1399+
#endif
1400+
}
1401+
1402+
const std::string mxGetTypeString(const mx::TypeDesc mxType, mx::SyntaxPtr syntax)
1403+
{
1404+
#if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION <= 38
1405+
return (!mxTypeIsNone(mxType)) ? syntax->getTypeName(&mxType) : "vec2";
14021406
#else
1403-
return port->getType();
1407+
return (!mxTypeIsNone(mxType)) ? syntax->getTypeName(mxType) : "vec2";
14041408
#endif
14051409
}
14061410

pxr/imaging/hdSt/materialXShaderGen.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ bool mxTypeIsSurfaceShader(MaterialX::TypeDesc typeDesc);
199199
bool mxTypeDescIsFilename(const MaterialX::TypeDesc typeDesc);
200200
MaterialX::TypeDesc getMxTypeDesc(const std::string& typeName);
201201
const MaterialX::TypeDesc getMxTypeDesc(const MaterialX::ShaderPort* port);
202+
const std::string mxGetTypeString(const MaterialX::TypeDesc mxType, MaterialX::SyntaxPtr syntax);
202203

203204
PXR_NAMESPACE_CLOSE_SCOPE
204205

0 commit comments

Comments
 (0)