TDME2 1.9.121
LightingShaderFoliageImplementation.cpp
Go to the documentation of this file.
2
3#include <string>
4
5#include <tdme/tdme.h>
9
12
13using std::string;
14using std::to_string;
15
23
24bool LightingShaderFoliageImplementation::isSupported(Renderer* renderer) {
25 return true;
26}
27
29{
30}
31
33 return "foliage";
34}
35
37{
38 auto shaderVersion = renderer->getShaderVersion();
39
40 // lighting
41 // vertex shader
44 "shader/" + shaderVersion + "/lighting/specular",
45 "render_vertexshader.vert",
46 "#define LIGHT_COUNT " + to_string(Engine::LIGHTS_MAX) + "\n#define HAVE_FOLIAGE\n#define HAVE_DEPTH_FOG",
47 FileSystem::getInstance()->getContentAsString(
48 "shader/" + shaderVersion + "/functions",
49 "create_rotation_matrix.inc.glsl"
50 ) +
51 "\n\n" +
52 FileSystem::getInstance()->getContentAsString(
53 "shader/" + shaderVersion + "/functions",
54 "create_translation_matrix.inc.glsl"
55 ) +
56 "\n\n" +
57 FileSystem::getInstance()->getContentAsString(
58 "shader/" + shaderVersion + "/functions",
59 "create_foliage_transform_matrix.inc.glsl"
60 )
61 );
62 if (vertexShaderId == 0) return;
63
64 // fragment shader
67 "shader/" + shaderVersion + "/lighting/specular",
68 "render_fragmentshader.frag",
69 "#define LIGHT_COUNT " + to_string(Engine::LIGHTS_MAX) + "\n#define HAVE_DEPTH_FOG",
70 FileSystem::getInstance()->getContentAsString(
71 "shader/" + shaderVersion + "/functions/specular",
72 "specular_lighting.inc.glsl"
73 )
74 );
75 if (fragmentShaderId == 0) return;
76
77 // create, attach and link program
81
82 //
84
85 // uniforms
89}
90
93 Engine::ShaderType::SHADERTYPE_OBJECT3D,
94 getId(),
95 {
96 { "speed", ShaderParameter(1.0f) },
97 { "amplitudeDefault", ShaderParameter(0.0f) },
98 { "amplitudeMax", ShaderParameter(20.0f) }
99 }
100 );
101}
102
104 auto& shaderParameters = renderer->getShaderParameters(contextIdx);
105 if (uniformSpeed != -1) renderer->setProgramUniformFloat(contextIdx, uniformSpeed, shaderParameters.getShaderParameter("speed").getFloatValue());
106 if (uniformAmplitudeDefault != -1) renderer->setProgramUniformFloat(contextIdx, uniformAmplitudeDefault, shaderParameters.getShaderParameter("amplitudeDefault").getFloatValue());
107 if (uniformAmplitudeMax != -1) renderer->setProgramUniformFloat(contextIdx, uniformAmplitudeMax, shaderParameters.getShaderParameter("amplitudeMax").getFloatValue());
108}
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.
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