HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HwShaderGenerator.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_HWSHADERGENERATOR_H
7 #define MATERIALX_HWSHADERGENERATOR_H
8 
9 /// @file
10 /// Hardware shader generator base class
11 
12 #include <MaterialXGenHw/Export.h>
13 
16 
17 // These headers below are not required for inclusion here
18 // they are included as an affordance to backwards compatibility
19 // during the refactor transition - The next breaking API point
20 // we should remove them
25 
27 
28 class HwShaderGenerator;
29 /// Shared pointer to a HwShaderGenerator
30 using HwShaderGeneratorPtr = shared_ptr<class HwShaderGenerator>;
31 
32 /// @class HwShaderGenerator
33 /// Base class for shader generators targeting HW rendering.
35 {
36  public:
37  /// Emit code for active light count definitions and uniforms
38  virtual void addStageLightingUniforms(GenContext& context, ShaderStage& stage) const;
39 
40  /// Return true if the node needs the ClosureData struct added
41  bool nodeNeedsClosureData(const ShaderNode& node) const override;
42 
43  void emitClosureDataArg(const ShaderNode& node, GenContext& context, ShaderStage& stage) const override;
44  void emitClosureDataParameter(const ShaderNode& node, GenContext& context, ShaderStage& stage) const override;
45 
46  /// Apply the default GenOptions for hardware shader generation.
47  void applyDefaultOptions(GenOptions& options) const override;
48 
49  /// Logic to indicate whether code to support direct lighting should be emitted.
50  /// By default if the graph is classified as a shader, or BSDF node then lighting is assumed to be required.
51  /// Derived classes can override this logic.
52  virtual bool requiresLighting(const ShaderGraph& graph) const;
53 
54  /// Bind a light shader to a light type id, for usage in surface shaders created
55  /// by the generator. The lightTypeId should be a unique identifier for the light
56  /// type (node definition) and the same id should be used when setting light parameters on a
57  /// generated surface shader.
58  static void bindLightShader(const NodeDef& nodeDef, unsigned int lightTypeId, GenContext& context);
59 
60  /// Unbind a light shader previously bound to the given light type id.
61  static void unbindLightShader(unsigned int lightTypeId, GenContext& context);
62 
63  /// Unbind all light shaders previously bound.
64  static void unbindLightShaders(GenContext& context);
65 
66  /// Determine the prefix of vertex data variables.
67  virtual string getVertexDataPrefix(const VariableBlock& vertexData) const = 0;
68 
69  /// Create the shader node implementation for a NodeGraph implementation.
70  ShaderNodeImplPtr createShaderNodeImplForNodeGraph(const NodeGraph& nodegraph) const override;
71 
72  // Note : the order must match the order defined in libraries/pbrlib/genglsl/lib/mx_closure_type.glsl
73  // TODO : investigate build time mechanism for ensuring these stay in sync.
74 
75  /// Types of closure contexts for HW.
77  {
84  CLOSURE
85  };
86 
87  protected:
88  HwShaderGenerator(TypeSystemPtr typeSystem, SyntaxPtr syntax);
89 
90  /// Create and initialize a new HW shader for shader generation.
91  virtual ShaderPtr createShader(const string& name, ElementPtr element, GenContext& context) const;
92 
93  void toVec4(TypeDesc type, string& variable) const;
94 };
95 
97 
98 #endif
virtual ShaderNodeImplPtr createShaderNodeImplForNodeGraph(const NodeGraph &nodegraph) const
Create the shader node implementation for a NodeGraph implementation.
ClosureContextType
Types of closure contexts for HW.
shared_ptr< ShaderNodeImpl > ShaderNodeImplPtr
Shared pointer to a ShaderNodeImpl.
Definition: Library.h:39
virtual bool nodeNeedsClosureData(const ShaderNode &) const
Return true if the node needs the additional ClosureData added.
#define MATERIALX_NAMESPACE_BEGIN
Definition: Generated.h:25
shared_ptr< class HwShaderGenerator > HwShaderGeneratorPtr
Shared pointer to a HwShaderGenerator.
shared_ptr< Syntax > SyntaxPtr
Shared pointer to a Syntax.
Definition: Syntax.h:28
shared_ptr< class TypeSystem > TypeSystemPtr
Definition: TypeDesc.h:219
virtual void applyDefaultOptions(GenOptions &options) const
Apply the default GenOptions for this generator's target.
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
virtual void emitClosureDataArg(const ShaderNode &, GenContext &, ShaderStage &) const
GLuint const GLchar * name
Definition: glcorearb.h:786
virtual void emitClosureDataParameter(const ShaderNode &, GenContext &, ShaderStage &) const
MX_RENDER_API ShaderPtr createShader(const string &shaderName, GenContext &context, ElementPtr elem)
Create a shader for a given element.
shared_ptr< Shader > ShaderPtr
Shared pointer to a Shader.
Definition: Library.h:33
shared_ptr< Element > ElementPtr
A shared pointer to an Element.
Definition: Element.h:31
#define MATERIALX_NAMESPACE_END
Definition: Generated.h:26
#define MX_GENHW_API
Definition: Export.h:18