| 930 | } |
| 931 | |
| 932 | void HnMaterialNetwork::AddTextureParam(const pxr::HdMaterialNetwork2& Network, |
| 933 | const pxr::HdMaterialNode2& Node, |
| 934 | const pxr::HdMaterialNode2& DownstreamNode, // needed to determine def value |
| 935 | const pxr::SdfPath& NodePath, |
| 936 | const pxr::TfToken& OutputName, |
| 937 | const pxr::TfToken& ParamName, |
| 938 | pxr::SdfPathSet& VisitedNodes) |
| 939 | { |
| 940 | // Make sure to add output name as the same texture may be used multiple times |
| 941 | // with different swizzles. For example, Metallic-Roughness.g, Metallic-Roughness.b. |
| 942 | if (!VisitedNodes.emplace(NodePath.AppendProperty(OutputName)).second) |
| 943 | return; |
| 944 | |
| 945 | pxr::SdrRegistry& ShaderReg = pxr::SdrRegistry::GetInstance(); |
| 946 | pxr::SdrShaderNodeConstPtr SdrNode = |
| 947 | ShaderReg.GetShaderNodeByIdentifier(Node.nodeTypeId, {pxr::HioGlslfxTokens->glslfx, HnMaterialPrivateTokens->mtlx}); |
| 948 | |
| 949 | HnMaterialParameter TexParam{HnMaterialParameter::ParamType::Texture, ParamName}; |
| 950 | |
| 951 | // Get swizzle metadata if possible |
| 952 | if (pxr::SdrShaderPropertyConstPtr SdrProperty = SdrNode->GetShaderOutput(OutputName)) |
| 953 | { |
| 954 | const pxr::NdrTokenMap& PropMetadata = SdrProperty->GetMetadata(); |
| 955 | |
| 956 | const auto& it = PropMetadata.find(HnSdrMetadataTokens->swizzle); |
| 957 | if (it != PropMetadata.end()) |
| 958 | { |
| 959 | TexParam.Swizzle = SwizzleStringToComponentMapping(it->second); |
| 960 | } |
| 961 | } |
| 962 | |
| 963 | // Determine the texture type |
| 964 | TexParam.TextureType = pxr::HdTextureType::Uv; |
| 965 | if (SdrNode && SdrNode->GetMetadata().count(HnMaterialPrivateTokens->isPtex)) |
| 966 | { |
| 967 | LOG_ERROR_MESSAGE("PTex textures are not currently supported"); |
| 968 | TexParam.TextureType = pxr::HdTextureType::Ptex; |
| 969 | } |
| 970 | |
| 971 | // Determine if texture should be pre-multiplied on CPU |
| 972 | // Currently, this will only happen if the texture param is called |
| 973 | // "diffuseColor" and if there is another param "opacity" connected to the |
| 974 | // same texture node via output "a", as long as the material tag is not |
| 975 | // "masked" |
| 976 | if (ParamName == HnMaterialPrivateTokens->diffuseColor && |
| 977 | m_Tag != HnMaterialTagTokens->masked) |
| 978 | { |
| 979 | auto const& opacity_conn_it = DownstreamNode.inputConnections.find(HnMaterialPrivateTokens->opacity); |
| 980 | if (opacity_conn_it != DownstreamNode.inputConnections.end()) |
| 981 | { |
| 982 | const pxr::HdMaterialConnection2& Conn = opacity_conn_it->second.front(); |
| 983 | TexParam.IsPremultiplied = |
| 984 | (NodePath == Conn.upstreamNode) && |
| 985 | (Conn.upstreamOutputName == HnMaterialPrivateTokens->a); |
| 986 | } |
| 987 | } |
| 988 | |
| 989 |
nothing calls this directly
no test coverage detected