Skip to content

Commit

Permalink
Support subdiv dicing camera #1062 (#1148)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienblor authored May 6, 2022
1 parent ce6a683 commit 6cf0db1
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 4 deletions.
3 changes: 3 additions & 0 deletions common/constant_strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,9 @@ ASTR(st);
ASTR(standard_surface);
ASTR(standard_volume);
ASTR(step_size);
ASTR(subdiv_dicing_camera);
ASTR(subdiv_frustum_culling);
ASTR(subdiv_frustum_padding);
ASTR(subdiv_iterations);
ASTR(subdiv_type);
ASTR(subsurface);
Expand Down
15 changes: 14 additions & 1 deletion render_delegate/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,20 @@ HdArnoldCamera::HdArnoldCamera(HdArnoldRenderDelegate* renderDelegate, const Sdf
}
}

HdArnoldCamera::~HdArnoldCamera() { AiNodeDestroy(_camera); }
HdArnoldCamera::~HdArnoldCamera() {
if (_camera) {
// Check if this camera node is referenced in the options
// and clear the attributes if needed
AtNode *options = AiUniverseGetOptions(AiNodeGetUniverse(_camera));
if (_camera == AiNodeGetPtr(options, str::camera))
AiNodeResetParameter(options, str::camera);

if (_camera == AiNodeGetPtr(options, str::subdiv_dicing_camera))
AiNodeResetParameter(options, str::subdiv_dicing_camera);

AiNodeDestroy(_camera);
}
}

void HdArnoldCamera::Sync(HdSceneDelegate* sceneDelegate, HdRenderParam* renderParam, HdDirtyBits* dirtyBits)
{
Expand Down
21 changes: 21 additions & 0 deletions render_delegate/render_delegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,11 @@ 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_subdiv_dicing_camera, {"Subdiv Dicing Camera", std::string{}}},
{str::t_subdiv_frustum_culling, {"Subdiv Frustum Culling"}},
{str::t_subdiv_frustum_padding, {"Subdiv Frustum Padding"}},

