MaterialX 1.39.1
Loading...
Searching...
No Matches
MdlShaderGenerator.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_MDLSHADERGENERATOR_H
7#define MATERIALX_MDLSHADERGENERATOR_H
8
11
13
15
16MATERIALX_NAMESPACE_BEGIN
17
19class MX_GENMDL_API GenMdlOptions : public GenUserData
20{
21 public:
23 enum class MdlVersion
24 {
25 MDL_1_6,
26 MDL_1_7,
27 MDL_1_8,
28 MDL_LATEST = MDL_1_8
29 };
30
33 targetVersion(MdlVersion::MDL_LATEST) { }
34
36 static const string GEN_CONTEXT_USER_DATA_KEY;
37
42};
43
45using GenMdlOptionsPtr = shared_ptr<class GenMdlOptions>;
46
48using MdlShaderGeneratorPtr = shared_ptr<class MdlShaderGenerator>;
49
52class MX_GENMDL_API MdlShaderGenerator : public ShaderGenerator
53{
54 public:
56
57 static ShaderGeneratorPtr create() { return std::make_shared<MdlShaderGenerator>(); }
58
60 const string& getTarget() const override { return TARGET; }
61
64 ShaderPtr generate(const string& name, ElementPtr element, GenContext& context) const override;
65
68 ShaderNodeImplPtr getImplementation(const NodeDef& nodedef, GenContext& context) const override;
69
71 string getUpstreamResult(const ShaderInput* input, GenContext& context) const override;
72
74 static const string TARGET;
75
77 static const std::unordered_map<string, string> GEOMPROP_DEFINITIONS;
78
80 void emitMdlVersionNumber(GenContext& context, ShaderStage& stage) const;
81
84
86 const string& getMdlVersionFilenameSuffix(GenContext& context) const;
87
88 protected:
89 // Create and initialize a new MDL shader for shader generation.
90 ShaderPtr createShader(const string& name, ElementPtr element, GenContext& context) const;
91
92 // Emit a block of shader inputs.
93 void emitShaderInputs(const DocumentPtr doc, const VariableBlock& inputs, ShaderStage& stage) const;
94};
95
96namespace MDL
97{
98
99// Identifiers for MDL variable blocks
100extern MX_GENMDL_API const string INPUTS;
101extern MX_GENMDL_API const string OUTPUTS;
102
103} // namespace MDL
104
105MATERIALX_NAMESPACE_END
106
107#endif
shared_ptr< Document > DocumentPtr
A shared pointer to a Document.
Definition: Document.h:22
shared_ptr< Element > ElementPtr
A shared pointer to an Element.
Definition: Element.h:31
Macros for declaring imported and exported symbols.
shared_ptr< Shader > ShaderPtr
Shared pointer to a Shader.
Definition: Library.h:34
shared_ptr< ShaderNodeImpl > ShaderNodeImplPtr
Shared pointer to a ShaderNodeImpl.
Definition: Library.h:40
shared_ptr< ShaderGenerator > ShaderGeneratorPtr
Shared pointer to a ShaderGenerator.
Definition: Library.h:38
MX_RENDER_API ShaderPtr createShader(const string &shaderName, GenContext &context, ElementPtr elem)
Create a shader for a given element.
shared_ptr< class MdlShaderGenerator > MdlShaderGeneratorPtr
Shared pointer to an MdlShaderGenerator.
Definition: MdlShaderGenerator.h:48
shared_ptr< class GenMdlOptions > GenMdlOptionsPtr
Shared pointer to GenMdlOptions.
Definition: MdlShaderGenerator.h:45
Base shader generator class.
A context class for shader generation.
Definition: GenContext.h:31
Generator context data class to pass strings.
Definition: MdlShaderGenerator.h:20
GenMdlOptions()
Create MDL code generator options with default values.
Definition: MdlShaderGenerator.h:32
MdlVersion targetVersion
The MDL version number the generated module will have.
Definition: MdlShaderGenerator.h:41
MdlVersion
MDL Versions supported by the Code Generator.
Definition: MdlShaderGenerator.h:24
static const string GEN_CONTEXT_USER_DATA_KEY
Unique identifier for the MDL options on the GenContext object.
Definition: MdlShaderGenerator.h:36
Base class for custom user data needed during shader generation.
Definition: GenUserData.h:27
Shader generator for MDL (Material Definition Language).
Definition: MdlShaderGenerator.h:53
const string & getTarget() const override
Return a unique identifier for the target this generator is for.
Definition: MdlShaderGenerator.h:60
static const string TARGET
Unique identifier for this generator target.
Definition: MdlShaderGenerator.h:74
ShaderPtr generate(const string &name, ElementPtr element, GenContext &context) const override
Generate a shader starting from the given element, translating the element and all dependencies upstr...
void emitMdlVersionNumber(GenContext &context, ShaderStage &stage) const
Add the MDL file header containing the version number of the generated module..
void emitMdlVersionFilenameSuffix(GenContext &context, ShaderStage &stage) const
Add the version number suffix appended to MDL modules that use versions.
static const std::unordered_map< string, string > GEOMPROP_DEFINITIONS
Map of code snippets for geomprops in MDL.
Definition: MdlShaderGenerator.h:77
ShaderNodeImplPtr getImplementation(const NodeDef &nodedef, GenContext &context) const override
Return a registered shader node implementation given an implementation element.
const string & getMdlVersionFilenameSuffix(GenContext &context) const
Get the version number suffix appended to MDL modules that use versions.
string getUpstreamResult(const ShaderInput *input, GenContext &context) const override
Return the result of an upstream connection or value for an input.
A node definition element within a Document.
Definition: Definition.h:82
Base class for shader generators All third-party shader generators should derive from this class.
Definition: ShaderGenerator.h:31
An input on a ShaderNode.
Definition: ShaderNode.h:264
A shader stage, containing the state and resulting source code for the stage.
Definition: ShaderStage.h:139
A block of variables in a shader stage.
Definition: ShaderStage.h:61