TDME2 1.9.121
LightingShaderPBRFoliageImplementation.cpp
Go to the documentation of this file.
2
3#include <string>
4
5#include <tdme/tdme.h>
11#include <tdme/engine/Timing.h>
14
15using std::string;
16using std::to_string;
17
27
28bool LightingShaderPBRFoliageImplementation::isSupported(Renderer* renderer) {
29 return renderer->isPBRAvailable();
30}
31
33{
34}
35
37 return "pbr-foliage";
38}
39
41{
42 auto shaderVersion = renderer->getShaderVersion();
43
44 // lighting
45 // vertex shader
48 "shader/" + shaderVersion + "/lighting/pbr",
49 "render_vertexshader.vert",
50 string() +
51 "#define LIGHT_COUNT " + to_string(Engine::LIGHTS_MAX) + "\n#define USE_PUNCTUAL\n#define MATERIAL_METALLICROUGHNESS\n#define HAVE_FOLIAGE\n#define USE_IBL\n",
52 FileSystem::getInstance()->getContentAsString(
53 "shader/" + shaderVersion + "/functions",
54 "create_rotation_matrix.inc.glsl"
55 ) +
56 "\n\n" +
57 FileSystem::getInstance()->getContentAsString(
58 "shader/" + shaderVersion + "/functions",
59 "create_translation_matrix.inc.glsl"
60 ) +
61 "\n\n" +
62 FileSystem::getInstance()->getContentAsString(
63 "shader/" + shaderVersion + "/functions",
64 "create_foliage_transform_matrix.inc.glsl"
65 ) + "\n\n"
66 );
67 if (vertexShaderId == 0) return;
68
69 // fragment shader
72 "shader/" + shaderVersion + "/lighting/pbr",
73 "render_fragmentshader.frag",
74 string() +
75 "#define LIGHT_COUNT " + to_string(Engine::LIGHTS_MAX) + "\n#define USE_PUNCTUAL\n#define MATERIAL_METALLICROUGHNESS\n#define HAVE_FOLIAGE\n#define USE_IBL\n",
76 FileSystem::getInstance()->getContentAsString(
77 "shader/" + shaderVersion + "/functions/pbr",
78 "tonemapping.inc.glsl"
79 ) +
80 "\n\n" +
81 FileSystem::getInstance()->getContentAsString(
82 "shader/" + shaderVersion + "/functions/pbr",
83 "textures.inc.glsl"
84 ) +
85 "\n\n" +
86 FileSystem::getInstance()->getContentAsString(
87 "shader/" + shaderVersion + "/functions/pbr",
88 "functions.inc.glsl"
89 ) +
90 "\n\n" +
91 FileSystem::getInstance()->getContentAsString(
92 "shader/" + shaderVersion + "/functions/pbr",
93 "pbr_lighting.inc.glsl"
94 ) +
95 "\n\n"
96 );
97 if (fragmentShaderId == 0) return;
98
99 // create, attach and link program
103
104 //
106
107 //
108 if (initialized == false) return;
109
110 //
111 initialized = false;
112
113 // uniforms
115 if (uniformSpeed == -1) return;
117 if (uniformTime == -1) return;
119 if (uniformAmplitudeDefault == -1) return;
121 if (uniformAmplitudeMax == -1) return;
122
123 //
124 initialized = true;
125}
126
129 Engine::ShaderType::SHADERTYPE_OBJECT3D,
130 getId(),
131 {
132 { "speed", ShaderParameter(1.0f) },
133 { "amplitudeDefault", ShaderParameter(0.0f) },
134 { "amplitudeMax", ShaderParameter(20.0f) }
135 }
136 );
137}
138
140{
142
143 // time
144 if (uniformTime != -1) renderer->setProgramUniformFloat(contextIdx, uniformTime, static_cast<float>(engine->getTiming()->getTotalTime()) / 1000.0f);
145}
146
148 auto& shaderParameters = renderer->getShaderParameters(contextIdx);
149 if (uniformSpeed != -1) renderer->setProgramUniformFloat(contextIdx, uniformSpeed, shaderParameters.getShaderParameter("speed").getFloatValue());
150 if (uniformAmplitudeDefault != -1) renderer->setProgramUniformFloat(contextIdx, uniformAmplitudeDefault, shaderParameters.getShaderParameter("amplitudeDefault").getFloatValue());
151 if (uniformAmplitudeMax != -1) renderer->setProgramUniformFloat(contextIdx, uniformAmplitudeMax, shaderParameters.getShaderParameter("amplitudeMax").getFloatValue());
152}
Engine main class.
Definition: Engine.h:122
Timing * getTiming()
Definition: Engine.h:900
static void registerShader(ShaderType type, const string &shaderId, const map< string, ShaderParameter > &parameterDefaults={})
Register shader.
Definition: Engine.cpp:2122
static constexpr int LIGHTS_MAX
Definition: Engine.h:173
TDME2 engine entity shader parameters.
Shader parameter model class.
Timing class.
Definition: Timing.h:17
int64_t getTotalTime()
Definition: Timing.h:61
virtual void useProgram(Engine *engine, int contextIdx) override
Use lighting program.
virtual void useProgram(Engine *engine, int contextIdx) override
Use lighting program.
virtual void updateShaderParameters(Renderer *renderer, int contextIdx) override
Update shader parameters.
virtual int32_t loadShader(int32_t type, const string &pathName, const string &fileName, const string &definitions=string(), const string &functions=string())=0
Loads a shader.
virtual int32_t createProgram(int type)=0
Creates a shader program.
virtual void attachShaderToProgram(int32_t programId, int32_t shaderId)=0
Attaches a shader to a program.
virtual int32_t getProgramUniformLocation(int32_t programId, const string &name)=0
Returns location of given uniform variable.
const EntityShaderParameters & getShaderParameters(int contextIdx)
Get shader parameters.
Definition: Renderer.h:1194
virtual void setProgramUniformFloat(int contextIdx, int32_t uniformId, float value)=0
Set up a float uniform value.
File system singleton class.
Definition: FileSystem.h:14