MCPcopy Create free account
hub / github.com/DiligentGraphics/DiligentFX / LoadParams

Method LoadParams

Hydrogent/src/HnMaterialNetwork.cpp:749–810  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

747}
748
749void HnMaterialNetwork::LoadParams(const pxr::HdMaterialNetwork2& Network,
750 const pxr::HdMaterialNode2& Node)
751{
752 // Hydrogent currently supports two material configurations.
753 // A custom glslfx file or a PreviewSurface material network.
754 // Either configuration consists of a terminal (Shader or PreviewSurface)
755 // with its input values authored or connected to a primvar, texture or
756 // volume node. The texture may have a primvar connected to provide UVs.
757 //
758 // The following code is made to process one of these two material configs
759 // exclusively. It cannot convert arbitrary material networks by
760 // generating the appropriate glsl code.
761
762 pxr::SdrRegistry& ShaderReg = pxr::SdrRegistry::GetInstance();
763
764 const pxr::SdrShaderNodeConstPtr SdrNode =
765 ShaderReg.GetShaderNodeByIdentifierAndType(Node.nodeTypeId, pxr::HioGlslfxTokens->glslfx);
766
767 if (SdrNode)
768 {
769 pxr::SdfPathSet VisitedNodes;
770 for (const TfToken& InputName : SdrNode->GetInputNames())
771 {
772 ProcessInputParameter(Network, Node, InputName, VisitedNodes);
773 }
774 }
775 else
776 {
777 LOG_WARNING_MESSAGE("Unrecognized node: ", Node.nodeTypeId.GetText());
778 }
779
780 // Set fallback values for the inputs on the terminal (excepting
781 // referenced sampler coords).
782 for (auto& Param : m_Parameters)
783 {
784 if (Param.Type != HnMaterialParameter::ParamType::AdditionalPrimvar &&
785 Param.FallbackValue.IsEmpty())
786 {
787 Param.FallbackValue = GetParamFallbackValue(Network, Node, Param.Name);
788 }
789 }
790
791 if (SdrNode)
792 {
793 // Create HnMaterialParameter for each primvar the terminal says it
794 // needs.
795 // Primvars come from 'attributes' in the glslfx and are separate from
796 // the input 'parameters'. We need to create a material param for them
797 // so that these primvars survive 'primvar filtering' that discards any
798 // unused primvars on the mesh.
799 // If the network lists additional primvars, we add those too.
800 pxr::NdrTokenVec Primvars = SdrNode->GetPrimvars();
801 Primvars.insert(Primvars.end(), Network.primvars.begin(), Network.primvars.end());
802 std::sort(Primvars.begin(), Primvars.end());
803 Primvars.erase(std::unique(Primvars.begin(), Primvars.end()), Primvars.end());
804
805 for (const TfToken& PrimvarName : Primvars)
806 {

Callers

nothing calls this directly

Calls 1

GetParamFallbackValueFunction · 0.85

Tested by

no test coverage detected