Skip to content

Commit

Permalink
introduces UsdImagingLightAPIAdapter for UsdImagingStageSceneIndex
Browse files Browse the repository at this point in the history
- adds support for delivering multiple renderContext nodeIdentifier values within HdMaterialNodeSchema
- adds fallback for HdSceneIndexAdapterSceneDelegate::GetLightParamValue to check against the light terminal node within the "material" data source
    - this is to handle legacy render delegate cases which expect to find light shader parameters within GetLightParamValue without compromising forward-looking use of material
- allows UsdImagingDataSourceMaterial to answer for unauthored light param attributes (like intensity) to match expectations of legacy hdStorm render delegate
- updates disk, distant, dome, plugin, rect and sphere light adapters to implement population-equivalent code for scene index pathway (GetImagingSubprimType)
- STILL TODO: have UsdImagingLightAPIAdapter provide "light" data source child values for "filters", "lightLink", "shadowLink" and "lightFilterLink"
     (corresponding collections are already handled by built-in support for API schemas, yeah!)

(Internal change: 2243381)
(Internal change: 2243412)
(Internal change: 2243439)
  • Loading branch information
stevelavietes authored and pixar-oss committed Jul 27, 2022
1 parent 05f204b commit 1f87b7b
Show file tree
Hide file tree
Showing 22 changed files with 761 additions and 32 deletions.
6 changes: 4 additions & 2 deletions pxr/imaging/hd/dataSourceLegacyPrim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2638,7 +2638,8 @@ _ConvertHdMaterialNetworkToHdDataSources(
cNames.data(),
cValues.data()),
HdRetainedTypedSampledDataSource<TfToken>::New(
node.identifier)));
node.identifier),
nullptr /*renderContextNodeIdentifiers*/));
}

terminalsValues.push_back(
Expand Down Expand Up @@ -2699,7 +2700,8 @@ _ConvertSampleFilterNodeToHdDataSources(
paramsValues.data()),
HdRetainedContainerDataSource::New(),// SampleFilter has no connections
HdRetainedTypedSampledDataSource<TfToken>::New(
hdNode.nodeTypeId));
hdNode.nodeTypeId),
nullptr /*renderContextNodeIdentifiers*/);

*result = HdSampleFilterSchema::BuildRetained(nodeDS);

Expand Down
30 changes: 26 additions & 4 deletions pxr/imaging/hd/materialNodeSchema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,24 @@ HdMaterialNodeSchema::GetNodeIdentifier()
HdMaterialNodeSchemaTokens->nodeIdentifier);
}

HdContainerDataSourceHandle
HdMaterialNodeSchema::GetRenderContextNodeIdentifiers()
{
return _GetTypedDataSource<HdContainerDataSource>(
HdMaterialNodeSchemaTokens->renderContextNodeIdentifiers);
}

