/
ishaderexpression.h
100 lines (85 loc) · 2.83 KB
/
ishaderexpression.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
#pragma once
#include <memory>
#include "iimage.h"
class IRenderEntity;
namespace shaders
{
// Material registers, used to store shader expression results
// The first two slots are always reserved for the constants 0 and 1, see enum ReservedRegisters
typedef std::vector<float> Registers;
// The indices to the constants in the registers array
enum ReservedRegisters
{
REG_ZERO = 0,
REG_ONE = 1,
NUM_RESERVED_REGISTERS,
};
/**
* A shader expression is something found in a Doom 3 material declaration,
* where things like shader parameters, time and constants can be combined
* by mathematical operators and table-lookups. A shader expression can be
* a constant number in its simplest form, or a complex formula like this:
*
* vertexParm 0 0.1 * sintable[time * 0.3], 0.15 * sintable[time * 0.15]
*
* The above makes vertex parameter 0 a time-dependent value which is evaluated
* each frame during rendering.
*
* A shader expression can be evaluated which results in a single floating point
* value. In actual materials the shader expression is linked to a material register
* where the value is written to after evaluation.
*/
class IShaderExpression
{
public:
/**
* Retrieve the floating point value of this expression. DEPRECATED
*/
virtual float getValue(std::size_t time) = 0;
/**
* Retrieve the floating point value of this expression.
*/
virtual float getValue(std::size_t time, const IRenderEntity& entity) = 0;
/**
* Evaluates the value of this expression, writing any results
* into the linked material register. DEPRECATED
*/
virtual float evaluate(std::size_t time) = 0;
/**
* Evaluates the value of this expression, writing any results
* into the linked material register.
*/
virtual float evaluate(std::size_t time, const IRenderEntity& entity) = 0;
/**
* Link the expression to the given Registers vector.
* Calling evaluate() will cause the result to be saved into the register.
*
* @returns: the register position the result will be written to.
*/
virtual std::size_t linkToRegister(Registers& registers) = 0;
};
typedef std::shared_ptr<IShaderExpression> IShaderExpressionPtr;
// Interface of a material expression used to specify a map image
// It can either represent a texture path to a file on disk or
// a generated texture like "makeIntensity(lights/intensitymap)"
class IMapExpression
{
public:
using Ptr = std::shared_ptr<IMapExpression>;
virtual ~IMapExpression() {}
/**
* \brief
* Construct and return the image created from this map expression.
*/
virtual ImagePtr getImage() const = 0;
/**
* \brief
* Return whether this map expression creates a cube map.
*
* \return
* true if this map expression creates a cube map, false if it is a single
* image.
*/
virtual bool isCubeMap() const = 0;
};
} // namespace