forked from autodesk-forks/MaterialX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGlslShaderGenerator.h
117 lines (86 loc) · 4.05 KB
/
GlslShaderGenerator.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//
// TM & (c) 2017 Lucasfilm Entertainment Company Ltd. and Lucasfilm Ltd.
// All rights reserved. See LICENSE.txt for license.
//
#ifndef MATERIALX_GLSLSHADERGENERATOR_H
#define MATERIALX_GLSLSHADERGENERATOR_H
/// @file
/// GLSL shader generator
#include <MaterialXGenShader/HwShaderGenerator.h>
namespace MaterialX
{
using GlslShaderGeneratorPtr = shared_ptr<class GlslShaderGenerator>;
/// Base class for GLSL (OpenGL Shading Language) code generation.
/// A generator for a specific GLSL target should be derived from this class.
class GlslShaderGenerator : public HwShaderGenerator
{
public:
GlslShaderGenerator();
static ShaderGeneratorPtr create() { return std::make_shared<GlslShaderGenerator>(); }
/// Generate a shader starting from the given element, translating
/// the element and all dependencies upstream into shader code.
ShaderPtr generate(const string& name, ElementPtr element, GenContext& context) const override;
/// Return a unique identifier for the language used by this generator
const string& getLanguage() const override { return LANGUAGE; }
/// Return a unique identifier for the target this generator is for
const string& getTarget() const override { return TARGET; }
/// Return the version string for the GLSL version this generator is for
virtual const string& getVersion() const { return VERSION; }
/// Emit function definitions for all nodes
void emitFunctionDefinitions(const ShaderGraph& graph, GenContext& context, ShaderStage& stage) const override;
/// Emit all functon calls constructing the shader body
void emitFunctionCalls(const ShaderGraph& graph, GenContext& context, ShaderStage& stage) const override;
/// Emit a shader variable.
void emitVariableDeclaration(const ShaderPort* variable, const string& qualifier, GenContext& context, ShaderStage& stage,
bool assignValue = true) const override;
/// Given an input specification attempt to remap this to an enumeration which is accepted by
/// the shader generator. The enumeration may be converted to a different type than the input.
bool remapEnumeration(const ValueElement& input, const string& value, std::pair<const TypeDesc*, ValuePtr>& result) const override;
public:
/// Unique identifier for the glsl language
static const string LANGUAGE;
/// Unique identifier for this generator target
static const string TARGET;
/// Version string for the generator target
static const string VERSION;
protected:
virtual void emitVertexStage(const ShaderGraph& graph, GenContext& context, ShaderStage& stage) const;
virtual void emitPixelStage(const ShaderGraph& graph, GenContext& context, ShaderStage& stage) const;
/// Emit specular environment lookup code
void emitSpecularEnvironment(GenContext& context, ShaderStage& stage) const;
/// Override the compound implementation creator in order to handle light compounds.
ShaderNodeImplPtr createCompoundImplementation(const NodeGraph& impl) const override;
static void toVec4(const TypeDesc* type, string& variable);
/// Nodes used internally for light sampling.
vector<ShaderNodePtr> _lightSamplingNodes;
};
/// Base class for common GLSL node implementations
class GlslImplementation : public ShaderNodeImpl
{
public:
const string& getLanguage() const override;
const string& getTarget() const override;
bool isEditable(const ShaderInput& input) const override;
protected:
GlslImplementation() {}
// Integer identifiers for corrdinate spaces
// The order must match the order given for
// the space enum string in stdlib.
enum Space
{
MODEL_SPACE = 0,
OBJECT_SPACE = 1,
WORLD_SPACE = 2
};
/// Internal string constants
static const string SPACE;
static const string TO_SPACE;
static const string FROM_SPACE;
static const string WORLD;
static const string OBJECT;
static const string MODEL;
static const string INDEX;
static const string GEOMPROP;
};
} // namespace MaterialX
#endif