HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ShaderGraphRefactor.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_SHADERGRAPHREFACTOR_H
7 #define MATERIALX_SHADERGRAPHREFACTOR_H
8 
9 /// @file
10 /// Shader graph refactoring passes
11 
13 
15 
16 class GenContext;
17 class ShaderGraph;
18 
19 /// A shared pointer to a shader graph refactor
20 using ShaderGraphRefactorPtr = shared_ptr<class ShaderGraphRefactor>;
21 
22 /// @class ShaderGraphRefactor
23 /// Base class for shader graph refactoring passes.
24 /// Each pass identifies a structural pattern in the shader graph and
25 /// rewrites it into a mathematically equivalent form better suited
26 /// to the target backend.
28 {
29  public:
30  virtual ~ShaderGraphRefactor() { }
31 
32  /// Return the name of this refactoring pass.
33  virtual const string& getName() const = 0;
34 
35  /// Execute the pass on the given graph.
36  /// Return the number of graph edits made, or zero if
37  /// the pass is not applicable to the current context.
38  virtual size_t execute(ShaderGraph& graph, GenContext& context) = 0;
39 };
40 
41 /// @class NodeElisionRefactor
42 /// Removes constant and dot nodes by bypassing them.
43 /// Constant nodes have their values moved downstream, and
44 /// dot nodes with filename-typed inputs are elided to prevent
45 /// extra samplers.
47 {
48  public:
49  const string& getName() const override;
50  size_t execute(ShaderGraph& graph, GenContext& context) override;
51 };
52 
53 /// @class PremultipliedBsdfAddRefactor
54 /// Replaces BSDF mix nodes with premultiplied add nodes.
55 /// Transforms mix(A, B, w) into add(A*w, B*(1-w)) by folding
56 /// the mix weight into each BSDF's weight input, enabling
57 /// hardware shading languages to skip BSDF evaluation when
58 /// the weight is zero.
60 {
61  public:
62  const string& getName() const override;
63  size_t execute(ShaderGraph& graph, GenContext& context) override;
64 };
65 
66 /// @class DistributeLayerOverMixRefactor
67 /// Distributes layer operations over mix nodes.
68 /// Transforms layer(mix(A, B, w), C) into mix(layer(A, C), layer(B, C), w)
69 /// to satisfy backends that cannot handle a mixed BSDF as the top
70 /// operand of a layer node.
72 {
73  public:
74  const string& getName() const override;
75  size_t execute(ShaderGraph& graph, GenContext& context) override;
76 };
77 
79 
80 #endif
virtual size_t execute(ShaderGraph &graph, GenContext &context)=0
shared_ptr< class ShaderGraphRefactor > ShaderGraphRefactorPtr
A shared pointer to a shader graph refactor.
#define MATERIALX_NAMESPACE_BEGIN
Definition: Generated.h:25
#define MX_GENSHADER_API
Definition: Export.h:18
PXL_API const char * getName(const ColorSpace *space)
Return the name of the color space.
virtual const string & getName() const =0
Return the name of this refactoring pass.
#define MATERIALX_NAMESPACE_END
Definition: Generated.h:26