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
5 changes: 5 additions & 0 deletions render_delegate/node_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,11 @@ AtNode* HdArnoldNodeGraph::GetTerminal(const TfToken& terminalName) const
return _nodeGraph.GetTerminal(terminalName);
}

std::vector<AtNode*> HdArnoldNodeGraph::GetTerminals(const TfToken& terminalName) const
{
return _nodeGraph.GetTerminals(terminalName);
}

#ifdef USD_HAS_MATERIAL_NETWORK2
bool HdArnoldNodeGraph::ReadMaterialNetwork(const HdMaterialNetwork2& network)
{
Expand Down
20 changes: 20 additions & 0 deletions render_delegate/node_graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ class HdArnoldNodeGraph : public HdMaterial {
HDARNOLD_API
AtNode* GetTerminal(const TfToken& terminalName) const;

/// Returns a custom terminal.
///
/// @param terminalBase Name of the terminal to lookup.
/// @return Vector of pointers to the terminal, nullptr if not found.
HDARNOLD_API
std::vector<AtNode*> GetTerminals(const TfToken& terminalBase) const;

protected:
/// Utility struct to store translated nodes.
struct NodeData {
Expand Down Expand Up @@ -163,6 +170,19 @@ class HdArnoldNodeGraph : public HdMaterial {
return it == terminals.end() ? nullptr : it->second;
}

/// Returns a terminal of the nodegraph.
///
/// @param terminalName Name of the terminal.
/// @return Pointer to the terminal, nullptr if terminal does not exists.
std::vector<AtNode*> GetTerminals(const TfToken& terminalBase) const
{
std::vector<AtNode*> result;
for (auto& t: terminals)
if (t.first.GetString().rfind(terminalBase.GetString(), 0) == 0)
result.push_back(t.second);
return result;
}

/// Checks if the shader any of the terminals.
///
/// @param terminal Pointer to the Arnold node.
Expand Down
19 changes: 19 additions & 0 deletions render_delegate/render_delegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ const SupportedRenderSettings& _GetSupportedRenderSettings()
{str::t_osl_includepath, {"OSL include path.", config.osl_includepath}},
{str::t_background, {"Path to the background node graph.", std::string{}}},
{str::t_atmosphere, {"Path to the atmosphere node graph.", std::string{}}},
{str::t_aov_shaders, {"Path to the aov_shaders node graph.", std::string{}}},
};
return data;
}
Expand Down Expand Up @@ -366,6 +367,15 @@ AtNode* _GetNodeGraphTerminal(HdRenderIndex* renderIndex, const SdfPath& id, con
return nodeGraph == nullptr ? nullptr : nodeGraph->GetTerminal(terminal);
}

std::vector<AtNode*> _GetNodeGraphTerminals(HdRenderIndex* renderIndex, const SdfPath& id, const TfToken& terminalBase)
{
if (id.IsEmpty()) {
return std::vector<AtNode*>();
}
auto* nodeGraph = reinterpret_cast<const HdArnoldNodeGraph*>(renderIndex->GetSprim(HdPrimTypeTokens->material, id));
return nodeGraph == nullptr ? std::vector<AtNode*>() : nodeGraph->GetTerminals(terminalBase);
}

} // namespace

std::mutex HdArnoldRenderDelegate::_mutexResourceRegistry;
Expand Down Expand Up @@ -633,6 +643,8 @@ void HdArnoldRenderDelegate::_SetRenderSetting(const TfToken& _key, const VtValu
_CheckForSdfPathValue(value, [&](const SdfPath& p) { _background = p; });
} else if (key == str::t_atmosphere) {
_CheckForSdfPathValue(value, [&](const SdfPath& p) { _atmosphere = p; });
} else if (key == str::t_aov_shaders) {
_CheckForSdfPathValue(value, [&](const SdfPath& p) { _aov_shaders = p; });
} else {
auto* optionsEntry = AiNodeGetNodeEntry(_options);
// Sometimes the Render Delegate receives parameters that don't exist
Expand Down Expand Up @@ -801,6 +813,8 @@ VtValue HdArnoldRenderDelegate::GetRenderSetting(const TfToken& _key) const
return VtValue(_background.GetString());
} else if (key == str::t_atmosphere) {
return VtValue(_atmosphere.GetString());
} else if (key == str::t_aov_shaders) {
return VtValue(_aov_shaders.GetString());
}
const auto* nentry = AiNodeGetNodeEntry(_options);
const auto* pentry = AiNodeEntryLookUpParameter(nentry, AtString(key.GetText()));
Expand Down Expand Up @@ -1333,4 +1347,9 @@ AtNode* HdArnoldRenderDelegate::GetAtmosphere(HdRenderIndex* renderIndex)
return _GetNodeGraphTerminal(renderIndex, _atmosphere, str::t_atmosphere);
}

