HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
material.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_IMAGING_HD_MATERIAL_H
8 #define PXR_IMAGING_HD_MATERIAL_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/imaging/hd/api.h"
12 #include "pxr/imaging/hd/sprim.h"
13 #include "pxr/imaging/hd/types.h"
14 #include "pxr/usd/sdr/declare.h"
15 #include "pxr/base/vt/dictionary.h"
16 
18 
19 ///
20 /// Hydra Schema for a material object.
21 ///
22 class HdMaterial : public HdSprim
23 {
24 public:
25  // change tracking for HdMaterial prim
27  Clean = 0,
28  // XXX: Got to skip varying and force sync bits for now
29  DirtyParams = 1 << 2,
30  DirtyResource = 1 << 3,
31  DirtySurface = 1 << 4,
33  DirtyVolume = 1 << 6,
35  };
36 
37  HD_API
38  ~HdMaterial() override;
39 
40 protected:
41  HD_API
42  HdMaterial(SdfPath const& id);
43 
44 private:
45  // Class can not be default constructed or copied.
46  HdMaterial() = delete;
47  HdMaterial(const HdMaterial &) = delete;
48  HdMaterial &operator =(const HdMaterial &) = delete;
49 };
50 
51 
52 /// \struct HdMaterialRelationship
53 ///
54 /// Describes a connection between two nodes in a material.
55 ///
56 /// A brief discussion of terminology follows:
57 ///
58 /// * Shading nodes have inputs and outputs.
59 /// * Shading nodes consume input values and produce output values.
60 /// * Connections also have inputs and outputs.
61 /// * Connections consume a value from the (\em inputId, \em inputName)
62 /// and pass that value to the (\em outputId, \em outputName).
63 ///
64 /// Note that a connection's input is considered an output on the
65 /// upstream shading node, and the connection's output is an input
66 /// on the downstream shading node.
67 ///
68 /// A guideline to remember this terminology is that inputs
69 /// are always upstream of outputs in the dataflow.
70 ///
72 {
77 };
78 
79 // VtValue requirements
80 HD_API
81 bool operator==(const HdMaterialRelationship& lhs,
82  const HdMaterialRelationship& rhs);
83 
84 
85 /// \struct HdMaterialNode
86 ///
87 /// Describes a material node which is made of a path, an identifier and
88 /// a list of parameters.
90 {
93  std::map<TfToken, VtValue> parameters;
94 };
95 
96 // VtValue requirements
97 HD_API
98 bool operator==(const HdMaterialNode& lhs, const HdMaterialNode& rhs);
99 
100 
101 /// \struct HdMaterialNetwork
102 ///
103 /// Describes a material network composed of nodes, primvars, and relationships
104 /// between the nodes and terminals of those nodes.
106 {
107  std::vector<HdMaterialRelationship> relationships;
108  std::vector<HdMaterialNode> nodes;
110 };
111 
112 /// \struct HdMaterialNetworkMap
113 ///
114 /// Describes a map from network type to network.
116 {
117  std::map<TfToken, HdMaterialNetwork> map;
118  std::vector<SdfPath> terminals;
120 };
121 
122 
123 ///
124 /// HdMaterialNetwork2
125 ///
126 /// This struct replaces the previously used MatfiltNetwork and
127 /// HdSt_MaterialNetwork.
128 /// In the furuture this HdMaterialNetwork2 will replace the current
129 /// HdMaterialNetwork defined above.
130 ///
131 
132 /// \struct HdMaterialConnection2
133 ///
134 /// Describes a single connection to an upsream node and output port
135 /// Replacement for HdMaterialRelationship.
137 {
140 
141  bool operator==(const HdMaterialConnection2 & rhs) const {
142  return upstreamNode == rhs.upstreamNode
143  && upstreamOutputName == rhs.upstreamOutputName;
144  }
145 };
146 
147 /// \struct HdMaterialNode2
148 ///
149 /// Describes an instance of a node within a network
150 /// A node contains a (shader) type identifier, parameter values, and
151 /// connections to upstream nodes. A single input (mapped by TfToken) may have
152 /// multiple upstream connections to describe connected array elements.
154 {
156  std::map<TfToken, VtValue> parameters;
157  std::map<TfToken, std::vector<HdMaterialConnection2>> inputConnections;
158 };
159 
160 /// \struct HdMaterialNetwork2
161 ///
162 /// Container of nodes and top-level terminal connections. This is the mutable
163 /// representation of a shading network sent to filtering functions by a
164 /// MatfiltFilterChain.
166 {
167  std::map<SdfPath, HdMaterialNode2> nodes;
168  std::map<TfToken, HdMaterialConnection2> terminals;
171 
172  bool operator==(const HdMaterialNetwork2 & rhs) const {
173  return nodes == rhs.nodes
174  && terminals == rhs.terminals
175  && primvars == rhs.primvars
176  && config == rhs.config;
177  }
178 };
179 
180 /// Converts a HdMaterialNetworkMap to a HdMaterialNetwork2
181 HD_API
183  const HdMaterialNetworkMap & hdNetworkMap,
184  bool *isVolume = nullptr);
185 
186 /// Extracts HdSamplerParameters from the parameters on the HdMaterialNode2 if
187 /// present. Otherwise extracts the sampler parameters from the SdrNode.
188 HD_API
190  const HdMaterialNode2& node,
191  const SdrShaderNodeConstPtr& sdrNode,
192  const SdfPath& nodePath = SdfPath::EmptyPath());
193 
194 /// Extract HdSamplerParameters from the given parameter map for the given node
195 /// type id. Functionally this works essentially the same as the other
196 /// HdGetSamplerParameters that operates on an HdMaterialNode2, but this allows
197 /// extracting sampler parameters from the map without requiring an
198 /// HdMaterialNode2.
199 HD_API
201  const TfToken& nodeTypeId,
202  const std::map<TfToken, VtValue>& parameters,
203  const SdfPath& nodePath = SdfPath::EmptyPath());
204 
205 // VtValue requirements
206 HD_API
207 std::ostream& operator<<(std::ostream& out, const HdMaterialNetwork& pv);
208 HD_API
209 bool operator==(const HdMaterialNetwork& lhs, const HdMaterialNetwork& rhs);
210 HD_API
211 bool operator!=(const HdMaterialNetwork& lhs, const HdMaterialNetwork& rhs);
212 
213 HD_API
214 std::ostream& operator<<(std::ostream& out,
215  const HdMaterialNetworkMap& pv);
216 HD_API
217 bool operator==(const HdMaterialNetworkMap& lhs,
218  const HdMaterialNetworkMap& rhs);
219 HD_API
220 bool operator!=(const HdMaterialNetworkMap& lhs,
221  const HdMaterialNetworkMap& rhs);
222 
223 // VtValue requirements
224 HD_API
225 std::ostream& operator<<(std::ostream& out, const HdMaterialNode2& pv);
226 HD_API
227 bool operator==(const HdMaterialNode2& lhs, const HdMaterialNode2& rhs);
228 HD_API
229 bool operator!=(const HdMaterialNode2& lhs, const HdMaterialNode2& rhs);
230 
231 
233 
234 #endif // PXR_IMAGING_HD_MATERIAL_H
std::vector< HdMaterialNode > nodes
Definition: material.h:108
HD_API HdSamplerParameters HdGetSamplerParameters(const HdMaterialNode2 &node, const SdrShaderNodeConstPtr &sdrNode, const SdfPath &nodePath=SdfPath::EmptyPath())
TfTokenVector primvars
Definition: material.h:109
HD_API bool operator!=(const HdMaterialNetwork &lhs, const HdMaterialNetwork &rhs)
VtDictionary config
Definition: material.h:170
std::map< SdfPath, HdMaterialNode2 > nodes
Definition: material.h:167
uint32_t HdDirtyBits
Definition: types.h:143
HD_API ~HdMaterial() override
std::vector< SdfPath > terminals
Definition: material.h:118
SdfPath path
Definition: material.h:91
bool operator==(const HdMaterialConnection2 &rhs) const
Definition: material.h:141
#define HD_API
Definition: api.h:23
SdrShaderNode const * SdrShaderNodeConstPtr
Definition: declare.h:51
std::map< TfToken, HdMaterialNetwork > map
Definition: material.h:117
TfTokenVector primvars
Definition: material.h:169
VtDictionary config
Definition: material.h:119
TfToken nodeTypeId
Definition: material.h:155
static SDF_API const SdfPath & EmptyPath()
The empty path value, equivalent to SdfPath().
Definition: token.h:70
std::map< TfToken, VtValue > parameters
Definition: material.h:93
std::map< TfToken, std::vector< HdMaterialConnection2 > > inputConnections
Definition: material.h:157
std::vector< HdMaterialRelationship > relationships
Definition: material.h:107
std::map< TfToken, HdMaterialConnection2 > terminals
Definition: material.h:168
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
Definition: path.h:273
TfToken identifier
Definition: material.h:92
TfToken upstreamOutputName
Definition: material.h:139
Definition: sprim.h:34
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
HD_API HdMaterialNetwork2 HdConvertToHdMaterialNetwork2(const HdMaterialNetworkMap &hdNetworkMap, bool *isVolume=nullptr)
Converts a HdMaterialNetworkMap to a HdMaterialNetwork2.
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
HD_API std::ostream & operator<<(std::ostream &out, const HdMaterialNetwork &pv)
std::map< TfToken, VtValue > parameters
Definition: material.h:156
bool operator==(const HdMaterialNetwork2 &rhs) const
Definition: material.h:172
HD_API bool operator==(const HdMaterialRelationship &lhs, const HdMaterialRelationship &rhs)