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 Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_IMAGING_HD_MATERIAL_H
25 #define PXR_IMAGING_HD_MATERIAL_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hd/api.h"
29 #include "pxr/imaging/hd/sprim.h"
30 
32 
33 ///
34 /// Hydra Schema for a material object.
35 ///
36 class HdMaterial : public HdSprim
37 {
38 public:
39  // change tracking for HdMaterial prim
41  Clean = 0,
42  // XXX: Got to skip varying and force sync bits for now
43  DirtyParams = 1 << 2,
44  DirtyResource = 1 << 3,
46  };
47 
48  HD_API
49  ~HdMaterial() override;
50 
51 protected:
52  HD_API
53  HdMaterial(SdfPath const& id);
54 
55 private:
56  // Class can not be default constructed or copied.
57  HdMaterial() = delete;
58  HdMaterial(const HdMaterial &) = delete;
59  HdMaterial &operator =(const HdMaterial &) = delete;
60 };
61 
62 
63 /// \struct HdMaterialRelationship
64 ///
65 /// Describes a connection between two nodes in a material.
66 ///
67 /// A brief discussion of terminology follows:
68 ///
69 /// * Shading nodes have inputs and outputs.
70 /// * Shading nodes consume input values and produce output values.
71 /// * Connections also have inputs and outputs.
72 /// * Connections consume a value from the (\em inputId, \em inputName)
73 /// and pass that value to the (\em outputId, \em outputName).
74 ///
75 /// Note that a connection's input is considered an output on the
76 /// upstream shading node, and the connection's output is an input
77 /// on the downstream shading node.
78 ///
79 /// A guideline to remember this terminology is that inputs
80 /// are always upstream of outputs in the dataflow.
81 ///
83 {
88 };
89 
90 // VtValue requirements
91 HD_API
92 bool operator==(const HdMaterialRelationship& lhs,
93  const HdMaterialRelationship& rhs);
94 
95 
96 /// \struct HdMaterialNode
97 ///
98 /// Describes a material node which is made of a path, an identifier and
99 /// a list of parameters.
101 {
104  std::map<TfToken, VtValue> parameters;
105 };
106 
107 // VtValue requirements
108 HD_API
109 bool operator==(const HdMaterialNode& lhs, const HdMaterialNode& rhs);
110 
111 
112 /// \struct HdMaterialNetwork
113 ///
114 /// Describes a material network composed of nodes, primvars, and relationships
115 /// between the nodes and terminals of those nodes.
117 {
118  std::vector<HdMaterialRelationship> relationships;
119  std::vector<HdMaterialNode> nodes;
121 };
122 
123 /// \struct HdMaterialNetworkMap
124 ///
125 /// Describes a map from network type to network.
127 {
128  std::map<TfToken, HdMaterialNetwork> map;
129  std::vector<SdfPath> terminals;
130 };
131 
132 
133 ///
134 /// HdMaterialNetwork2
135 ///
136 /// This struct replaces the previously used MatfiltNetwork and
137 /// HdSt_MaterialNetwork.
138 /// In the furuture this HdMaterialNetwork2 will replace the current
139 /// HdMaterialNetwork defined above.
140 ///
141 
142 /// \struct HdMaterialConnection2
143 ///
144 /// Describes a single connection to an upsream node and output port
145 /// Replacement for HdMaterialRelationship.
147 {
150 
151  bool operator==(const HdMaterialConnection2 & rhs) const {
152  return upstreamNode == rhs.upstreamNode
153  && upstreamOutputName == rhs.upstreamOutputName;
154  }
155 };
156 
157 /// \struct HdMaterialNode2
158 ///
159 /// Describes an instance of a node within a network
160 /// A node contains a (shader) type identifier, parameter values, and
161 /// connections to upstream nodes. A single input (mapped by TfToken) may have
162 /// multiple upstream connections to describe connected array elements.
164 {
166  std::map<TfToken, VtValue> parameters;
167  std::map<TfToken, std::vector<HdMaterialConnection2>> inputConnections;
168 };
169 
170 /// \struct HdMaterialNetwork2
171 ///
172 /// Container of nodes and top-level terminal connections. This is the mutable
173 /// representation of a shading network sent to filtering functions by a
174 /// MatfiltFilterChain.
176 {
177  std::map<SdfPath, HdMaterialNode2> nodes;
178  std::map<TfToken, HdMaterialConnection2> terminals;
180 
181  bool operator==(const HdMaterialNetwork2 & rhs) const {
182  return nodes == rhs.nodes
183  && terminals == rhs.terminals
184  && primvars == rhs.primvars;
185  }
186 };
187 
188 /// Converts a HdMaterialNetworkMap to a HdMaterialNetwork2
189 HD_API
191  const HdMaterialNetworkMap & hdNetworkMap,
192  bool *isVolume = nullptr);
193 
194 
195 // VtValue requirements
196 HD_API
197 std::ostream& operator<<(std::ostream& out, const HdMaterialNetwork& pv);
198 HD_API
199 bool operator==(const HdMaterialNetwork& lhs, const HdMaterialNetwork& rhs);
200 HD_API
201 bool operator!=(const HdMaterialNetwork& lhs, const HdMaterialNetwork& rhs);
202 
203 HD_API
204 std::ostream& operator<<(std::ostream& out,
205  const HdMaterialNetworkMap& pv);
206 HD_API
207 bool operator==(const HdMaterialNetworkMap& lhs,
208  const HdMaterialNetworkMap& rhs);
209 HD_API
210 bool operator!=(const HdMaterialNetworkMap& lhs,
211  const HdMaterialNetworkMap& rhs);
212 
213 // VtValue requirements
214 HD_API
215 std::ostream& operator<<(std::ostream& out, const HdMaterialNode2& pv);
216 HD_API
217 bool operator==(const HdMaterialNode2& lhs, const HdMaterialNode2& rhs);
218 HD_API
219 bool operator!=(const HdMaterialNode2& lhs, const HdMaterialNode2& rhs);
220 
221 
223 
224 #endif // PXR_IMAGING_HD_MATERIAL_H
std::vector< HdMaterialNode > nodes
Definition: material.h:119
TfTokenVector primvars
Definition: material.h:120
HD_API bool operator!=(const HdMaterialNetwork &lhs, const HdMaterialNetwork &rhs)
std::map< SdfPath, HdMaterialNode2 > nodes
Definition: material.h:177
uint32_t HdDirtyBits
Definition: types.h:158
HD_API ~HdMaterial() override
std::vector< SdfPath > terminals
Definition: material.h:129
SdfPath path
Definition: material.h:102
bool operator==(const HdMaterialConnection2 &rhs) const
Definition: material.h:151
#define HD_API
Definition: api.h:40
std::map< TfToken, HdMaterialNetwork > map
Definition: material.h:128
TfTokenVector primvars
Definition: material.h:179
TfToken nodeTypeId
Definition: material.h:165
Definition: token.h:87
std::map< TfToken, VtValue > parameters
Definition: material.h:104
std::map< TfToken, std::vector< HdMaterialConnection2 > > inputConnections
Definition: material.h:167
std::vector< HdMaterialRelationship > relationships
Definition: material.h:118
std::map< TfToken, HdMaterialConnection2 > terminals
Definition: material.h:178
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:442
Definition: path.h:291
TfToken identifier
Definition: material.h:103
TfToken upstreamOutputName
Definition: material.h:149
Definition: sprim.h:51
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
HD_API HdMaterialNetwork2 HdConvertToHdMaterialNetwork2(const HdMaterialNetworkMap &hdNetworkMap, bool *isVolume=nullptr)
Converts a HdMaterialNetworkMap to a HdMaterialNetwork2.
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
HD_API std::ostream & operator<<(std::ostream &out, const HdMaterialNetwork &pv)
std::map< TfToken, VtValue > parameters
Definition: material.h:166
bool operator==(const HdMaterialNetwork2 &rhs) const
Definition: material.h:181
HD_API bool operator==(const HdMaterialRelationship &lhs, const HdMaterialRelationship &rhs)