Skip to content
Open
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
5 changes: 4 additions & 1 deletion pxr/imaging/hd/material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ HdConvertToHdMaterialNetwork2(
}

// Transfer primvars:
result.primvars = hdNetwork.primvars;
result.primvars.insert(
result.primvars.end(),
hdNetwork.primvars.begin(),
hdNetwork.primvars.end());
}

// Transfer config dictionary
Expand Down
30 changes: 26 additions & 4 deletions pxr/imaging/hd/materialNetworkSchema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,25 @@ HdMaterialNetworkSchema::GetConfig() const
HdMaterialNetworkSchemaTokens->config));
}

HdTokenVectorMapDataSourceHandle
HdMaterialNetworkSchema::GetPrimvars() const
{
return _GetTypedDataSource<HdTokenVectorMapDataSource>(
HdMaterialNetworkSchemaTokens->primvars);
}

/*static*/
HdContainerDataSourceHandle
HdMaterialNetworkSchema::BuildRetained(
const HdContainerDataSourceHandle &nodes,
const HdContainerDataSourceHandle &terminals,
const HdContainerDataSourceHandle &interfaceMappings,
const HdContainerDataSourceHandle &config
const HdContainerDataSourceHandle &config,
const HdTokenVectorMapDataSourceHandle &primvarsMap
)
{
TfToken _names[4];
HdDataSourceBaseHandle _values[4];
TfToken _names[5];
HdDataSourceBaseHandle _values[5];

size_t _count = 0;

Expand All @@ -93,6 +101,11 @@ HdMaterialNetworkSchema::BuildRetained(
_names[_count] = HdMaterialNetworkSchemaTokens->config;
_values[_count++] = config;
}

if (primvarsMap) {
_names[_count] = HdMaterialNetworkSchemaTokens->primvars;
_values[_count++] = primvarsMap;
}
return HdRetainedContainerDataSource::New(_count, _names, _values);
}

Expand Down Expand Up @@ -128,14 +141,23 @@ HdMaterialNetworkSchema::Builder::SetConfig(
return *this;
}

HdMaterialNetworkSchema::Builder &
HdMaterialNetworkSchema::Builder::SetPrimvars(
const HdTokenVectorMapDataSourceHandle &primvarsMap)
{
_primvarsMap = primvarsMap;
return *this;
}

HdContainerDataSourceHandle
HdMaterialNetworkSchema::Builder::Build()
{
return HdMaterialNetworkSchema::BuildRetained(
_nodes,
_terminals,
_interfaceMappings,
_config
_config,
_primvarsMap
);
}

Expand Down
16 changes: 15 additions & 1 deletion pxr/imaging/hd/materialNetworkSchema.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,19 @@
PXR_NAMESPACE_OPEN_SCOPE

// --(BEGIN CUSTOM CODE: Declares)--

using HdTokenVectorMap = std::map<TfToken, TfTokenVector>;
using HdTokenVectorMapDataSource = HdTypedSampledDataSource<HdTokenVectorMap>;
using HdTokenVectorMapDataSourceHandle = HdTokenVectorMapDataSource::Handle;

// --(END CUSTOM CODE: Declares)--

#define HD_MATERIAL_NETWORK_SCHEMA_TOKENS \
(nodes) \
(terminals) \
(interfaceMappings) \
(config) \
(primvars) \

TF_DECLARE_PUBLIC_TOKENS(HdMaterialNetworkSchemaTokens, HD_API,
HD_MATERIAL_NETWORK_SCHEMA_TOKENS);
Expand Down Expand Up @@ -113,6 +119,9 @@ class HdMaterialNetworkSchema : public HdSchema
HD_API
HdSampledDataSourceContainerSchema GetConfig() const;

HD_API
HdTokenVectorMapDataSourceHandle GetPrimvars() const;

/// @}

/// \name Schema construction
Expand All @@ -131,7 +140,8 @@ class HdMaterialNetworkSchema : public HdSchema
const HdContainerDataSourceHandle &nodes,
const HdContainerDataSourceHandle &terminals,
const HdContainerDataSourceHandle &interfaceMappings,
const HdContainerDataSourceHandle &config
const HdContainerDataSourceHandle &config,
const HdTokenVectorMapDataSourceHandle &primvarsMap
);

/// \class HdMaterialNetworkSchema::Builder
Expand All @@ -155,6 +165,9 @@ class HdMaterialNetworkSchema : public HdSchema
HD_API
Builder &SetConfig(
const HdContainerDataSourceHandle &config);
HD_API
Builder &SetPrimvars(
const HdTokenVectorMapDataSourceHandle &primvarsMap);

/// Returns a container data source containing the members set thus far.
HD_API
Expand All @@ -165,6 +178,7 @@ class HdMaterialNetworkSchema : public HdSchema
HdContainerDataSourceHandle _terminals;
HdContainerDataSourceHandle _interfaceMappings;
HdContainerDataSourceHandle _config;
HdTokenVectorMapDataSourceHandle _primvarsMap;

};

Expand Down
17 changes: 17 additions & 0 deletions pxr/imaging/hd/sceneIndexAdapterSceneDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1275,6 +1275,13 @@ _ToMaterialNetworkMap(
matHd.config = _ToDictionary(config);
}

HdTokenVectorMap primvarsMap;
if (const HdTokenVectorMapDataSourceHandle primvarsMapDs =
netSchema.GetPrimvars())
{
primvarsMap = primvarsMapDs->GetTypedValue(0);
}