std::vector<AtNode*> HdArnoldRenderDelegate::GetAovShaders(HdRenderIndex* renderIndex)
{
return _GetNodeGraphTerminals(renderIndex, _aov_shaders, str::t_aov_shaders);
}

PXR_NAMESPACE_CLOSE_SCOPE
8 changes: 8 additions & 0 deletions render_delegate/render_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,13 @@ class HdArnoldRenderDelegate final : public HdRenderDelegate {
HDARNOLD_API
AtNode* GetAtmosphere(HdRenderIndex* renderIndex);

/// Get the aov shaders.
///
/// @param renderIndex Pointer to the Hydra render index.
/// @return Vector of Pointer to the aov shaders.
HDARNOLD_API
std::vector<AtNode*> GetAovShaders(HdRenderIndex* renderIndex);

private:
HdArnoldRenderDelegate(const HdArnoldRenderDelegate&) = delete;
HdArnoldRenderDelegate& operator=(const HdArnoldRenderDelegate&) = delete;
Expand Down Expand Up @@ -519,6 +526,7 @@ class HdArnoldRenderDelegate final : public HdRenderDelegate {
SdfPath _id; ///< Path of the Render Delegate.
SdfPath _background; ///< Path to the background shader.
SdfPath _atmosphere; ///< Path to the atmosphere shader.
SdfPath _aov_shaders; ///< Path to the aov shaders.
AtUniverse* _universe; ///< Universe used by the Render Delegate.
#ifdef ARNOLD_MULTIPLE_RENDER_SESSIONS
AtRenderSession* _renderSession; ///< Render session used by the Render Delegate.
Expand Down
13 changes: 11 additions & 2 deletions render_delegate/render_pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,14 @@ void HdArnoldRenderPass::_Execute(const HdRenderPassStateSharedPtr& renderPassSt
checkShader(_renderDelegate->GetBackground(GetRenderIndex()), str::background);
checkShader(_renderDelegate->GetAtmosphere(GetRenderIndex()), str::atmosphere);

// check if the user aov shaders have changed
auto aovShaders = _renderDelegate->GetAovShaders(GetRenderIndex());
bool updateAovs = false;
if (_aovShaders != aovShaders) {
_aovShaders = aovShaders;
updateAovs = true;
}

// We are checking if the current aov bindings match the ones we already created, if not,
// then rebuild the driver setup.
// If AOV bindings are empty, we are only setting up color and depth for basic opengl composition. This should
Expand Down Expand Up @@ -600,7 +608,7 @@ void HdArnoldRenderPass::_Execute(const HdRenderPassStateSharedPtr& renderPassSt
// We expect Hydra to resize the render buffers.
const auto& delegateRenderProducts = _renderDelegate->GetDelegateRenderProducts();
if (_RenderBuffersChanged(aovBindings) || (!delegateRenderProducts.empty() && _deepProducts.empty()) ||
_usingFallbackBuffers) {
_usingFallbackBuffers || updateAovs) {
_usingFallbackBuffers = false;
renderParam->Interrupt();
_ClearRenderBuffers();
Expand All @@ -612,7 +620,8 @@ void HdArnoldRenderPass::_Execute(const HdRenderPassStateSharedPtr& renderPassSt
std::vector<AtString> outputs;
outputs.reserve(numBindings);
std::vector<AtString> lightPathExpressions;
std::vector<AtNode*> aovShaders;
// first add the user aov_shaders
std::vector<AtNode*> aovShaders = _aovShaders;
// When creating the outputs array we follow this logic:
// - color -> RGBA RGBA for the beauty box filter by default
// - depth -> P VECTOR for remapping point to depth using the projection matrices closest filter by default
Expand Down
1 change: 1 addition & 0 deletions render_delegate/render_pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class HdArnoldRenderPass : public HdRenderPass {
HdArnoldRenderBuffer _fallbackPrimId; ///< Prim ID buffer if there are no aov bindings.
AtArray* _fallbackOutputs; ///< AtArray storing the fallback outputs definitions.
AtArray* _fallbackAovShaders; ///< AtArray storing the fallback AOV shaders.
std::vector<AtNode*> _aovShaders; ///< Pointer to list of user aov shaders

HdArnoldRenderDelegate* _renderDelegate; ///< Pointer to the Render Delegate.
AtNode* _camera = nullptr; ///< Pointer to the Arnold Camera.
Expand Down