-
Notifications
You must be signed in to change notification settings - Fork 59
/
points.cpp
125 lines (107 loc) · 4.99 KB
/
points.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Copyright 2022 Autodesk, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "points.h"
#include <constant_strings.h>
#include "node_graph.h"
#include "utils.h"
PXR_NAMESPACE_OPEN_SCOPE
#if PXR_VERSION >= 2102
HdArnoldPoints::HdArnoldPoints(HdArnoldRenderDelegate* renderDelegate, const SdfPath& id)
: HdArnoldRprim<HdPoints>(str::points, renderDelegate, id)
{
}
#else
HdArnoldPoints::HdArnoldPoints(HdArnoldRenderDelegate* renderDelegate, const SdfPath& id, const SdfPath& instancerId)
: HdArnoldRprim<HdPoints>(str::points, renderDelegate, id, instancerId)
{
}
#endif
HdDirtyBits HdArnoldPoints::GetInitialDirtyBitsMask() const
{
return HdChangeTracker::DirtyPoints | HdChangeTracker::DirtyTransform | HdChangeTracker::DirtyVisibility |
HdChangeTracker::DirtyDoubleSided | HdChangeTracker::DirtyPrimvar | HdChangeTracker::DirtyWidths |
HdChangeTracker::DirtyMaterialId | HdArnoldShape::GetInitialDirtyBitsMask();
}
void HdArnoldPoints::Sync(
HdSceneDelegate* sceneDelegate, HdRenderParam* renderParam, HdDirtyBits* dirtyBits, const TfToken& reprToken)
{
HdArnoldRenderParamInterrupt param(renderParam);
const auto& id = GetId();
auto transformDirtied = false;
if (HdChangeTracker::IsTransformDirty(*dirtyBits, id)) {
param.Interrupt();
HdArnoldSetTransform(GetArnoldNode(), sceneDelegate, GetId());
transformDirtied = true;
}
if (HdChangeTracker::IsPrimvarDirty(*dirtyBits, id, HdTokens->widths)) {
param.Interrupt();
HdArnoldSetRadiusFromPrimvar(GetArnoldNode(), id, sceneDelegate);
}
CheckVisibilityAndSidedness(sceneDelegate, id, dirtyBits, param);
if (*dirtyBits & HdChangeTracker::DirtyMaterialId) {
param.Interrupt();
const auto materialId = sceneDelegate->GetMaterialId(id);
// Ensure the reference from this shape to its material is properly tracked
// by the render delegate
GetRenderDelegate()->TrackDependencies(id, HdArnoldRenderDelegate::PathSet {materialId});
const auto* material = reinterpret_cast<const HdArnoldNodeGraph*>(
sceneDelegate->GetRenderIndex().GetSprim(HdPrimTypeTokens->material, materialId));
if (material != nullptr) {
AiNodeSetPtr(GetArnoldNode(), str::shader, material->GetSurfaceShader());
} else {
AiNodeSetPtr(GetArnoldNode(), str::shader, GetRenderDelegate()->GetFallbackSurfaceShader());
}
}
auto extrapolatePoints = false;
if (*dirtyBits & HdChangeTracker::DirtyPrimvar) {
HdArnoldGetPrimvars(sceneDelegate, id, *dirtyBits, false, _primvars);
_visibilityFlags.ClearPrimvarFlags();
_sidednessFlags.ClearPrimvarFlags();
param.Interrupt();
for (auto& primvar : _primvars) {
auto& desc = primvar.second;
// We can use this information to reset built-in values to their default values.
if (!desc.NeedsUpdate()) {
continue;
}
if (desc.interpolation == HdInterpolationConstant) {
if (primvar.first == str::deformKeys) {
if (desc.value.IsHolding<int>()) {
extrapolatePoints = SetDeformKeys(desc.value.UncheckedGet<int>());
}
} else {
HdArnoldSetConstantPrimvar(
GetArnoldNode(), primvar.first, desc.role, desc.value, &_visibilityFlags, &_sidednessFlags,
nullptr);
}
// Anything that's not per instance interpolation needs to be converted to uniform data.
} else if (desc.interpolation != HdInterpolationInstance) {
// Even though we are using velocity and acceleration for optional interpolation, we are still
// converting the values to user data.
if (primvar.first != HdTokens->points && primvar.first != HdTokens->widths) {
HdArnoldSetUniformPrimvar(GetArnoldNode(), primvar.first, desc.role, desc.value);
}
}
}
UpdateVisibilityAndSidedness();
}
if (extrapolatePoints || HdChangeTracker::IsPrimvarDirty(*dirtyBits, id, HdTokens->points)) {
param.Interrupt();
HdArnoldSetPositionFromPrimvar(
GetArnoldNode(), id, sceneDelegate, str::points, param(), GetDeformKeys(), &_primvars);
}
SyncShape(*dirtyBits, sceneDelegate, param, transformDirtied);
*dirtyBits = HdChangeTracker::Clean;
}
PXR_NAMESPACE_CLOSE_SCOPE