HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ShaderMaterial.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_RENDER_SHADER_MATERIAL_H
7 #define MATERIALX_RENDER_SHADER_MATERIAL_H
8 
9 /// @file
10 /// ShaderMaterial helper classes
11 
13 #include <MaterialXRender/Image.h>
14 #include <MaterialXRender/Mesh.h>
17 #include <MaterialXRender/Camera.h>
19 
20 #include <memory>
21 
23 
24 using MaterialPtr = std::shared_ptr<class ShaderMaterial>;
25 
26 /// @class ShadowState
27 /// Helper class representing shadow rendering state
29 {
30  public:
34  float ambientOcclusionGain = 0.0f;
35 };
36 
37 /// @class ShaderMaterial
38 /// Abstract class for shader generation and rendering of a ShaderMaterial
40 {
41  public:
43  virtual ~ShaderMaterial();
44 
45  /// Set the renderable element associated with this ShaderMaterial
46  void setDocument(DocumentPtr doc);
47 
48  /// Return the document associated with this ShaderMaterial
49  DocumentPtr getDocument() const;
50 
51  /// Set the renderable element associated with this ShaderMaterial
52  void setElement(TypedElementPtr val);
53 
54  /// Return the renderable element associated with this ShaderMaterial
55  TypedElementPtr getElement() const;
56 
57  /// Set the ShaderMaterial node associated with this ShaderMaterial
58  void setMaterialNode(NodePtr node);
59 
60  /// Return the ShaderMaterial node associated with this ShaderMaterial
61  NodePtr getMaterialNode() const;
62 
63  /// Set udim identifier
64  void setUdim(const std::string& val);
65 
66  /// Get any associated udim identifier
67  const std::string& getUdim();
68 
69  /// Load shader source from file.
70  virtual bool loadSource(const FilePath& vertexShaderFile,
71  const FilePath& pixelShaderFile,
72  bool hasTransparency) = 0;
73 
74  /// Generate a shader from our currently stored element and
75  /// the given generator context.
76  virtual bool generateShader(GenContext& context) = 0;
77 
78  /// Copies shader and API specific generated program from ShaderMaterial to this one.
79  virtual void copyShader(MaterialPtr ShaderMaterial) = 0;
80 
81  /// Generate a shader from the given hardware shader.
82  virtual bool generateShader(ShaderPtr hwShader) = 0;
83 
84  /// Generate an environment background shader
85  virtual bool generateEnvironmentShader(GenContext& context,
86  const FilePath& filename,
87  DocumentPtr stdLib,
88  const FilePath& imagePath);
89 
90  /// Return the underlying hardware shader.
91  ShaderPtr getShader() const;
92 
93  /// Return true if this ShaderMaterial has transparency.
94  bool hasTransparency() const;
95 
96  /// Bind shader
97  virtual bool bindShader() const = 0;
98 
99  /// Bind viewing information for this ShaderMaterial.
100  virtual void bindViewInformation(CameraPtr camera) = 0;
101 
102  /// Bind all images for this ShaderMaterial.
103  virtual void bindImages(ImageHandlerPtr imageHandler,
104  const FileSearchPath& searchPath,
105  bool enableMipmaps = true) = 0;
106 
107  /// Unbbind all images for this ShaderMaterial.
108  virtual void unbindImages(ImageHandlerPtr imageHandler) = 0;
109 
110  /// Bind a single image.
111  virtual ImagePtr bindImage(const FilePath& filePath,
112  const std::string& uniformName,
113  ImageHandlerPtr imageHandler,
114  const ImageSamplingProperties& samplingProperties) = 0;
115 
116  /// Bind lights to shader.
117  virtual void bindLighting(LightHandlerPtr lightHandler,
118  ImageHandlerPtr imageHandler,
119  const ShadowState& shadowState) = 0;
120 
121  /// Bind the given mesh to this ShaderMaterial.
122  virtual void bindMesh(MeshPtr mesh) = 0;
123 
124  /// Bind a mesh partition to this ShaderMaterial.
125  virtual bool bindPartition(MeshPartitionPtr part) const = 0;
126 
127  /// Draw the given mesh partition.
128  virtual void drawPartition(MeshPartitionPtr part) const = 0;
129 
130  /// Unbind all geometry from this ShaderMaterial.
131  virtual void unbindGeometry() = 0;
132 
133  /// Return the block of public uniforms for this ShaderMaterial.
134  virtual VariableBlock* getPublicUniforms() const = 0;
135 
136  /// Find a public uniform from its MaterialX path.
137  virtual ShaderPort* findUniform(const std::string& path) const = 0;
138 
139  /// Modify the value of the uniform with the given path.
140  virtual void modifyUniform(const std::string& path,
142  std::string valueString = EMPTY_STRING) = 0;
143 
144  protected:
145  virtual void clearShader() = 0;
146 
147  protected:
150 
154 
157 
159 };
160 
162 
163 #endif
shared_ptr< class Mesh > MeshPtr
Shared pointer to a mesh.
Definition: Mesh.h:230
std::shared_ptr< class Camera > CameraPtr
Shared pointer to a Camera.
Definition: Camera.h:14
GT_API const UT_StringHolder filename
ImagePtr shadowMap
Definition: File.h:26
#define MATERIALX_NAMESPACE_BEGIN
Definition: Generated.h:25
shared_ptr< class MeshPartition > MeshPartitionPtr
Shared pointer to a mesh partition.
Definition: Mesh.h:146
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
shared_ptr< const Value > ConstValuePtr
A shared pointer to a const Value.
Definition: Value.h:31
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
std::vector< ImagePtr > ImageVec
A vetor of images.
Definition: Image.h:32
shared_ptr< TypedElement > TypedElementPtr
A shared pointer to a TypedElement.
Definition: Element.h:36
MATERIALX_NAMESPACE_BEGIN MX_CORE_API const string EMPTY_STRING
NodePtr _materialNode
ShaderPtr _hwShader
TypedElementPtr _elem
ImageVec _boundImages
std::shared_ptr< class LightHandler > LightHandlerPtr
Shared pointer to a LightHandler.
Definition: LightHandler.h:25
std::string _udim
ImagePtr ambientOcclusionMap
std::shared_ptr< ImageHandler > ImageHandlerPtr
Shared pointer to an ImageHandler.
Definition: ImageHandler.h:32
DocumentPtr _doc
shared_ptr< Document > DocumentPtr
A shared pointer to a Document.
Definition: Document.h:22
#define MX_RENDER_API
Definition: Export.h:18
Matrix44 shadowMatrix
GLuint GLfloat * val
Definition: glcorearb.h:1608
shared_ptr< Shader > ShaderPtr
Shared pointer to a Shader.
Definition: Library.h:34
Definition: core.h:1131
#define MATERIALX_NAMESPACE_END
Definition: Generated.h:26
std::shared_ptr< class ShaderMaterial > MaterialPtr
shared_ptr< Image > ImagePtr
A shared pointer to an image.
Definition: Image.h:23
GLuint GLsizei GLsizei GLchar * uniformName
Definition: glcorearb.h:1464
shared_ptr< Node > NodePtr
A shared pointer to a Node.
Definition: Node.h:24