Skip to content

Commit

Permalink
Random curves width when primvars:radius is present Autodesk#1961
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastienblor committed Jul 9, 2024
1 parent d935002 commit 6499d24
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 10 deletions.
11 changes: 9 additions & 2 deletions libs/render_delegate/basis_curves.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,13 @@ void HdArnoldBasisCurves::Sync(
// The curves node only knows the "uvs" parameter, so we have to rename the attribute
TfToken arnoldAttributeName = primvar.first;
auto value = desc.value;
bool skipExisting = true;
if (primvar.first == str::t_uv || primvar.first == str::t_st) {
arnoldAttributeName = str::t_uvs;
// Primvars which correspond to an attribute in the arnold node entry will be skipped
// by default #1961. Here we want to make an exception since uvs is a builtin attribute in Arnold
// even though it's a primvar in USD
skipExisting = false;
// Special case if the uvs attribute has 3 dimensions
if (desc.value.IsHolding<VtVec3fArray>()) {
value = Vec3fToVec2f(desc.value);
Expand All @@ -249,7 +254,8 @@ void HdArnoldBasisCurves::Sync(
nullptr, GetRenderDelegate());
}
} else if (desc.interpolation == HdInterpolationUniform) {
HdArnoldSetUniformPrimvar(GetArnoldNode(), arnoldAttributeName, desc.role, value, GetRenderDelegate());
HdArnoldSetUniformPrimvar(GetArnoldNode(), arnoldAttributeName, desc.role, value,
GetRenderDelegate(), skipExisting);
} else if (desc.interpolation == HdInterpolationVertex || desc.interpolation == HdInterpolationVarying) {
if (primvar.first == HdTokens->points) {
HdArnoldSetPositionFromValue(GetArnoldNode(), str::points, value);
Expand All @@ -266,7 +272,8 @@ void HdArnoldBasisCurves::Sync(
bool, VtUCharArray::value_type, unsigned int, int, float, GfVec2f, GfVec3f, GfVec4f,
std::string, TfToken, SdfAssetPath>(value);
}
HdArnoldSetVertexPrimvar(GetArnoldNode(), arnoldAttributeName, desc.role, value, GetRenderDelegate());
HdArnoldSetVertexPrimvar(GetArnoldNode(), arnoldAttributeName, desc.role, value,
GetRenderDelegate(), skipExisting);
}
}
}
Expand Down
34 changes: 30 additions & 4 deletions libs/render_delegate/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,12 +367,18 @@ bool ConvertPrimvarToBuiltinParameter(

void HdArnoldSetConstantPrimvar(
AtNode* node, const TfToken& name, const TfToken& role, const VtValue& value, HdArnoldRayFlags* visibility,
HdArnoldRayFlags* sidedness, HdArnoldRayFlags* autobumpVisibility, HdArnoldRenderDelegate *renderDelegate)
HdArnoldRayFlags* sidedness, HdArnoldRayFlags* autobumpVisibility,
HdArnoldRenderDelegate *renderDelegate, bool skipExisting)
{
// Remap primvars:arnold:xyz parameters to xyz parameters on the node.
if (ConvertPrimvarToBuiltinParameter(node, name, value, visibility, sidedness, autobumpVisibility, renderDelegate)) {
return;
}
// If this attribute already exists in the node entry parameters list,
// we must skip it #1961
if (skipExisting && AiNodeEntryLookUpParameter(AiNodeGetNodeEntry(node), AtString(name.GetText())) != nullptr) {
return;
}

DeclareAndAssignParameter(node, name,
str::t_constant, value, renderDelegate->GetAPIAdapter(),
Expand All @@ -389,8 +395,15 @@ void HdArnoldSetConstantPrimvar(
autobumpVisibility, renderDelegate);
}

void HdArnoldSetUniformPrimvar(AtNode* node, const TfToken& name, const TfToken& role, const VtValue& value, HdArnoldRenderDelegate *renderDelegate)
void HdArnoldSetUniformPrimvar(AtNode* node, const TfToken& name, const TfToken& role, const VtValue& value,
HdArnoldRenderDelegate *renderDelegate, bool skipExisting)
{
// If this attribute already exists in the node entry parameters list,
// we must skip it #1961
if (skipExisting && AiNodeEntryLookUpParameter(AiNodeGetNodeEntry(node), AtString(name.GetText())) != nullptr) {
return;
}

DeclareAndAssignParameter(node, name,
str::t_uniform, value, renderDelegate->GetAPIAdapter(),
role == HdPrimvarRoleTokens->color);
Expand All @@ -402,8 +415,15 @@ void HdArnoldSetUniformPrimvar(
HdArnoldSetUniformPrimvar(node, primvarDesc.name, primvarDesc.role, delegate->Get(id, primvarDesc.name), renderDelegate);
}

void HdArnoldSetVertexPrimvar(AtNode* node, const TfToken& name, const TfToken& role, const VtValue& value, HdArnoldRenderDelegate *renderDelegate)
void HdArnoldSetVertexPrimvar(AtNode* node, const TfToken& name, const TfToken& role, const VtValue& value,
HdArnoldRenderDelegate *renderDelegate, bool skipExisting)
{
// If this attribute already exists in the node entry parameters list,
// we must skip it #1961
if (skipExisting && AiNodeEntryLookUpParameter(AiNodeGetNodeEntry(node), AtString(name.GetText())) != nullptr) {
return;
}

DeclareAndAssignParameter(node, name,
str::t_varying, value, renderDelegate->GetAPIAdapter(),
role == HdPrimvarRoleTokens->color);
Expand All @@ -420,8 +440,14 @@ void HdArnoldSetFaceVaryingPrimvar(
#ifdef USD_HAS_SAMPLE_INDEXED_PRIMVAR
const VtIntArray& valueIndices,
#endif
const VtIntArray* vertexCounts, const size_t* vertexCountSum)
const VtIntArray* vertexCounts, const size_t* vertexCountSum, bool skipExisting)
{
// If this attribute already exists in the node entry parameters list,
// we must skip it #1961
if (skipExisting && AiNodeEntryLookUpParameter(AiNodeGetNodeEntry(node), AtString(name.GetText())) != nullptr) {
return;
}

const uint32_t numElements = DeclareAndAssignParameter(node, name,
str::t_indexed, value, renderDelegate->GetAPIAdapter(),
role == HdPrimvarRoleTokens->color);
Expand Down
15 changes: 11 additions & 4 deletions libs/render_delegate/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,12 @@ bool ConvertPrimvarToRayFlag(AtNode* node, const TfToken& name, const VtValue& v
/// @param sidedness Pointer to the output sidedness parameter.
/// @param autobumpVisibility Pointer to the output autobump_visibility parameter.
/// @param renderDelegate Pointer to the current Render Delegate.
/// @param skipExisting Should this primvar be skipped when the attribute exists in the node entry
HDARNOLD_API
void HdArnoldSetConstantPrimvar(
AtNode* node, const TfToken& name, const TfToken& role, const VtValue& value, HdArnoldRayFlags* visibility,
HdArnoldRayFlags* sidedness, HdArnoldRayFlags* autobumpVisibility, HdArnoldRenderDelegate *renderDelegate);
HdArnoldRayFlags* sidedness, HdArnoldRayFlags* autobumpVisibility,
HdArnoldRenderDelegate *renderDelegate, bool skipExisting = true);
/// Sets a Constant scope Primvar on an Arnold node from a Hydra Primitive.
///
/// There is some additional type remapping done to deal with various third
Expand Down Expand Up @@ -330,8 +332,10 @@ void HdArnoldSetConstantPrimvar(
/// @param name Name of the primvar.
/// @param role Role of the primvar.
/// @param value Value of the primvar.
/// @param skipExisting Should this primvar be skipped when the attribute exists in the node entry
HDARNOLD_API
void HdArnoldSetUniformPrimvar(AtNode* node, const TfToken& name, const TfToken& role, const VtValue& value, HdArnoldRenderDelegate *renderDelegate);
void HdArnoldSetUniformPrimvar(AtNode* node, const TfToken& name, const TfToken& role, const VtValue& value,
HdArnoldRenderDelegate *renderDelegate, bool skipExisting = true);
/// Sets a Uniform scope Primvar on an Arnold node from a Hydra Primitive.
///
/// @param node Pointer to an Arnold Node.
Expand All @@ -347,8 +351,10 @@ void HdArnoldSetUniformPrimvar(
/// @param name Name of the primvar.
/// @param role Role of the primvar.
/// @param value Value of the primvar.
/// @param skipExisting Should this primvar be skipped when the attribute exists in the node entry
HDARNOLD_API
void HdArnoldSetVertexPrimvar(AtNode* node, const TfToken& name, const TfToken& role, const VtValue& value, HdArnoldRenderDelegate *renderDelegate);
void HdArnoldSetVertexPrimvar(AtNode* node, const TfToken& name, const TfToken& role, const VtValue& value,
HdArnoldRenderDelegate *renderDelegate, bool skipExisting = true);
/// Sets a Vertex scope Primvar on an Arnold node from a Hydra Primitive.
///
/// @param node Pointer to an Arnold Node.
Expand All @@ -369,13 +375,14 @@ void HdArnoldSetVertexPrimvar(
/// @param valueIndices Face-varying indices for the primvar.
/// @param vertexCounts Optional pointer to the VtIntArray holding the face vertex counts for the mesh.
/// @param vertexCountSum Optional size_t with sum of the vertexCounts.
/// @param skipExisting Should this primvar be skipped when the attribute exists in the node entry
HDARNOLD_API
void HdArnoldSetFaceVaryingPrimvar(
AtNode* node, const TfToken& name, const TfToken& role, const VtValue& value, HdArnoldRenderDelegate *renderDelegate,
#ifdef USD_HAS_SAMPLE_INDEXED_PRIMVAR
const VtIntArray& valueIndices,
#endif
const VtIntArray* vertexCounts = nullptr, const size_t* vertexCountSum = nullptr);
const VtIntArray* vertexCounts = nullptr, const size_t* vertexCountSum = nullptr, bool skipExisting = true);
/// Sets instance primvars on an instancer node.
///
/// @param node Pointer to the Arnold instancer node.
Expand Down

0 comments on commit 6499d24

Please sign in to comment.