@@ -159,8 +159,8 @@ _GetGlslfxForTerminal(
159159 }
160160}
161161
162- static HdMaterialNode2 const *
163- _GetTerminalNode (
162+ HdMaterialNode2 const *
163+ HdSt_GetTerminalNode (
164164 HdMaterialNetwork2 const & network,
165165 TfToken const & terminalName,
166166 SdfPath * terminalNodePath)
@@ -1100,57 +1100,85 @@ HdStMaterialNetwork::ProcessMaterialNetwork(
11001100{
11011101 HD_TRACE_FUNCTION ();
11021102
1103- _fragmentSource.clear ();
1104- _displacementSource.clear ();
1105- _materialMetadata.clear ();
1106- _materialParams.clear ();
1107- _textureDescriptors.clear ();
1108- _materialTag = HdStMaterialTagTokens->defaultMaterialTag ;
1103+ bool isVolume = false ;
1104+
1105+ auto filterTask = std::make_shared<HdSt_MaterialFilterTask>();
1106+ filterTask->hdNetwork =
1107+ HdConvertToHdMaterialNetwork2 (hdNetworkMap, &isVolume);
11091108
11101109 // The fragment source comes from the 'surface' network or the
11111110 // 'volume' network.
1112- bool isVolume = false ;
11131111 HdMaterialNetwork2 surfaceNetwork =
11141112 HdConvertToHdMaterialNetwork2 (hdNetworkMap, &isVolume);
11151113 const TfToken &terminalName = (isVolume) ? HdMaterialTerminalTokens->volume
11161114 : HdMaterialTerminalTokens->surface ;
11171115
1118- SdfPath surfTerminalPath;
1119- if (HdMaterialNode2 const * surfTerminal =
1120- _GetTerminalNode (surfaceNetwork, terminalName, &surfTerminalPath)) {
1116+ filterTask->terminalNode =
1117+ HdSt_GetTerminalNode (
1118+ filterTask->hdNetwork ,
1119+ terminalName,
1120+ &filterTask->terminalNodePath );
1121+
1122+ if (!filterTask->terminalNode ) {
1123+ return ;
1124+ }
1125+
1126+ ProcessFilterTask (materialId, filterTask, isVolume, resourceRegistry);
1127+ }
1128+
1129+ void
1130+ HdStMaterialNetwork::ProcessFilterTask (
1131+ SdfPath const & materialId,
1132+ HdSt_MaterialFilterTaskSharedPtr filterTask,
1133+ bool isVolume,
1134+ HdStResourceRegistry *resourceRegistry)
1135+ {
1136+ HD_TRACE_FUNCTION ();
1137+
1138+ _fragmentSource.clear ();
1139+ _displacementSource.clear ();
1140+ _materialMetadata.clear ();
1141+ _materialParams.clear ();
1142+ _textureDescriptors.clear ();
1143+
1144+ _materialTag = HdStMaterialTagTokens->defaultMaterialTag ;
1145+
1146+ if (!filterTask || !filterTask->terminalNode ) {
1147+ return ;
1148+ }
11211149
11221150#ifdef PXR_MATERIALX_SUPPORT_ENABLED
1123- if (!isVolume) {
1124- _materialXGfx = HdSt_ApplyMaterialXFilter (&surfaceNetwork, materialId,
1125- *surfTerminal, surfTerminalPath,
1126- &_materialParams, resourceRegistry);
1127- }
1151+ if (!isVolume) {
1152+ _materialXGfx = HdSt_ApplyMaterialXFilter (filterTask, materialId,
1153+ &_materialParams, resourceRegistry);
1154+ }
11281155#endif
1129- // Extract the glslfx and metadata for surface/volume.
1130- _GetGlslfxForTerminal (_surfaceGfx, &_surfaceGfxHash,
1131- surfTerminal->nodeTypeId , resourceRegistry);
1132- if (_surfaceGfx) {
1133-
1134- // If the glslfx file is not valid we skip parsing the network.
1135- // This produces no fragmentSource which means Storm's material
1136- // will use the fallback shader.
1137- if (_surfaceGfx->IsValid ()) {
1138-
1139- _fragmentSource = _surfaceGfx->GetSurfaceSource ();
1140- _volumeSource = _surfaceGfx->GetVolumeSource ();
1141-
1142- _materialMetadata = _surfaceGfx->GetMetadata ();
1143- _materialTag = _GetMaterialTag (_materialMetadata, *surfTerminal);
1144- _GatherMaterialParams (surfaceNetwork, *surfTerminal,
1145- &_materialParams, &_textureDescriptors,
1146- _materialTag);
1147-
1148- // OSL networks have a displacement network in hdNetworkMap
1149- // under terminal: HdMaterialTerminalTokens->displacement.
1150- // For Storm however we expect the displacement shader to be
1151- // provided via the surface glslfx / terminal.
1152- _displacementSource = _surfaceGfx->GetDisplacementSource ();
1153- }
1156+ // Extract the glslfx and metadata for surface/volume.
1157+ _GetGlslfxForTerminal (_surfaceGfx, &_surfaceGfxHash,
1158+ filterTask->terminalNode ->nodeTypeId , resourceRegistry);
1159+ if (_surfaceGfx) {
1160+
1161+ // If the glslfx file is not valid we skip parsing the network.
1162+ // This produces no fragmentSource which means Storm's material
1163+ // will use the fallback shader.
1164+ if (_surfaceGfx->IsValid ()) {
1165+ _fragmentSource = _surfaceGfx->GetSurfaceSource ();
1166+ _volumeSource = _surfaceGfx->GetVolumeSource ();
1167+
1168+ _materialMetadata = _surfaceGfx->GetMetadata ();
1169+
1170+ _materialTag = _GetMaterialTag (
1171+ _surfaceGfx->GetMetadata (), *filterTask->terminalNode );
1172+ _GatherMaterialParams (
1173+ filterTask->hdNetwork , *filterTask->terminalNode ,
1174+ &_materialParams, &_textureDescriptors,
1175+ _materialTag);
1176+
1177+ // OSL networks have a displacement network in hdNetworkMap
1178+ // under terminal: HdMaterialTerminalTokens->displacement.
1179+ // For Storm however we expect the displacement shader to be
1180+ // provided via the surface glslfx / terminal.
1181+ _displacementSource = _surfaceGfx->GetDisplacementSource ();
11541182 }
11551183 }
11561184}
0 commit comments