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

Function GetParamFallbackValue

Hydrogent/src/HnMaterialNetwork.cpp:298–375  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

296
297
298pxr::VtValue GetParamFallbackValue(const pxr::HdMaterialNetwork2& Network,
299 const pxr::HdMaterialNode2& Node,
300 const pxr::TfToken& ParamName)
301{
302 // The 'fallback value' will be the value of the material param if nothing
303 // is connected or what is connected is mis-configured. For example a
304 // missing texture file.
305
306 // Check if there are any connections to the terminal input.
307 {
308 const auto conn_it = Node.inputConnections.find(ParamName);
309 if (conn_it != Node.inputConnections.end())
310 {
311 if (!conn_it->second.empty())
312 {
313 const pxr::HdMaterialConnection2& Connection = conn_it->second.front();
314
315 const auto up_it = Network.nodes.find(Connection.upstreamNode);
316 if (up_it != Network.nodes.end())
317 {
318 const pxr::HdMaterialNode2& UpstreamNode = up_it->second;
319
320 const pxr::VtValue FallbackValue =
321 GetNodeFallbackValue(UpstreamNode, Connection.upstreamOutputName);
322 if (!FallbackValue.IsEmpty())
323 {
324 return FallbackValue;
325 }
326 }
327 }
328 }
329 }
330
331 // If there are no connections, there may be an authored value.
332 {
333 const auto param_it = Node.parameters.find(ParamName);
334 if (param_it != Node.parameters.end())
335 {
336 return param_it->second;
337 }
338 }
339
340 // If we had nothing connected, but we do have an Sdr node, we can use the
341 // DefaultValue for the input as specified in the Sdr schema.
342 // E.g. PreviewSurface is a terminal with an Sdr schema.
343 {
344 pxr::SdrRegistry& ShaderReg = pxr::SdrRegistry::GetInstance();
345
346 pxr::SdrShaderNodeConstPtr TerminalSdr =
347 ShaderReg.GetShaderNodeByIdentifierAndType(Node.nodeTypeId, pxr::HioGlslfxTokens->glslfx);
348
349 if (TerminalSdr)
350 {
351 if (const pxr::SdrShaderPropertyConstPtr& Input = TerminalSdr->GetShaderInput(ParamName))
352 {
353 pxr::VtValue Out = Input->GetDefaultValue();
354 // If no default value was registered with Sdr for
355 // the output, fallback to the type's default.

Callers 2

GetTransform2dParamFunction · 0.85
LoadParamsMethod · 0.85

Calls 1

GetNodeFallbackValueFunction · 0.85

Tested by

no test coverage detected