HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ClosureLayerNodeMdl.h
Go to the documentation of this file.
1 //
2 // Copyright Contributors to the MaterialX Project
3 // SPDX-License-Identifier: Apache-2.0
4 //
5 
6 #ifndef MATERIALX_CLOSURELAYERNODEMDL_H
7 #define MATERIALX_CLOSURELAYERNODEMDL_H
8 
11 
14 
16 
17 /// Holds all constants required by the layering and its transformations.
19 {
20  StringConstantsMdl() = delete;
21 
22  public:
23  /// String constants
24  static const string TOP; ///< layer parameter name of the top component
25  static const string BASE; ///< layer parameter name of the base component
26  static const string FG; ///< parameter of the mix node
27  static const string BG; ///< parameter of the mix node
28  static const string IN1; ///< parameter of the add and multiply nodes
29  static const string IN2; ///< parameter of the add and multiply nodes
30 
31  static const string THICKNESS; ///< thickness parameter name of the thin_film_bsdf
32  static const string IOR; ///< ior parameter name of the thin_film_bsdf
33 
34  static const string THIN_FILM_THICKNESS; ///< helper parameter name for transporting thickness
35  static const string THIN_FILM_IOR; ///< helper parameter name for transporting ior
36 
37  static const string EMPTY; ///< the empty string ""
38 };
39 
40 /// Helper class to be injected into nodes that need to carry thin film parameters from the
41 /// thin_film_bsdf through layers and mixers, etc., to the elemental bsdfs that support thin film.
42 /// Because thin-film can not be layered on any BSDF in MDL, we try to push down the parameters to
43 /// the nodes that support thin-film.
44 template <typename TBase> class CarryThinFilmParameters : public TBase
45 {
46  public:
47  /// Add the thin film inputs for transporting the parameter.
48  /// `addInputs` for the injected base class is called first.
49  void addInputs(ShaderNode& node, GenContext& context) const override
50  {
51  TBase::addInputs(node, context);
54  }
55 
56  /// Mark the thin film parameters as not editable because connections are
57  /// created while emitting the MDL code and the default values should not
58  /// get exposed to the public material interface.
59  bool isEditable(const ShaderInput& input) const override
60  {
63  {
64  return false;
65  }
66  return TBase::isEditable(input);
67  }
68 };
69 
70 /// Closure layer node implementation for MDL.
72 {
73  public:
74  static ShaderNodeImplPtr create();
75 
76  void emitFunctionCall(const ShaderNode& node, GenContext& context, ShaderStage& stage) const override;
77 
78  void emitBsdfOverBsdfFunctionCalls(
79  const ShaderNode& node,
80  GenContext& context,
81  ShaderStage& stage,
82  const ShaderGenerator& shadergen,
83  ShaderNode* top,
84  ShaderNode* base,
85  ShaderOutput* output) const;
86 
87  void emitBsdfOverBsdfFunctionCalls_thinFilm(
88  const ShaderNode& node,
89  GenContext& context,
90  ShaderStage& stage,
91  const ShaderGenerator& shadergen,
92  ShaderNode* top,
93  ShaderNode* base,
94  ShaderOutput* output) const;
95 };
96 
97 /// Layerable BSDF node.
98 /// Because MDL does not support vertical layering the nodes are transformed in a way that
99 /// the base node is passed as parameter to the top layer node.
100 /// Note, not all elemental bsdfs support this kind of transformation.
102 {
103  public:
104  virtual ~LayerableNodeMdl() = default;
105  static ShaderNodeImplPtr create();
106 
107  void addInputs(ShaderNode& node, GenContext&) const override;
108 };
109 
110 /// Used for elemental nodes that can consume thin film.
112 {
114 
115  public:
116  static ShaderNodeImplPtr create();
117 };
118 
119 /// Base class for operators that on bsdfs that need to transport the thin film parameters
120 class ThinFilmCombineNodeMdl : public CarryThinFilmParameters<SourceCodeNodeMdl>
121 {
123 
124  public:
125  virtual ~ThinFilmCombineNodeMdl() = default;
126 
127  void emitFunctionCall(const ShaderNode& node, GenContext& context, ShaderStage& stage) const override;
128 
129  protected:
130  virtual const string& getOperatorName(size_t index) const = 0;
131 };
132 
133 /// Used for mix_bsdf nodes.
135 {
136  public:
137  static ShaderNodeImplPtr create();
138 
139  protected:
140  virtual const string& getOperatorName(size_t index) const final;
141 };
142 
143 /// Used for add_bsdf and multpli_bsdf nodes.
145 {
146  public:
147  static ShaderNodeImplPtr create();
148 
149  protected:
150  virtual const string& getOperatorName(size_t index) const final;
151 };
152 
154 
155 #endif
const string & getName() const
Return the name of this port.
Definition: ShaderNode.h:150
Holds all constants required by the layering and its transformations.
shared_ptr< ShaderNodeImpl > ShaderNodeImplPtr
Shared pointer to a ShaderNodeImpl.
Definition: Library.h:40
#define MATERIALX_NAMESPACE_BEGIN
Definition: Generated.h:25
#define MX_GENMDL_API
Definition: Export.h:18
static const string IN1
parameter of the add and multiply nodes
static const string IOR
ior parameter name of the thin_film_bsdf
static ShaderNodeImplPtr create()
ShaderInput * addInput(const string &name, const TypeDesc *type)
Add inputs/outputs.
virtual const string & getOperatorName(size_t index) const =0
static const string THIN_FILM_IOR
helper parameter name for transporting ior
static const string THICKNESS
thickness parameter name of the thin_film_bsdf
Used for mix_bsdf nodes.
virtual ~ThinFilmCombineNodeMdl()=default
static const string BG
parameter of the mix node
virtual void addInputs(ShaderNode &node, GenContext &context) const
Add additional inputs on a node.
static const string IN2
parameter of the add and multiply nodes
void emitFunctionCall(const ShaderNode &node, GenContext &context, ShaderStage &stage) const override
Emit the function call or inline source code for given node instance in the given context...
static const string BASE
layer parameter name of the base component
void addInputs(ShaderNode &node, GenContext &context) const override
Base class for operators that on bsdfs that need to transport the thin film parameters.
Used for elemental nodes that can consume thin film.
Closure layer node implementation for MDL.
GLuint index
Definition: glcorearb.h:786
static const string FG
parameter of the mix node
static const string EMPTY
the empty string ""
GLdouble GLdouble GLdouble top
Definition: glad.h:2817
MX_GENSHADER_API const TypeDesc * FLOAT
Definition: ImfPixelType.h:24
#define MATERIALX_NAMESPACE_END
Definition: Generated.h:26
static const string THIN_FILM_THICKNESS
helper parameter name for transporting thickness
bool isEditable(const ShaderInput &input) const override
static const string TOP
String constants.
Used for add_bsdf and multpli_bsdf nodes.