Skip to content

Commit

Permalink
Avoid updating the main driver matrices in case of camera movement.
Browse files Browse the repository at this point in the history
Fixes #869
  • Loading branch information
sirpalee committed Aug 13, 2021
1 parent ae70e1a commit 68a99af
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 20 deletions.
23 changes: 5 additions & 18 deletions render_delegate/nodes/driver_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@
#include <memory>

#include <constant_strings.h>
#include "../render_buffer.h"

#include "../utils.h"
#include "nodes.h"

PXR_NAMESPACE_OPEN_SCOPE

Expand All @@ -41,20 +42,6 @@ AI_DRIVER_NODE_EXPORT_METHODS(HdArnoldDriverMainMtd);
namespace {
const char* supportedExtensions[] = {nullptr};

struct DriverData {
GfMatrix4f projMtx = GfMatrix4f{1.0f};
GfMatrix4f viewMtx = GfMatrix4f{1.0f};
HdArnoldRenderBuffer* colorBuffer = nullptr;
HdArnoldRenderBuffer* depthBuffer = nullptr;
HdArnoldRenderBuffer* idBuffer = nullptr;
// Local storage for converting from P to depth.
std::vector<float> depths[AI_MAX_THREADS];
// Local storage for the id remapping.
std::vector<int> ids[AI_MAX_THREADS];
// Local storage for the color buffer.
std::vector<AtRGBA> colors[AI_MAX_THREADS];
};

} // namespace

node_parameters
Expand All @@ -69,12 +56,12 @@ node_parameters
node_initialize
{
AiDriverInitialize(node, true);
AiNodeSetLocalData(node, new DriverData());
AiNodeSetLocalData(node, new DriverMainData());
}

node_update
{
auto* data = reinterpret_cast<DriverData*>(AiNodeGetLocalData(node));
auto* data = reinterpret_cast<DriverMainData*>(AiNodeGetLocalData(node));
data->projMtx = HdArnoldConvertMatrix(AiNodeGetMatrix(node, str::projMtx));
data->viewMtx = HdArnoldConvertMatrix(AiNodeGetMatrix(node, str::viewMtx));
data->colorBuffer = static_cast<HdArnoldRenderBuffer*>(AiNodeGetPtr(node, str::color_pointer));
Expand All @@ -99,7 +86,7 @@ driver_prepare_bucket {}

driver_process_bucket
{
auto* driverData = reinterpret_cast<DriverData*>(AiNodeGetLocalData(node));
auto* driverData = reinterpret_cast<DriverMainData*>(AiNodeGetLocalData(node));
#if ARNOLD_VERSION_NUMBER > 60201
AtString outputName;
#else
Expand Down
18 changes: 18 additions & 0 deletions render_delegate/nodes/nodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@

#include <pxr/pxr.h>

#include <pxr/base/gf/matrix4f.h>

#include <pxr/base/tf/token.h>

#include "../render_buffer.h"

#include <ai.h>

#include <functional>
Expand All @@ -42,6 +46,20 @@

PXR_NAMESPACE_OPEN_SCOPE

struct DriverMainData {
GfMatrix4f projMtx = GfMatrix4f{1.0f};
GfMatrix4f viewMtx = GfMatrix4f{1.0f};
HdArnoldRenderBuffer* colorBuffer = nullptr;
HdArnoldRenderBuffer* depthBuffer = nullptr;
HdArnoldRenderBuffer* idBuffer = nullptr;
// Local storage for converting from P to depth.
std::vector<float> depths[AI_MAX_THREADS];
// Local storage for the id remapping.
std::vector<int> ids[AI_MAX_THREADS];
// Local storage for the color buffer.
std::vector<AtRGBA> colors[AI_MAX_THREADS];
};

/// Installs Arnold nodes that are used by the Render Delegate.
void hdArnoldInstallNodes();

Expand Down
12 changes: 10 additions & 2 deletions render_delegate/render_pass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

#include "camera.h"
#include "config.h"
#include "nodes/nodes.h"
#include "utils.h"

PXR_NAMESPACE_OPEN_SCOPE
Expand Down Expand Up @@ -475,8 +476,15 @@ void HdArnoldRenderPass::_Execute(const HdRenderPassStateSharedPtr& renderPassSt
_projMtx = projMtx;
_viewMtx = viewMtx;
renderParam->Interrupt(true, false);
AiNodeSetMatrix(_mainDriver, str::projMtx, HdArnoldConvertMatrix(_projMtx));
AiNodeSetMatrix(_mainDriver, str::viewMtx, HdArnoldConvertMatrix(_viewMtx));
auto* mainDriverData = static_cast<DriverMainData*>(AiNodeGetLocalData(_mainDriver));
if (mainDriverData != nullptr) {
mainDriverData->projMtx = GfMatrix4f{_projMtx};
mainDriverData->viewMtx = GfMatrix4f{_viewMtx};
} else {
AiNodeSetMatrix(_mainDriver, str::projMtx, HdArnoldConvertMatrix(_projMtx));
AiNodeSetMatrix(_mainDriver, str::viewMtx, HdArnoldConvertMatrix(_viewMtx));
}

if (useOwnedCamera) {
const auto fov = static_cast<float>(GfRadiansToDegrees(atan(1.0 / _projMtx[0][0]) * 2.0));
AiNodeSetFlt(_camera, str::fov, fov);
Expand Down

0 comments on commit 68a99af

Please sign in to comment.