MaterialX 1.39.1
Loading...
Searching...
No Matches
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
11
12#include <MaterialXCore/Generated.h>
17#include <MaterialXRender/Camera.h>
19
20#include <memory>
21
22MATERIALX_NAMESPACE_BEGIN
23
24using MaterialPtr = std::shared_ptr<class ShaderMaterial>;
25
28class MX_RENDER_API ShadowState
29{
30 public:
31 ImagePtr shadowMap;
32 Matrix44 shadowMatrix;
33 ImagePtr ambientOcclusionMap;
34 float ambientOcclusionGain = 0.0f;
35};
36
39class MX_RENDER_API ShaderMaterial
40{
41 public:
43 virtual ~ShaderMaterial();
44
47
50
53
56
59
62
64 void setUdim(const std::string& val);
65
67 const std::string& getUdim();
68
70 virtual bool loadSource(const FilePath& vertexShaderFile,
71 const FilePath& pixelShaderFile,
72 bool hasTransparency) = 0;
73
76 virtual bool generateShader(GenContext& context) = 0;
77
79 virtual void copyShader(MaterialPtr ShaderMaterial) = 0;
80
82 virtual bool generateShader(ShaderPtr hwShader) = 0;
83
86 const FilePath& filename,
87 DocumentPtr stdLib,
88 const FilePath& imagePath);
89
92
94 bool hasTransparency() const;
95
97 virtual bool bindShader() const = 0;
98
100 virtual void bindViewInformation(CameraPtr camera) = 0;
101
103 virtual void bindImages(ImageHandlerPtr imageHandler,
104 const FileSearchPath& searchPath,
105 bool enableMipmaps = true) = 0;
106
108 virtual void unbindImages(ImageHandlerPtr imageHandler) = 0;
109
111 virtual ImagePtr bindImage(const FilePath& filePath,
112 const std::string& uniformName,
113 ImageHandlerPtr imageHandler,
114 const ImageSamplingProperties& samplingProperties) = 0;
115
117 virtual void bindLighting(LightHandlerPtr lightHandler,
118 ImageHandlerPtr imageHandler,
119 const ShadowState& shadowState) = 0;
120
122 virtual void bindMesh(MeshPtr mesh) = 0;
123
125 virtual bool bindPartition(MeshPartitionPtr part) const = 0;
126
128 virtual void drawPartition(MeshPartitionPtr part) const = 0;
129
131 virtual void unbindGeometry() = 0;
132
134 virtual VariableBlock* getPublicUniforms() const = 0;
135
137 virtual ShaderPort* findUniform(const std::string& path) const = 0;
138
140 virtual void modifyUniform(const std::string& path,
141 ConstValuePtr value,
142 std::string valueString = EMPTY_STRING) = 0;
143
144 protected:
145 virtual void clearShader() = 0;
146
147 protected:
148 ShaderPtr _hwShader;
149 MeshPtr _boundMesh;
150
151 DocumentPtr _doc;
152 TypedElementPtr _elem;
153 NodePtr _materialNode;
154
155 std::string _udim;
156 bool _hasTransparency;
157
158 ImageVec _boundImages;
159};
160
161MATERIALX_NAMESPACE_END
162
163#endif
shared_ptr< Document > DocumentPtr
A shared pointer to a Document.
Definition: Document.h:22
shared_ptr< TypedElement > TypedElementPtr
A shared pointer to a TypedElement.
Definition: Element.h:36
Image class.
std::vector< ImagePtr > ImageVec
A vetor of images.
Definition: Image.h:32
shared_ptr< Image > ImagePtr
A shared pointer to an image.
Definition: Image.h:23
Image handler interfaces.
std::shared_ptr< ImageHandler > ImageHandlerPtr
Shared pointer to an ImageHandler.
Definition: ImageHandler.h:32
Handler for hardware lights.
std::shared_ptr< class LightHandler > LightHandlerPtr
Shared pointer to a LightHandler.
Definition: LightHandler.h:25
shared_ptr< Shader > ShaderPtr
Shared pointer to a Shader.
Definition: Library.h:34
Mesh interfaces.
shared_ptr< class MeshPartition > MeshPartitionPtr
Shared pointer to a mesh partition.
Definition: Mesh.h:146
shared_ptr< class Mesh > MeshPtr
Shared pointer to a mesh.
Definition: Mesh.h:230
shared_ptr< Node > NodePtr
A shared pointer to a Node.
Definition: Node.h:24
Unit system classes.
shared_ptr< const Value > ConstValuePtr
A shared pointer to a const Value.
Definition: Value.h:31
A generic file path, supporting both syntactic and file system operations.
Definition: File.h:27
A sequence of file paths, which may be queried to find the first instance of a given filename on the ...
Definition: File.h:219
A context class for shader generation.
Definition: GenContext.h:31
Interface to describe sampling properties for images.
Definition: ImageHandler.h:43
A 4x4 matrix of floating-point values.
Definition: Types.h:656
Abstract class for shader generation and rendering of a ShaderMaterial.
Definition: ShaderMaterial.h:40
virtual void unbindImages(ImageHandlerPtr imageHandler)=0
Unbbind all images for this ShaderMaterial.
bool hasTransparency() const
Return true if this ShaderMaterial has transparency.
virtual bool generateShader(ShaderPtr hwShader)=0
Generate a shader from the given hardware shader.
void setUdim(const std::string &val)
Set udim identifier.
virtual void bindMesh(MeshPtr mesh)=0
Bind the given mesh to this ShaderMaterial.
void setDocument(DocumentPtr doc)
Set the renderable element associated with this ShaderMaterial.
virtual bool generateShader(GenContext &context)=0
Generate a shader from our currently stored element and the given generator context.
virtual bool bindShader() const =0
Bind shader.
virtual bool loadSource(const FilePath &vertexShaderFile, const FilePath &pixelShaderFile, bool hasTransparency)=0
Load shader source from file.
void setElement(TypedElementPtr val)
Set the renderable element associated with this ShaderMaterial.
virtual ImagePtr bindImage(const FilePath &filePath, const std::string &uniformName, ImageHandlerPtr imageHandler, const ImageSamplingProperties &samplingProperties)=0
Bind a single image.
virtual void bindLighting(LightHandlerPtr lightHandler, ImageHandlerPtr imageHandler, const ShadowState &shadowState)=0
Bind lights to shader.
virtual void bindViewInformation(CameraPtr camera)=0
Bind viewing information for this ShaderMaterial.
TypedElementPtr getElement() const
Return the renderable element associated with this ShaderMaterial.
virtual bool generateEnvironmentShader(GenContext &context, const FilePath &filename, DocumentPtr stdLib, const FilePath &imagePath)
Generate an environment background shader.
virtual VariableBlock * getPublicUniforms() const =0
Return the block of public uniforms for this ShaderMaterial.
virtual bool bindPartition(MeshPartitionPtr part) const =0
Bind a mesh partition to this ShaderMaterial.
virtual void copyShader(MaterialPtr ShaderMaterial)=0
Copies shader and API specific generated program from ShaderMaterial to this one.
virtual void modifyUniform(const std::string &path, ConstValuePtr value, std::string valueString=EMPTY_STRING)=0
Modify the value of the uniform with the given path.
virtual void unbindGeometry()=0
Unbind all geometry from this ShaderMaterial.
DocumentPtr getDocument() const
Return the document associated with this ShaderMaterial.
virtual void bindImages(ImageHandlerPtr imageHandler, const FileSearchPath &searchPath, bool enableMipmaps=true)=0
Bind all images for this ShaderMaterial.
const std::string & getUdim()
Get any associated udim identifier.
ShaderPtr getShader() const
Return the underlying hardware shader.
virtual ShaderPort * findUniform(const std::string &path) const =0
Find a public uniform from its MaterialX path.
void setMaterialNode(NodePtr node)
Set the ShaderMaterial node associated with this ShaderMaterial.
NodePtr getMaterialNode() const
Return the ShaderMaterial node associated with this ShaderMaterial.
virtual void drawPartition(MeshPartitionPtr part) const =0
Draw the given mesh partition.
An input or output port on a ShaderNode.
Definition: ShaderNode.h:123
Helper class representing shadow rendering state.
Definition: ShaderMaterial.h:29
A block of variables in a shader stage.
Definition: ShaderStage.h:61