/*static*/
HdContainerDataSourceHandle
HdMaterialNodeSchema::BuildRetained(
const HdContainerDataSourceHandle &parameters,
const HdContainerDataSourceHandle &inputConnections,
const HdTokenDataSourceHandle &nodeIdentifier
const HdTokenDataSourceHandle &nodeIdentifier,
const HdContainerDataSourceHandle &renderContextNodeIdentifiers
)
{
TfToken names[3];
HdDataSourceBaseHandle values[3];
TfToken names[4];
HdDataSourceBaseHandle values[4];

size_t count = 0;
if (parameters) {
Expand All @@ -86,6 +94,11 @@ HdMaterialNodeSchema::BuildRetained(
values[count++] = nodeIdentifier;
}

if (renderContextNodeIdentifiers) {
names[count] = HdMaterialNodeSchemaTokens->renderContextNodeIdentifiers;
values[count++] = renderContextNodeIdentifiers;
}

return HdRetainedContainerDataSource::New(count, names, values);
}

Expand Down Expand Up @@ -114,13 +127,22 @@ HdMaterialNodeSchema::Builder::SetNodeIdentifier(
return *this;
}

HdMaterialNodeSchema::Builder &
HdMaterialNodeSchema::Builder::SetRenderContextNodeIdentifiers(
const HdContainerDataSourceHandle &renderContextNodeIdentifiers)
{
_renderContextNodeIdentifiers = renderContextNodeIdentifiers;
return *this;
}

HdContainerDataSourceHandle
HdMaterialNodeSchema::Builder::Build()
{
return HdMaterialNodeSchema::BuildRetained(
_parameters,
_inputConnections,
_nodeIdentifier
_nodeIdentifier,
_renderContextNodeIdentifiers
);
}

Expand Down
24 changes: 23 additions & 1 deletion pxr/imaging/hd/materialNodeSchema.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ PXR_NAMESPACE_OPEN_SCOPE
(parameters) \
(inputConnections) \
(nodeIdentifier) \
(renderContextNodeIdentifiers) \

TF_DECLARE_PUBLIC_TOKENS(HdMaterialNodeSchemaTokens, HD_API,
HDMATERIALNODE_SCHEMA_TOKENS);
Expand All @@ -58,9 +59,25 @@ class HdMaterialNodeSchema : public HdSchema
HdContainerDataSourceHandle GetParameters();
HD_API
HdContainerDataSourceHandle GetInputConnections();

// This identifies the shader the node represents. The
// renderContextNodeIdentifier container can store alternative values for
// this. A consumer which is interested in a specific render context
// should check for that token within renderContextNodeIdentifiers and
// fall back on this value in its absence.
HD_API
HdTokenDataSourceHandle GetNodeIdentifier();

// A shading node can hold a nodeIdentifier value for multiple render
// contexts at once. This allows multiple renderer target representations
// to coexist in the same renderable scene. The contents of this
// container are alternate possible values for nodeIdentifier. A consumer
// which is interested in a specific render context should check for that
// token within this container and fall back on nodeIdentifier in its
// absence.
HD_API
HdContainerDataSourceHandle GetRenderContextNodeIdentifiers();

// RETRIEVING AND CONSTRUCTING

/// Builds a container data source which includes the provided child data
Expand All @@ -73,7 +90,8 @@ class HdMaterialNodeSchema : public HdSchema
BuildRetained(
const HdContainerDataSourceHandle &parameters,
const HdContainerDataSourceHandle &inputConnections,
const HdTokenDataSourceHandle &nodeIdentifier
const HdTokenDataSourceHandle &nodeIdentifier,
const HdContainerDataSourceHandle &renderContextNodeIdentifiers
);

/// \class HdMaterialNodeSchema::Builder
Expand All @@ -94,6 +112,9 @@ class HdMaterialNodeSchema : public HdSchema
HD_API
Builder &SetNodeIdentifier(
const HdTokenDataSourceHandle &nodeIdentifier);
HD_API
Builder &SetRenderContextNodeIdentifiers(
const HdContainerDataSourceHandle &renderContextNodeIdentifiers);

/// Returns a container data source containing the members set thus far.
HD_API
Expand All @@ -103,6 +124,7 @@ class HdMaterialNodeSchema : public HdSchema
HdContainerDataSourceHandle _parameters;
HdContainerDataSourceHandle _inputConnections;
HdTokenDataSourceHandle _nodeIdentifier;
HdContainerDataSourceHandle _renderContextNodeIdentifiers;
};

};
Expand Down
124 changes: 108 additions & 16 deletions pxr/imaging/hd/sceneIndexAdapterSceneDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,7 @@ void
_Walk(
const SdfPath & nodePath,
const HdContainerDataSourceHandle & nodesDS,
const TfTokenVector &renderContexts,
std::unordered_set<SdfPath, SdfPath::Hash> * visitedSet,
HdMaterialNetwork * netHd)
{
Expand All @@ -914,8 +915,34 @@ _Walk(
if (!nodeSchema.IsDefined()) {
return;
}

const TfToken nodeId = nodeSchema.GetNodeIdentifier()->GetTypedValue(0);

TfToken nodeId;
if (HdTokenDataSourceHandle idDs = nodeSchema.GetNodeIdentifier()) {
nodeId = idDs->GetTypedValue(0);
}

// check for render-specific contexts
if (!renderContexts.empty()) {
if (HdContainerDataSourceHandle idsDs =
nodeSchema.GetRenderContextNodeIdentifiers()) {
for (const TfToken &name : renderContexts) {

if (name.IsEmpty() && !nodeId.IsEmpty()) {
break;
}
if (HdTokenDataSourceHandle ds = HdTokenDataSource::Cast(
idsDs->Get(name))) {

const TfToken v = ds->GetTypedValue(0);
if (!v.IsEmpty()) {
nodeId = v;
break;
}
}
}
}
}

HdContainerDataSourceHandle connsDS = nodeSchema.GetInputConnections();
HdContainerDataSourceHandle paramsDS = nodeSchema.GetParameters();

Expand All @@ -941,7 +968,8 @@ _Walk(
TfToken p = connSchema.GetUpstreamNodePath()->GetTypedValue(0);
TfToken n =
connSchema.GetUpstreamNodeOutputName()->GetTypedValue(0);
_Walk(SdfPath(p.GetString()), nodesDS, visitedSet, netHd);
_Walk(SdfPath(p.GetString()), nodesDS, renderContexts,
visitedSet, netHd);

HdMaterialRelationship r;
r.inputId = SdfPath(p.GetString());
Expand Down Expand Up @@ -1041,15 +1069,20 @@ HdSceneIndexAdapterSceneDelegate::GetMaterialResource(SdfPath const & id)
SdfPath path(pathTk.GetString());
matHd.terminals.push_back(path);


TfTokenVector renderContexts =
GetRenderIndex().GetRenderDelegate()->GetMaterialRenderContexts();


// Continue walking the network
HdMaterialNetwork & netHd = matHd.map[name];
_Walk(path, nodesDS, &visitedNodes, &netHd);
_Walk(path, nodesDS, renderContexts, &visitedNodes, &netHd);

// see "includeDisconnectedNodes" above
if (includeDisconnectedNodes && nodesDS) {
for (const TfToken &nodeName : nodesDS->GetNames()) {
_Walk(SdfPath(nodeName.GetString()),
nodesDS, &visitedNodes, &netHd);
nodesDS, renderContexts, &visitedNodes, &netHd);
}
}
}
Expand Down Expand Up @@ -1120,6 +1153,61 @@ HdSceneIndexAdapterSceneDelegate::GetCameraParamValue(
}
}

