Skip to content

Commit 1033d49

Browse files
committed
Updates based on Toms notes.
1 parent ebec3ba commit 1033d49

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
@@ -163,12 +163,7 @@ HdStMaterialXShaderGen<Base>::_EmitGlslfxHeader(mx::ShaderStage& mxStage) const
163163
TF_WARN("MaterialX geomprop '%s' has unknown type '%s'",
164164
primvarPair.first.c_str(), primvarPair.second.c_str());
165165
}
166-
167-
#if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION==38
168-
const std::string type = (!mxTypeIsNone(mxType)) ? Base::_syntax->getTypeName(&mxType) : "vec2";
169-
#else
170-
const std::string type = (!mxTypeIsNone(mxType)) ? Base::_syntax->getTypeName(mxType) : "vec2";
171-
#endif
166+
const std::string type = mxGetTypeString(mxType, Base::_syntax);
172167

173168
line += " \"" + primvarPair.first + "\": {\n";
174169
line += " \"type\": \"" + type + "\"\n";
@@ -291,7 +286,7 @@ HdStMaterialXShaderGen<Base>::_EmitMxSurfaceShader(
291286
if (outputConnection) {
292287

293288
std::string finalOutput = outputConnection->getVariable();
294-
#if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION==38
289+
#if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION <= 38
295290
// channels feature removed in MaterialX 1.39
296291
const std::string& channels = outputSocket->getChannels();
297292
if (!channels.empty()) {
@@ -1360,49 +1355,58 @@ HdStMaterialXShaderGenMsl::_EmitMxFunctions(
13601355

13611356
bool mxTypeIsNone(mx::TypeDesc typeDesc)
13621357
{
1363-
#if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION==38
1364-
return typeDesc == *mx::Type::NONE;
1358+
#if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION <= 38
1359+
return typeDesc == *mx::Type::NONE;
13651360
#else
1366-
return typeDesc == mx::Type::NONE;
1361+
return typeDesc == mx::Type::NONE;
13671362
#endif
13681363
}
13691364

13701365
bool mxTypeIsSurfaceShader(mx::TypeDesc typeDesc)
13711366
{
1372-
#if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION==38
1373-
return typeDesc == *mx::Type::SURFACESHADER;
1367+
#if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION <= 38
1368+
return typeDesc == *mx::Type::SURFACESHADER;
13741369
#else
1375-
return typeDesc == mx::Type::SURFACESHADER;
1370+
return typeDesc == mx::Type::SURFACESHADER;
13761371
#endif
13771372
}
13781373

13791374
bool mxTypeDescIsFilename(const mx::TypeDesc typeDesc)
13801375
{
1381-
#if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION==38
1382-
return typeDesc == *mx::Type::FILENAME;
1376+
#if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION <= 38
1377+
return typeDesc == *mx::Type::FILENAME;
13831378
#else
1384-
return typeDesc == mx::Type::FILENAME;
1379+
return typeDesc == mx::Type::FILENAME;
13851380
#endif
13861381
}
13871382

13881383
mx::TypeDesc getMxTypeDesc(const std::string& typeName)
13891384
{
1390-
#if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION==38
1391-
const mx::TypeDesc* mxType = mx::TypeDesc::get(typeName);
1392-
if (mxType)
1393-
return *mxType;
1394-
return *mx::Type::NONE;
1385+
#if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION <= 38
1386+
const mx::TypeDesc* mxType = mx::TypeDesc::get(typeName);
1387+
if (mxType)
1388+
return *mxType;
1389+
return *mx::Type::NONE;
13951390
#else
1396-
return mx::TypeDesc::get(typeName);
1391+
return mx::TypeDesc::get(typeName);
13971392
#endif
13981393
}
13991394

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

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)