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

Avoid updating the main driver matrices in case of camera movement #870

Merged
merged 1 commit into from
Aug 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Avoid updating the main driver matrices in case of camera movement.
Fixes #869
  • Loading branch information
sirpalee committed Aug 13, 2021
commit 68a99af29788dc3d881f87562c6616a4b21eb4e0
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