// Render delegates which retrieve light params (such as "intensity") via
// GetLightParamValue rather than from a light's material resource need to be
// mapped back to the "material" data source for cases when the data is not
// provided by a legacy scene delegate. Because filtering scene indices may
// be modifying the "material" data source value, this mapping can happen only
// when adapting to legacy render delegates.
static
VtValue
_GetLightParamValueFromMaterial(
const HdContainerDataSourceHandle &primDataSource,
TfToken const &paramName)
{

// these appear with "light" data source but are not expected to be within
// a light's shader within a material data source
if (paramName == HdTokens->filters
|| paramName == HdTokens->lightLink
|| paramName == HdTokens->shadowLink
|| paramName == HdTokens->lightFilterLink) {
return VtValue();
}

if (auto mat = HdMaterialSchema::GetFromParent(primDataSource)) {
HdMaterialNetworkSchema network(mat.GetMaterialNetwork());
if (HdContainerDataSourceHandle terminals = network.GetTerminals()) {
if (HdMaterialConnectionSchema connection =
HdMaterialConnectionSchema(
HdContainerDataSource::Cast(
terminals->Get(HdLightSchemaTokens->light)))) {
if (HdTokenDataSourceHandle nodeNameDs =
connection.GetUpstreamNodePath()) {
if (HdContainerDataSourceHandle nodes =
network.GetNodes()) {
if (HdContainerDataSourceHandle params =
HdMaterialNodeSchema(
HdContainerDataSource::Cast(
nodes->Get(
nodeNameDs->GetTypedValue(0.0f)))
).GetParameters()) {

if (auto param = HdSampledDataSource::Cast(
params->Get(paramName))) {

return param->GetValue(0.0f);
}
}
}
}
}
}
}

return VtValue();
}

VtValue
HdSceneIndexAdapterSceneDelegate::GetLightParamValue(
SdfPath const &id, TfToken const &paramName)
Expand All @@ -1131,24 +1219,28 @@ HdSceneIndexAdapterSceneDelegate::GetLightParamValue(
return VtValue();
}

// Prioritize retrieving light parameters from the material and fallback
// on "light" data source.
VtValue result = _GetLightParamValueFromMaterial(prim.dataSource, paramName);

if (!result.IsEmpty()) {
return result;
}

HdContainerDataSourceHandle light =
HdContainerDataSource::Cast(
prim.dataSource->Get(HdLightSchemaTokens->light));
if (!light) {
return VtValue();
}

HdSampledDataSourceHandle valueDs =
HdSampledDataSource::Cast(
light->Get(paramName));
if (!valueDs) {
return VtValue();
if (light) {
HdSampledDataSourceHandle valueDs = HdSampledDataSource::Cast(
light->Get(paramName));
if (valueDs) {
result = valueDs->GetValue(0);
}
}

return valueDs->GetValue(0);
return result;
}


static VtValue
_GetRenderSettings(HdSceneIndexPrim prim, TfToken const &key)
{
Expand Down
1 change: 1 addition & 0 deletions pxr/usdImaging/usdImaging/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ pxr_library(usdImaging
implicitSurfaceMeshUtils
instanceAdapter
lightAdapter
lightAPIAdapter
lightFilterAdapter
materialAdapter
materialBindingAPIAdapter
Expand Down
Loading

0 comments on commit 1f87b7b

Please sign in to comment.