for (const auto & name : names) {
visitedNodes.clear();

Expand Down Expand Up @@ -1304,6 +1311,16 @@ _ToMaterialNetworkMap(
nodesSchema, renderContexts, &visitedNodes, &netHd);
}
}

// Extra primvars.
if (const auto &primvarsIter = primvarsMap.find(name);
primvarsIter != primvarsMap.end())
{
netHd.primvars.insert(
netHd.primvars.end(),
primvarsIter->second.begin(),
primvarsIter->second.end());
}
}

return matHd;
Expand Down
20 changes: 19 additions & 1 deletion pxr/imaging/hd/testenv/testHdUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//
#include "pxr/pxr.h"

#include "pxr/base/gf/vec3f.h"
#include "pxr/imaging/hd/dataSource.h"
#include "pxr/imaging/hd/utils.h"
#include "pxr/base/tf/errorMark.h"
Expand All @@ -22,7 +23,7 @@ BasicTest()
{
// Create a representation of a material network
HdMaterialNetwork materialNetwork;
materialNetwork.nodes.reserve(3);
materialNetwork.nodes.reserve(4);

const SdfPath materialPath("/Asset/Looks/Material");

Expand All @@ -43,6 +44,16 @@ BasicTest()
standInNode.identifier = TfToken("PbsNetworkMaterialStandIn_3");
materialNetwork.nodes.push_back(standInNode);

const TfToken primvarToken("Primvar_0");
materialNetwork.primvars.push_back(primvarToken);

HdMaterialNode primvarNode;
primvarNode.path = SdfPath("/Asset/Looks/Material/Primvar_0Reader");
primvarNode.identifier = TfToken("PrimvarReader_float3");
primvarNode.parameters[TfToken("varname")] = primvarToken;
primvarNode.parameters[TfToken("fallback")] = VtValue(GfVec3f(1.0f, 1.0f, 1.0f));
materialNetwork.nodes.push_back(primvarNode);

// Connect the nodes
HdMaterialRelationship textureMaterialLayerRel;
textureMaterialLayerRel.inputId = textureNode.path;
Expand All @@ -58,6 +69,13 @@ BasicTest()
materialLayerStandInRel.outputName = TfToken("multiMaterialIn");
materialNetwork.relationships.push_back(materialLayerStandInRel);

pxr::HdMaterialRelationship primvarRel;
primvarRel.inputId = primvarNode.path;
primvarRel.inputName = TfToken("result");
primvarRel.outputId = materialPath;
primvarRel.outputName = primvarToken;
materialNetwork.relationships.push_back(primvarRel);

HdMaterialNetworkMap networkMap;
networkMap.map[TfToken("surface")] = materialNetwork;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@
[nodeIdentifier]
MaterialLayer_3
[parameters]
[/Asset/Looks/Material/Primvar_0Reader]
[inputConnections]
[nodeIdentifier]
PrimvarReader_float3
[parameters]
[fallback]
[value]
(1, 1, 1)
[varname]
[value]
Primvar_0
[/Asset/Looks/Material/StandIn]
[inputConnections]
[multiMaterialIn]
Expand All @@ -31,6 +42,7 @@
[inputs:filename]
[value]
studio/patterns/checkerboard/checkerboard.tex
[primvars]
[terminals]
[surface]
[upstreamNodeOutputName]
Expand Down
4 changes: 4 additions & 0 deletions pxr/imaging/hd/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ ConvertHdMaterialNetworkToHdMaterialNetworkSchema(
std::vector<HdDataSourceBaseHandle> terminalsValues;
std::vector<TfToken> nodeNames;
std::vector<HdDataSourceBaseHandle> nodeValues;
HdTokenVectorMap primvarsMap;

struct ParamData {
VtValue value;
Expand All @@ -160,6 +161,7 @@ ConvertHdMaterialNetworkToHdMaterialNetworkSchema(
}

terminalsNames.push_back(terminalName);
primvarsMap[terminalName] = hdNetwork.primvars;

// Transfer over individual nodes.
// Note that the same nodes may be shared by multiple terminals.
Expand Down Expand Up @@ -307,6 +309,8 @@ ConvertHdMaterialNetworkToHdMaterialNetworkSchema(
.SetNodes(nodesDefaultContext)
.SetTerminals(terminalsDefaultContext)
.SetConfig(configDefaultContext)
.SetPrimvars(
HdRetainedTypedSampledDataSource<HdTokenVectorMap>::New(primvarsMap))
.Build();
}

Expand Down
27 changes: 27 additions & 0 deletions pxr/imaging/hdSt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3363,4 +3363,31 @@ pxr_register_test(testHdStShaders
ENV
TF_DEBUG=HD_SAFE_MODE
)

pxr_build_test(testHdStShaderPrimvars
LIBRARIES
hdSt
hd
sdr
tf
gf
CPPFILES
testenv/testHdStShaderPrimvars.cpp
)
pxr_install_test_dir(
SRC testenv/testHdStShaderPrimvars
DEST testHdStShaderPrimvars
)
pxr_register_test(testHdStShaderPrimvars
COMMAND "${CMAKE_INSTALL_PREFIX}/tests/testHdStShaderPrimvars --offscreen --outputFilePrefix testHdStShaderPrimvars"
EXPECTED_RETURN_CODE 0
IMAGE_DIFF_COMPARE
testHdStShaderPrimvars.png
FAIL 1
FAIL_PERCENT 1
PERCEPTUAL
TESTENV testHdStShaderPrimvars
ENV
TF_DEBUG=HD_SAFE_MODE
)
endif() # TARGET shared_libs
Loading