Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync AOV shaders referenced from the Render Settings in the delegate #1065

Merged
merged 10 commits into from
Mar 11, 2022
Next Next commit
Support AOV shaders on the render settings in the procedural (#968)
  • Loading branch information
Julian Hodgson committed Mar 9, 2022
commit 034b5c597a9d6b53c10dcdc5337e4498a939096c
43 changes: 43 additions & 0 deletions translator/reader/read_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ TF_DEFINE_PRIVATE_TOKENS(_tokens,
((aovSettingName,"driver:parameters:aov:name"))
((aovGlobalAtmosphere, "arnold:global:atmosphere"))
((aovGlobalBackground, "arnold:global:background"))
((aovGlobalAovs, "arnold:global:aov_shaders"))
((_float, "float"))
((_int, "int"))
(ArnoldNodeGraph)
Expand Down Expand Up @@ -133,6 +134,47 @@ static inline void UsdArnoldNodeGraphConnection(AtNode *options, const UsdAttrib
}
}

// Read eventual connections to a ArnoldNodeGraph primitive for the aov_shader shader array connections
static inline void UsdArnoldNodeGraphAovConnection(AtNode *options, const UsdAttribute &attr, const std::string &attrBase, UsdArnoldReaderContext &context)
{
const TimeSettings &time = context.GetTimeSettings();
VtValue value;
if (attr && attr.Get(&value, time.frame)) {
// RenderSettings have a string attribute, referencing a prim in the stage
std::string valStr = VtValueGetString(value);
if (!valStr.empty()) {
SdfPath path(valStr);
// We check if there is a primitive at the path of this string
UsdPrim ngPrim = context.GetReader()->GetStage()->GetPrimAtPath(SdfPath(valStr));
// We verify if the primitive is indeed a ArnoldNodeGraph
if (ngPrim && ngPrim.GetTypeName() == _tokens->ArnoldNodeGraph) {
// We can use a UsdShadeShader schema in order to read connections
UsdShadeShader ngShader(ngPrim);
for (unsigned i=1;; i++) {
// the output terminal name will be aov_shader{1,...,n} as a contiguous array
TfToken outputName(attrBase + std::to_string(i));
UsdShadeOutput outputAttr = ngShader.GetOutput(outputName);
if (!outputAttr)
break;
SdfPathVector sourcePaths;
// Check which shader is connected to this output
if (outputAttr.HasConnectedSource() && outputAttr.GetRawConnectedSourcePaths(&sourcePaths) &&
!sourcePaths.empty()) {
SdfPath outPath(sourcePaths[0].GetPrimPath());
UsdPrim outPrim = context.GetReader()->GetStage()->GetPrimAtPath(outPath);
if (outPrim) {
// we connect to aov_shaders{0,...,n-1} parameters i.e. 0 indexed
std::string outputElement = attrBase + std::to_string(i-1);
context.AddConnection(options, outputElement, outPath.GetText(),
UsdArnoldReader::CONNECTION_PTR);
}
}
}
}
}
}
}

void UsdArnoldReadRenderSettings::Read(const UsdPrim &prim, UsdArnoldReaderContext &context)
{
// No need to create any node in arnold, since the options node is automatically created
Expand Down Expand Up @@ -374,4 +416,5 @@ void UsdArnoldReadRenderSettings::Read(const UsdPrim &prim, UsdArnoldReaderConte
// Read eventual connections to a node graph
UsdArnoldNodeGraphConnection(options, prim.GetAttribute(_tokens->aovGlobalAtmosphere), "atmosphere", context);
UsdArnoldNodeGraphConnection(options, prim.GetAttribute(_tokens->aovGlobalBackground), "background", context);
UsdArnoldNodeGraphAovConnection(options, prim.GetAttribute(_tokens->aovGlobalBackground), "aov_shaders", context);
}