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

Function GetNodeFallbackValue

Hydrogent/src/HnMaterialNetwork.cpp:248–295  ·  view source on GitHub ↗

Get the fallback value for material node, first consulting Sdr to find whether the node has an input for the fallback value and then checking whether the output named outputName is known to Sdr and using either the default value specified by the SdrShaderProperty or using a default constructed value of the type specified by SdrShaderProperty.

Source from the content-addressed store, hash-verified

246// the default value specified by the SdrShaderProperty or using a
247// default constructed value of the type specified by SdrShaderProperty.
248pxr::VtValue GetNodeFallbackValue(const pxr::HdMaterialNode2& Node,
249 const pxr::TfToken& OutputName)
250{
251 pxr::SdrRegistry& ShaderReg = pxr::SdrRegistry::GetInstance();
252
253 // Find the corresponding Sdr node.
254 const pxr::SdrShaderNodeConstPtr SdrNode =
255 ShaderReg.GetShaderNodeByIdentifierAndType(Node.nodeTypeId, pxr::HioGlslfxTokens->glslfx);
256 if (!SdrNode)
257 {
258 return pxr::VtValue{};
259 }
260
261
262 // HACK: Incorrect usage of GetDefaultInput to
263 // determine what the fallback value is.
264 // GetDefaultInput is meant to be used for 'disabled'
265 // node where the 'default input' becomes the value
266 // pass-through in the network. But there is no other
267 // mechanism currently to deal with fallback values.
268 if (const pxr::SdrShaderPropertyConstPtr& DefaultInput = SdrNode->GetDefaultInput())
269 {
270 const pxr::TfToken& DefInputName = DefaultInput->GetName();
271 auto const& def_param_it = Node.parameters.find(DefInputName);
272 if (def_param_it != Node.parameters.end())
273 {
274 return def_param_it->second;
275 }
276 }
277
278 // Sdr supports specifying default values for outputs so if we
279 // did not use the GetDefaultInput hack above, we fallback to
280 // using this DefaultOutput value.
281 if (const pxr::SdrShaderPropertyConstPtr& Output = SdrNode->GetShaderOutput(OutputName))
282 {
283 const pxr::VtValue Out = Output->GetDefaultValue();
284 if (!Out.IsEmpty())
285 {
286 return Out;
287 }
288
289 // If no default value was registered with Sdr for
290 // the output, fallback to the type's default.
291 return Output->GetTypeAsSdfType().first.GetDefaultValue();
292 }
293
294 return pxr::VtValue{};
295}
296
297
298pxr::VtValue GetParamFallbackValue(const pxr::HdMaterialNetwork2& Network,

Callers 1

GetParamFallbackValueFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected