Skip to content

Commit

Permalink
Adding support for atmosphere and background shaders (#989)
Browse files Browse the repository at this point in the history
* Adding support for atmosphere and background shaders.
* Fixing typo and checking for the std::string contents before converting to SdfPath.

Fixes #873
  • Loading branch information
sirpalee authored Dec 29, 2021
1 parent 24331e8 commit 57f6a33
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
2 changes: 2 additions & 0 deletions common/constant_strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,11 @@ ASTR(aov_write_vector);
ASTR(aperture_size);
ASTR(append);
ASTR(arnold);
ASTR(atmosphere);
ASTR(attribute);
ASTR(auto_transparency_depth);
ASTR(autobump_visibility);
ASTR(background);
ASTR(barndoor);
ASTR(barndoor_bottom_edge);
ASTR(barndoor_bottom_left);
Expand Down
42 changes: 42 additions & 0 deletions render_delegate/render_delegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ const SupportedRenderSettings& _GetSupportedRenderSettings()
{str::t_plugin_searchpath, {"Plugin search path.", config.plugin_searchpath}},
{str::t_procedural_searchpath, {"Procedural search path.", config.procedural_searchpath}},
{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{}}},
};
return data;
}
Expand Down Expand Up @@ -336,12 +338,34 @@ void _CheckForFloatValue(const VtValue& value, F&& f)
}
}

template <typename F>
void _CheckForSdfPathValue(const VtValue& value, F&& f)
{
if (value.IsHolding<SdfPath>()) {
f(value.UncheckedGet<SdfPath>());
} else if (value.IsHolding<std::string>()) {
const auto s = value.UncheckedGet<std::string>();
if (!s.empty() && *s.begin() == '/') {
f(SdfPath{value.UncheckedGet<std::string>()});
}
}
}

void _RemoveArnoldGlobalPrefix(const TfToken& key, TfToken& key_new)
{
key_new =
TfStringStartsWith(key, _tokens->arnoldGlobal) ? TfToken{key.GetText() + _tokens->arnoldGlobal.size()} : key;
}

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

} // namespace

std::mutex HdArnoldRenderDelegate::_mutexResourceRegistry;
Expand Down Expand Up @@ -585,6 +609,10 @@ void HdArnoldRenderDelegate::_SetRenderSetting(const TfToken& _key, const VtValu
_CheckForBoolValue(value, [&](const bool b) { AiNodeSetBool(_options, str::ignore_motion_blur, b); });
} else if (key == str::t_houdiniFps) {
_CheckForFloatValue(value, [&](const float f) { _fps = f; });
} else if (key == str::t_background) {
_CheckForSdfPathValue(value, [&](const SdfPath& p) { _background = p; });
} else if (key == str::t_atmosphere) {
_CheckForSdfPathValue(value, [&](const SdfPath& p) { _atmosphere = p; });
} else {
auto* optionsEntry = AiNodeGetNodeEntry(_options);
// Sometimes the Render Delegate receives parameters that don't exist
Expand Down Expand Up @@ -749,6 +777,10 @@ VtValue HdArnoldRenderDelegate::GetRenderSetting(const TfToken& _key) const
return VtValue(v);
} else if (key == str::t_profile_file) {
return VtValue(std::string(AiProfileGetFileName().c_str()));
} else if (key == str::t_background) {
return VtValue(_background.GetString());
} else if (key == str::t_atmosphere) {
return VtValue(_atmosphere.GetString());
}
const auto* nentry = AiNodeGetNodeEntry(_options);
const auto* pentry = AiNodeEntryLookUpParameter(nentry, AtString(key.GetText()));
Expand Down Expand Up @@ -1271,4 +1303,14 @@ void HdArnoldRenderDelegate::SetRenderTags(const TfTokenVector& renderTags)
}
}

AtNode* HdArnoldRenderDelegate::GetBackground(HdRenderIndex* renderIndex)
{
return _GetNodeGraphTerminal(renderIndex, _background, str::t_background);
}

AtNode* HdArnoldRenderDelegate::GetAtmosphere(HdRenderIndex* renderIndex)
{
return _GetNodeGraphTerminal(renderIndex, _atmosphere, str::t_atmosphere);
}

PXR_NAMESPACE_CLOSE_SCOPE
16 changes: 16 additions & 0 deletions render_delegate/render_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,20 @@ class HdArnoldRenderDelegate final : public HdRenderDelegate {
HDARNOLD_API
void SetRenderTags(const TfTokenVector& renderTags);

/// Get the background shader.
///
/// @param renderIndex Pointer to the Hydra render index.
/// @return Pointer to the background shader, nullptr if no shader is set.
HDARNOLD_API
AtNode* GetBackground(HdRenderIndex* renderIndex);

/// Get the atmosphere shader.
///
/// @param renderIndex Pointer to the Hydra render index.
/// @return Pointer to the atmosphere shader, nullptr if no shader is set.
HDARNOLD_API
AtNode* GetAtmosphere(HdRenderIndex* renderIndex);

private:
HdArnoldRenderDelegate(const HdArnoldRenderDelegate&) = delete;
HdArnoldRenderDelegate& operator=(const HdArnoldRenderDelegate&) = delete;
Expand Down Expand Up @@ -503,6 +517,8 @@ class HdArnoldRenderDelegate final : public HdRenderDelegate {
/// rendering.
std::unique_ptr<HdArnoldRenderParam> _renderParam;
SdfPath _id; ///< Path of the Render Delegate.
SdfPath _background; ///< Path to the background shader.
SdfPath _atmosphere; ///< Path to the atmosphere shader.
AtUniverse* _universe; ///< Universe used by the Render Delegate.
#ifdef ARNOLD_MULTIPLE_RENDER_SESSIONS
AtRenderSession* _renderSession; ///< Render session used by the Render Delegate.
Expand Down
11 changes: 11 additions & 0 deletions render_delegate/render_pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,17 @@ void HdArnoldRenderPass::_Execute(const HdRenderPassStateSharedPtr& renderPassSt
AiNodeSetInt(options, str::yres, _height);
}

auto checkShader = [&] (AtNode* shader, const AtString& paramName) {
auto* options = _renderDelegate->GetOptions();
if (shader != static_cast<AtNode*>(AiNodeGetPtr(options, paramName))) {
renderParam->Interrupt(true, false);
AiNodeSetPtr(options, paramName, shader);
}
};

checkShader(_renderDelegate->GetBackground(GetRenderIndex()), str::background);
checkShader(_renderDelegate->GetAtmosphere(GetRenderIndex()), str::atmosphere);

// 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

0 comments on commit 57f6a33

Please sign in to comment.