| 1 |
#pragma once |
| 2 |
|
| 3 |
#include <memory> |
| 4 |
#include "iimage.h" |
| 5 |
|
| 6 |
class IRenderEntity; |
| 7 |
|
| 8 |
namespace shaders |
| 9 |
{ |
| 10 |
|
| 11 |
// Material registers, used to store shader expression results |
| 12 |
// The first two slots are always reserved for the constants 0 and 1, see enum ReservedRegisters |
| 13 |
typedef std::vector<float> Registers; |
| 14 |
|
| 15 |
// The indices to the constants in the registers array |
| 16 |
enum ReservedRegisters |
| 17 |
{ |
| 18 |
REG_ZERO = 0, |
| 19 |
REG_ONE = 1, |
| 20 |
NUM_RESERVED_REGISTERS, |
| 21 |
}; |
| 22 |
|
| 23 |
/** |
| 24 |
* A shader expression is something found in a Doom 3 material declaration, |
| 25 |
* where things like shader parameters, time and constants can be combined |
| 26 |
* by mathematical operators and table-lookups. A shader expression can be |
| 27 |
* a constant number in its simplest form, or a complex formula like this: |
| 28 |
* |
| 29 |
* vertexParm 0 0.1 * sintable[time * 0.3], 0.15 * sintable[time * 0.15] |
| 30 |
* |
| 31 |
* The above makes vertex parameter 0 a time-dependent value which is evaluated |
| 32 |
* each frame during rendering. |
| 33 |
* |
| 34 |
* A shader expression can be evaluated which results in a single floating point |
| 35 |
* value. In actual materials the shader expression is linked to a material register |
| 36 |
* where the value is written to after evaluation. |
| 37 |
*/ |
| 38 |
class IShaderExpression |
| 39 |
{ |
| 40 |
public: |
| 41 |
using Ptr = std::shared_ptr<IShaderExpression>; |
| 42 |
|
| 43 |
/** |
| 44 |
* Retrieve the floating point value of this expression. DEPRECATED |
| 45 |
*/ |
| 46 |
virtual float getValue(std::size_t time) = 0; |
| 47 |
|
| 48 |
/** |
| 49 |
* Retrieve the floating point value of this expression. |
| 50 |
*/ |
| 51 |
virtual float getValue(std::size_t time, const IRenderEntity& entity) = 0; |
| 52 |
|
| 53 |
/** |
| 54 |
* Evaluates the value of this expression, writing any results |
| 55 |
* into the linked material register. DEPRECATED |
| 56 |
*/ |
| 57 |
virtual float evaluate(std::size_t time) = 0; |
| 58 |
|
| 59 |
/** |
| 60 |
* Evaluates the value of this expression, writing any results |
| 61 |
* into the linked material register. |
| 62 |
*/ |
| 63 |
virtual float evaluate(std::size_t time, const IRenderEntity& entity) = 0; |
| 64 |
|
| 65 |
/** |
| 66 |
* Link the expression to the given Registers vector. |
| 67 |
* Calling evaluate() will cause the result to be saved into the register. |
| 68 |
* |
| 69 |
* @returns: the register position the result will be written to. |
| 70 |
*/ |
| 71 |
virtual std::size_t linkToRegister(Registers& registers) = 0; |
| 72 |
|
| 73 |
// Link this expression to the given Registers vector, using the specified index |
| 74 |
// instead of allocating a new register |
| 75 |
virtual void linkToSpecificRegister(Registers& registers, std::size_t index) = 0; |
| 76 |
|
| 77 |
// True if this expression is linked to a register |
| 78 |
virtual bool isLinked() const = 0; |
| 79 |
|
| 80 |
// Returns any previously used register position (for possible re-use) |
| 81 |
virtual std::size_t unlinkFromRegisters() = 0; |
| 82 |
|
| 83 |
// Returns the string this expression has been parsed from |
| 84 |
virtual std::string getExpressionString() = 0; |
| 85 |
|
| 86 |
// Clone this expression and all possible sub-expressions |
| 87 |
// The cloned expression will not be linked to any register |
| 88 |
virtual IShaderExpression::Ptr clone() const = 0; |
| 89 |
}; |
| 90 |
|
| 91 |
// Interface of a material expression used to specify a map image |
| 92 |
// It can either represent a texture path to a file on disk or |
| 93 |
// a generated texture like "makeIntensity(lights/intensitymap)" |
| 94 |
class IMapExpression |
| 95 |
{ |
| 96 |
public: |
| 97 |
using Ptr = std::shared_ptr<IMapExpression>; |
| 98 |
|
| 99 |
virtual ~IMapExpression() {} |
| 100 |
|
| 101 |
/** |
| 102 |
* \brief |
| 103 |
* Return whether this map expression creates a cube map. |
| 104 |
* |
| 105 |
* \return |
| 106 |
* true if this map expression creates a cube map, false if it is a single |
| 107 |
* image. |
| 108 |
*/ |
| 109 |
virtual bool isCubeMap() const = 0; |
| 110 |
|
| 111 |
/** |
| 112 |
* Returns the string as parsed from the material source |
| 113 |
*/ |
| 114 |
virtual std::string getExpressionString() = 0; |
| 115 |
}; |
| 116 |
|
| 117 |
class IVideoMapExpression : |
| 118 |
public IMapExpression |
| 119 |
{ |
| 120 |
public: |
| 121 |
virtual ~IVideoMapExpression() {} |
| 122 |
|
| 123 |
// Whether the cinematic is looping |
| 124 |
virtual bool isLooping() const = 0; |
| 125 |
}; |
| 126 |
|
| 127 |
class ISoundMapExpression : |
| 128 |
public IMapExpression |
| 129 |
{ |
| 130 |
public: |
| 131 |
virtual ~ISoundMapExpression() {} |
| 132 |
|
| 133 |
// Whether the sound map should use the waveform display mode |
| 134 |
virtual bool isWaveform() const = 0; |
| 135 |
}; |
| 136 |
|
| 137 |
} // namespace |