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 #include "pxr/imaging/hd/types.h"
31 #include "pxr/usd/sdr/declare.h"
32 
34 
35 ///
36 /// Hydra Schema for a material object.
37 ///
38 class HdMaterial : public HdSprim
39 {
40 public:
41  // change tracking for HdMaterial prim
43  Clean = 0,
44  // XXX: Got to skip varying and force sync bits for now
45  DirtyParams = 1 << 2,
46  DirtyResource = 1 << 3,
48  };
49 
50  HD_API
51  ~HdMaterial() override;
52 
53 protected:
54  HD_API
55  HdMaterial(SdfPath const& id);
56 
57 private:
58  // Class can not be default constructed or copied.
59  HdMaterial() = delete;
60  HdMaterial(const HdMaterial &) = delete;
61  HdMaterial &operator =(const HdMaterial &) = delete;
62 };
63 
64 
65 /// \struct HdMaterialRelationship
66 ///
67 /// Describes a connection between two nodes in a material.
68 ///
69 /// A brief discussion of terminology follows:
70 ///
71 /// * Shading nodes have inputs and outputs.
72 /// * Shading nodes consume input values and produce output values.
73 /// * Connections also have inputs and outputs.
74 /// * Connections consume a value from the (\em inputId, \em inputName)
75 /// and pass that value to the (\em outputId, \em outputName).
76 ///
77 /// Note that a connection's input is considered an output on the
78 /// upstream shading node, and the connection's output is an input
79 /// on the downstream shading node.
80 ///
81 /// A guideline to remember this terminology is that inputs
82 /// are always upstream of outputs in the dataflow.
83 ///
85 {
90 };
91 
92 // VtValue requirements
93 HD_API
94 bool operator==(const HdMaterialRelationship& lhs,
95  const HdMaterialRelationship& rhs);
96 
97 
98 /// \struct HdMaterialNode
99 ///
100 /// Describes a material node which is made of a path, an identifier and
101 /// a list of parameters.
103 {
106  std::map<TfToken, VtValue> parameters;
107 };
108 
109 // VtValue requirements
110 HD_API
111 bool operator==(const HdMaterialNode& lhs, const HdMaterialNode& rhs);
112 
113 
114 /// \struct HdMaterialNetwork
115 ///
116 /// Describes a material network composed of nodes, primvars, and relationships
117 /// between the nodes and terminals of those nodes.
119 {
120  std::vector<HdMaterialRelationship> relationships;
121  std::vector<HdMaterialNode> nodes;
123 };
124 
125 /// \struct HdMaterialNetworkMap
126 ///
127 /// Describes a map from network type to network.
129 {
130  std::map<TfToken, HdMaterialNetwork> map;
131  std::vector<SdfPath> terminals;
132 };
133 
134 
135 ///
136 /// HdMaterialNetwork2
137 ///
138 /// This struct replaces the previously used MatfiltNetwork and
139 /// HdSt_MaterialNetwork.
140 /// In the furuture this HdMaterialNetwork2 will replace the current
141 /// HdMaterialNetwork defined above.
142 ///
143 
144 /// \struct HdMaterialConnection2
145 ///
146 /// Describes a single connection to an upsream node and output port
147 /// Replacement for HdMaterialRelationship.
149 {
152 
153  bool operator==(const HdMaterialConnection2 & rhs) const {
154  return upstreamNode == rhs.upstreamNode
155  && upstreamOutputName == rhs.upstreamOutputName;
156  }
157 };
158 
159 /// \struct HdMaterialNode2
160 ///
161 /// Describes an instance of a node within a network
162 /// A node contains a (shader) type identifier, parameter values, and
163 /// connections to upstream nodes. A single input (mapped by TfToken) may have
164 /// multiple upstream connections to describe connected array elements.
166 {
168  std::map<TfToken, VtValue> parameters;
169  std::map<TfToken, std::vector<HdMaterialConnection2>> inputConnections;
170 };
171 
172 /// \struct HdMaterialNetwork2
173 ///
174 /// Container of nodes and top-level terminal connections. This is the mutable
175 /// representation of a shading network sent to filtering functions by a
176 /// MatfiltFilterChain.
178 {
179  std::map<SdfPath, HdMaterialNode2> nodes;
180  std::map<TfToken, HdMaterialConnection2> terminals;
182 
183  bool operator==(const HdMaterialNetwork2 & rhs) const {
184  return nodes == rhs.nodes
185  && terminals == rhs.terminals
186  && primvars == rhs.primvars;
187  }
188 };
189 
190 /// Converts a HdMaterialNetworkMap to a HdMaterialNetwork2
191 HD_API
193  const HdMaterialNetworkMap & hdNetworkMap,
194  bool *isVolume = nullptr);
195 
196 /// Extracts HdSamplerParameters from the parameters on the HdMaterialNode2 if
197 /// present. Otherwise extracts the sampler parameters from the SdrNode.
198 HD_API
200  const SdfPath& nodePath,
201  const HdMaterialNode2& node,
202  const SdrShaderNodeConstPtr& sdrNode);
203 
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:121
TfTokenVector primvars
Definition: material.h:122
HD_API bool operator!=(const HdMaterialNetwork &lhs, const HdMaterialNetwork &rhs)
std::map< SdfPath, HdMaterialNode2 > nodes
Definition: material.h:179
uint32_t HdDirtyBits
Definition: types.h:158
HD_API ~HdMaterial() override
std::vector< SdfPath > terminals
Definition: material.h:131
SdfPath path
Definition: material.h:104
bool operator==(const HdMaterialConnection2 &rhs) const
Definition: material.h:153
#define HD_API
Definition: api.h:40
HD_API HdSamplerParameters HdGetSamplerParameters(const SdfPath &nodePath, const HdMaterialNode2 &node, const SdrShaderNodeConstPtr &sdrNode)
SdrShaderNode const * SdrShaderNodeConstPtr
Definition: declare.h:44
std::map< TfToken, HdMaterialNetwork > map
Definition: material.h:130
TfTokenVector primvars
Definition: material.h:181
TfToken nodeTypeId
Definition: material.h:167
Definition: token.h:87
std::map< TfToken, VtValue > parameters
Definition: material.h:106
std::map< TfToken, std::vector< HdMaterialConnection2 > > inputConnections
Definition: material.h:169
std::vector< HdMaterialRelationship > relationships
Definition: material.h:120
std::map< TfToken, HdMaterialConnection2 > terminals
Definition: material.h:180
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:457
Definition: path.h:290
TfToken identifier
Definition: material.h:105
TfToken upstreamOutputName
Definition: material.h:151
Definition: sprim.h:51
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
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:168
bool operator==(const HdMaterialNetwork2 &rhs) const
Definition: material.h:183
HD_API bool operator==(const HdMaterialRelationship &lhs, const HdMaterialRelationship &rhs)