MaterialX 1.38.2
GlslShaderGenerator.h
Go to the documentation of this file.
1//
2// TM & (c) 2017 Lucasfilm Entertainment Company Ltd. and Lucasfilm Ltd.
3// All rights reserved. See LICENSE.txt for license.
4//
5
6#ifndef MATERIALX_GLSLSHADERGENERATOR_H
7#define MATERIALX_GLSLSHADERGENERATOR_H
8
11
13
15
16namespace MaterialX
17{
18
19using GlslShaderGeneratorPtr = shared_ptr<class GlslShaderGenerator>;
20
23class MX_GENGLSL_API GlslShaderGenerator : public HwShaderGenerator
24{
25 public:
27
28 static ShaderGeneratorPtr create() { return std::make_shared<GlslShaderGenerator>(); }
29
32 ShaderPtr generate(const string& name, ElementPtr element, GenContext& context) const override;
33
35 const string& getTarget() const override { return TARGET; }
36
38 virtual const string& getVersion() const { return VERSION; }
39
41 void emitFunctionDefinitions(const ShaderGraph& graph, GenContext& context, ShaderStage& stage) const override;
42
44 void emitFunctionCalls(const ShaderGraph& graph, GenContext& context, ShaderStage& stage) const override;
45
47 void emitVariableDeclaration(const ShaderPort* variable, const string& qualifier, GenContext& context, ShaderStage& stage,
48 bool assignValue = true) const override;
49
51 virtual const string getVertexDataPrefix(const VariableBlock& vertexData) const;
52
53 public:
55 static const string TARGET;
56
58 static const string VERSION;
59
60 protected:
61 virtual void emitVertexStage(const ShaderGraph& graph, GenContext& context, ShaderStage& stage) const;
62 virtual void emitPixelStage(const ShaderGraph& graph, GenContext& context, ShaderStage& stage) const;
63
64 virtual void emitDirectives(GenContext& context, ShaderStage& stage) const;
65 virtual void emitConstants(GenContext& context, ShaderStage& stage) const;
66 virtual void emitUniforms(GenContext& context, ShaderStage& stage) const;
67 virtual void emitLightData(GenContext& context, ShaderStage& stage) const;
68 virtual void emitInputs(GenContext& context, ShaderStage& stage) const;
69 virtual void emitOutputs(GenContext& context, ShaderStage& stage) const;
70
71 virtual HwResourceBindingContextPtr getResourceBindingContext(GenContext& context) const;
72
76 virtual bool requiresLighting(const ShaderGraph& graph) const;
77
79 virtual void emitSpecularEnvironment(GenContext& context, ShaderStage& stage) const;
80
82 ShaderNodeImplPtr createCompoundImplementation(const NodeGraph& impl) const override;
83
84 static void toVec4(const TypeDesc* type, string& variable);
85
87 vector<ShaderNodePtr> _lightSamplingNodes;
88};
89
90
92class MX_GENGLSL_API GlslImplementation : public ShaderNodeImpl
93{
94 public:
95 const string& getTarget() const override;
96
97 bool isEditable(const ShaderInput& input) const override;
98
99 protected:
101
102 // Integer identifiers for corrdinate spaces
103 // The order must match the order given for
104 // the space enum string in stdlib.
105 enum Space
106 {
107 MODEL_SPACE = 0,
108 OBJECT_SPACE = 1,
109 WORLD_SPACE = 2
110 };
111
113 static const string SPACE;
114 static const string TO_SPACE;
115 static const string FROM_SPACE;
116 static const string WORLD;
117 static const string OBJECT;
118 static const string MODEL;
119 static const string INDEX;
120 static const string GEOMPROP;
121};
122
123} // namespace MaterialX
124
125#endif
shared_ptr< Element > ElementPtr
A shared pointer to an Element.
Definition: Element.h:31
Hardware shader generator base class.
shared_ptr< class HwResourceBindingContext > HwResourceBindingContextPtr
Shared pointer to a HwResourceBindingContext.
Definition: HwShaderGenerator.h:235
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
A context class for shader generation.
Definition: GenContext.h:27
Base class for common GLSL node implementations.
Definition: GlslShaderGenerator.h:93
static const string SPACE
Internal string constants.
Definition: GlslShaderGenerator.h:113
Base class for GLSL (OpenGL Shading Language) code generation.
Definition: GlslShaderGenerator.h:24
const string & getTarget() const override
Return a unique identifier for the target this generator is for.
Definition: GlslShaderGenerator.h:35
virtual const string & getVersion() const
Return the version string for the GLSL version this generator is for.
Definition: GlslShaderGenerator.h:38
vector< ShaderNodePtr > _lightSamplingNodes
Nodes used internally for light sampling.
Definition: GlslShaderGenerator.h:87
static const string TARGET
Unique identifier for this generator target.
Definition: GlslShaderGenerator.h:55
static const string VERSION
Version string for the generator target.
Definition: GlslShaderGenerator.h:58
Base class for shader generators targeting HW rendering.
Definition: HwShaderGenerator.h:356
A node graph element within a Document.
Definition: Node.h:316
Class representing a graph (DAG) for shader generation.
Definition: ShaderGraph.h:45
An input on a ShaderNode.
Definition: ShaderNode.h:256
Class handling the shader generation implementation for a node.
Definition: ShaderNodeImpl.h:32
An input or output port on a ShaderNode.
Definition: ShaderNode.h:125
A shader stage, containing the state and resulting source code for the stage.
Definition: ShaderStage.h:124
A type descriptor for MaterialX data types.
Definition: TypeDesc.h:29
A block of variables in a shader stage.
Definition: ShaderStage.h:53