![]() |
|
In the context of Sdr, a "shader" is any program that takes input and produces output.
Sdr provides a framework in which you can register shader nodes with Sdr, and subsequently ask for information about those nodes. Additionally, shader node parsing and "discovery" are done via plugins to keep Sdr extendable.
If this is your first time working with Sdr, we recommend you read the SdrShaderProperty Types section to understand some implicit behaviors.
Sdr can be split into 5 major components, as described by the following subsections.
The core Sdr registry, SdrRegistry
, is where shader node-level queries are done. Upon initialization, the registry searches for all parser and discovery plugins. During this start-up phase the discovery plugins are all run, but the nodes that are found are NOT parsed. The registry parses nodes on demand when information about a node(s) is requested in order to keep the start-up process as fast as possible.
The type of information that the Sdr registry provides includes:
Sdr provides a node class, SdrShaderNode
, which exposes information such as:
An SdrShaderNode represents a dataflow-connectable computation, intended to be a node in a computational network. A node's SdrShaderProperty's represent its computational inputs and outputs, and its URI's identify its external sources:
Sdr also provides a property class, SdrShaderProperty
. Inputs and outputs are on a node are collectively identified as "properties".
The shader property exposes information like:
Discovery plugins are how the shader registry finds (or "discovers") shader nodes. The registry makes no assumptions on where, or how, nodes are stored. A discovery plugin can be built to find file-based nodes on the filesystem (a typical case), search a database, a cloud service, or any other system that might contain nodes. If nodes are scattered across multiple systems, a discovery plugin can be created for each. More info about discovery plugins is available in the SdrDiscoveryPlugin
documentation.
Note that a filesystem-based discovery plugin is active by default. More information on how to configure this plugin can be found in the documentation for _SdrFilesystemDiscoveryPlugin
. In a nutshell, there are a few environment variables that can be configured to control its behavior. However, the more robust pattern that any renderer or shading-system plugin should follow is to provide its own DiscoveryPlugin, so that its configuration will not interfere with that of other plugins. The filesystem discovery machinery that the builtin _SdrFilesystemDiscoveryPlugin
plugin uses is available for other discovery plugins to use - see SdrFsHelpersDiscoverShaderNodes().
Once the registry knows about shader nodes via the discovery plugin(s), the parser plugins parse the nodes and provide the registry with the resulting information. The parser plugins are responsible for information such as the node's type, its metadata, and all information about its inputs and outputs. In the end, the parser plugin is responsible for determining all information about the node that could not otherwise be determined via the discovery plugin. More information about parser plugins is available in the SdrParserPlugin
documentation.
See the documentation for SdrDiscoveryPlugin
for more information.
See the documentation for SdrParserPlugin
for more information.
A SdrShaderProperty's type is described using the given SdrPropertyType token, as well as SdrShaderProperty::GetArraySize(), if SdrShaderProperty::IsDynamicArray() is true. SdrPropertyType tokens are defined here.
For whether a SdrShaderProperty can connect to another SdrShaderProperty based on its type, see the implementation of SdrShaderProperty::CanConnectTo
. SdrShaderProperty connectability has more flexibility than a simple type equivalence check does; for example, a property of type SdrPropertyTypes->Color can connect to another property of type SdrPropertyTypes->Vector because they both represent a "Float3".
Sdr defines a limited set of types with SdrPropertyType tokens. These types correspond to certain SdfValueTypeNames. There are two levels of type determination described below.
Metadata-based controls may modify each type determination step. Each step is detailed in sections below.
The SdrPropertyType is not written out to a USD layer, but with the aid of other information and metadata gathered from a node's shader definition, the SdrPropertyType is mapped to an SdfValueTypeName that is written into USD layers. The SdfValueTypeNames are a much richer and wider set of types, and it is this type that is looked at during opinion composition.
Clients writing SdrParserPlugin sub-classes for Sdr need only be concerned with a property's SdrPropertyType. Sdr will handle the details of assigning the correct SdfValueTypeName.
If the property's 'role' metadata is 'none', this triggers automatic SdrPropertyType transformation during SdrShaderProperty construction time. The SdrPropertyType will be transformed to be as generic as possible. For example, if a property of original SdrPropertyTypes->Color has 'role' specified as 'none', then the property will actually become SdrPropertyTypes->Float with an arraysize of 3.
See this map for all property construction-time type transformations from 'none' roles.
SdfValueTypeName conversion is governed by these conversion maps and is triggered by call to SdrShaderProperty::GetTypeAsSdfType.
However, the presence of some metadata on SdrShaderProperty alters conversion. Metadata that is used for SdfValueTypeName conversion is authored either by shader writers (SdrUsdDefinitionName), or it should be injected into an SdrShaderProperty by a parser plugin writer (IsAssetIdentifier).
Three types are specific to Sdr and have no corresponding SdfValueTypeName.
These special types have no reasonable corresponding SdfValueTypeName, so we map them to SdfValueTypeName->Token, which is typically reserved for an Unknown type.
Traditional methods of accessing type information will give incomplete info for the above special cases, for example: SdrShaderProperty::GetType
returns a "struct" token without indicating what kind of struct it represents, and SdrShaderProperty::GetTypeAsSdfType().GetSdfType
returns SdfValueTypeNames->Token
, which is even more ambiguous than "struct".
Therefore to provide more complete type info, the 'renderType' metadata should be authored when creating a SdrShaderProperty with one of the above special types.
A user can find the original struct type or terminal type of one of these properties by examining the 'renderType' metadata on the property directly.
In the above example, the properties would be translated as follows:
Property | SdrPropertyType | SdfValueTypeName |
---|---|---|
foo | SdrPropertyTypes->Color | SdfValueTypeNames->Color |
bar | SdrPropertyTypes->String | SdfValueTypeNames->String |
surface | SdrPropertyTypes->Terminal | SdfValueTypeNames->Token |