{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{}}},
Expand Down Expand Up @@ -633,6 +638,11 @@ void HdArnoldRenderDelegate::_SetRenderSetting(const TfToken& _key, const VtValu
ArnoldUsdCheckForSdfPathValue(value, [&](const SdfPath& p) { _atmosphere = p; });
} else if (key == str::t_aov_shaders) {
ArnoldUsdCheckForSdfPathValue(value, [&](const SdfPath& p) { _aov_shaders = p; });
} else if (key == str::t_subdiv_dicing_camera) {
ArnoldUsdCheckForSdfPathValue(value, [&](const SdfPath& p) {
_subdiv_dicing_camera = p;
AiNodeSetPtr(_options, str::subdiv_dicing_camera, AiNodeLookUpByName(_universe, AtString(_subdiv_dicing_camera.GetText())));
});
} else if (key == str::color_space_linear) {
if (value.IsHolding<std::string>()) {
AtNode* colorManager = getOrCreateColorManager(_universe, _options);
Expand Down Expand Up @@ -813,6 +823,8 @@ VtValue HdArnoldRenderDelegate::GetRenderSetting(const TfToken& _key) const
return VtValue(_atmosphere.GetString());
} else if (key == str::t_aov_shaders) {
return VtValue(_aov_shaders.GetString());
} else if (key == str::t_subdiv_dicing_camera) {
return VtValue(_subdiv_dicing_camera.GetString());
}
const auto* nentry = AiNodeGetNodeEntry(_options);
const auto* pentry = AiNodeEntryLookUpParameter(nentry, AtString(key.GetText()));
Expand Down Expand Up @@ -1400,4 +1412,13 @@ std::vector<AtNode*> HdArnoldRenderDelegate::GetAovShaders(HdRenderIndex* render
return HdArnoldNodeGraph::GetNodeGraphTerminals(renderIndex, _aov_shaders, str::t_aov_shaders);
}

AtNode* HdArnoldRenderDelegate::GetSubdivDicingCamera(HdRenderIndex* renderIndex)
{
if (_subdiv_dicing_camera.IsEmpty())
return nullptr;

return AiNodeLookUpByName(_universe, AtString(_subdiv_dicing_camera.GetText()));
}


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 @@ -478,6 +478,13 @@ class HdArnoldRenderDelegate final : public HdRenderDelegate {
HDARNOLD_API
AtNode* GetAtmosphere(HdRenderIndex* renderIndex);

/// Get the camera used for subdivision dicing
///
/// @param renderIndex Pointer to the Hydra render index.
/// @return Pointer to the camera node, nullptr if no camera is set.
HDARNOLD_API
AtNode* HdArnoldRenderDelegate::GetSubdivDicingCamera(HdRenderIndex* renderIndex);

/// Get the aov shaders.
///
/// @param renderIndex Pointer to the Hydra render index.
Expand Down Expand Up @@ -564,6 +571,7 @@ class HdArnoldRenderDelegate final : public HdRenderDelegate {
SdfPath _background; ///< Path to the background shader.
SdfPath _atmosphere; ///< Path to the atmosphere shader.
SdfPath _aov_shaders; ///< Path to the aov shaders.
SdfPath _subdiv_dicing_camera; ///< Path to the subdiv dicing camera
AtUniverse* _universe; ///< Universe used by the Render Delegate.
#ifdef ARNOLD_MULTIPLE_RENDER_SESSIONS
AtRenderSession* _renderSession; ///< Render session used by the Render Delegate.
Expand Down
15 changes: 12 additions & 3 deletions render_delegate/render_pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,10 @@ void HdArnoldRenderPass::_Execute(const HdRenderPassStateSharedPtr& renderPassSt
auto* renderParam = reinterpret_cast<HdArnoldRenderParam*>(_renderDelegate->GetRenderParam());
const auto dataWindow = _GetDataWindow(renderPassState);

AtNode *options = AiUniverseGetOptions(_renderDelegate->GetUniverse());

const auto* currentUniverseCamera =
static_cast<const AtNode*>(AiNodeGetPtr(AiUniverseGetOptions(_renderDelegate->GetUniverse()), str::camera));
static_cast<const AtNode*>(AiNodeGetPtr(options, str::camera));
const auto* camera = reinterpret_cast<const HdArnoldCamera*>(renderPassState->GetCamera());
const auto useOwnedCamera = camera == nullptr;
AtNode* currentCamera = nullptr;
Expand All @@ -467,13 +469,13 @@ void HdArnoldRenderPass::_Execute(const HdRenderPassStateSharedPtr& renderPassSt
currentCamera = _camera;
if (currentUniverseCamera != _camera) {
renderParam->Interrupt();
AiNodeSetPtr(AiUniverseGetOptions(_renderDelegate->GetUniverse()), str::camera, _camera);
AiNodeSetPtr(options, str::camera, _camera);
}
} else {
currentCamera = camera->GetCamera();
if (currentUniverseCamera != currentCamera) {
renderParam->Interrupt();
AiNodeSetPtr(AiUniverseGetOptions(_renderDelegate->GetUniverse()), str::camera, currentCamera);
AiNodeSetPtr(options, str::camera, currentCamera);
}
}

Expand Down Expand Up @@ -529,6 +531,13 @@ void HdArnoldRenderPass::_Execute(const HdRenderPassStateSharedPtr& renderPassSt
updateAovs = true;
}

// Eventually set the subdiv dicing camera in the options
const AtNode *subdivDicingCamera = _renderDelegate->GetSubdivDicingCamera(GetRenderIndex());
if (subdivDicingCamera)
AiNodeSetPtr(options, str::subdiv_dicing_camera, (void*)subdivDicingCamera);
else
AiNodeResetParameter(options, str::subdiv_dicing_camera);

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

Please sign in to comment.