TDME2  1.9.200
PostProcessingShaderVignetteImplementation.cpp
Go to the documentation of this file.
1 #include <string>
2 
3 #include <tdme/tdme.h>
7 #include <tdme/engine/Color4.h>
8 #include <tdme/engine/Engine.h>
10 #include <tdme/math/Vector3.h>
11 
12 using std::string;
13 
20 
21 bool PostProcessingShaderVignetteImplementation::isSupported(Renderer* renderer) {
22  return renderer->getShaderVersion() == "gl3";
23 }
24 
26 {
27 }
28 
30 {
31  auto shaderVersion = renderer->getShaderVersion();
32 
33  // fragment shader
36  "shader/" + shaderVersion + "/postprocessing",
37  "vignette_fragmentshader.frag",
38  Engine::is4K() == true?"#define HAVE_4K":""
39  );
40  if (fragmentShaderId == 0) return;
41 
42  // vertex shader
45  "shader/" + shaderVersion + "/postprocessing",
46  "vignette_vertexshader.vert"
47  );
48  if (vertexShaderId == 0) return;
49 
50  // create, attach and link program
54 
55  //
57 
58  // uniforms
61 
62  //
63  if (initialized == false) return;
64 
65  // register shader
67  Engine::ShaderType::SHADERTYPE_POSTPROCESSING,
68  "vignette",
69  {
70  { "intensity", ShaderParameter(0.0f), ShaderParameter(0.0f), ShaderParameter(1.0f), ShaderParameter(0.05f) },
71  { "borderColor", ShaderParameter(Color4(1.0f, 1.0f, 1.0f, 1.0f)), ShaderParameter(Color4(0.0f, 0.0f, 0.0f, 1.0f)), ShaderParameter(Color4(1.0f, 1.0f, 1.0f, 1.0f)), ShaderParameter(Color4(0.05f, 0.05f, 0.05f, 0.0f)) }
72  }
73  );
74 }
75 
77  if (uniformIntensity != -1) renderer->setProgramUniformFloat(contextIdx, uniformIntensity, engine->getShaderParameter("vignette", "intensity").getFloatValue());
78  if (uniformBorderColor != -1) renderer->setProgramUniformFloatVec3(contextIdx, uniformBorderColor, engine->getShaderParameter("vignette", "borderColor").getColor3ValueArray());
79 }
Color 4 definition class.
Definition: Color4.h:18
Engine main class.
Definition: Engine.h:131
const ShaderParameter getShaderParameter(const string &shaderId, const string &parameterName)
Returns shader parameter for given shader id and parameter name, if the value does not exist,...
Definition: Engine.h:941
static void registerShader(ShaderType type, const string &shaderId, const vector< Shader::ParameterDefaults > &parameterDefaults={}, bool internal=false)
Register shader.
Definition: Engine.h:856
static bool is4K()
Definition: Engine.h:685
Shader parameter model class.
const array< float, 3 > getColor3ValueArray() const
virtual void setShaderParameters(int contextIdx, Engine *engine) override
Set 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.
virtual void setProgramUniformFloatVec3(int contextIdx, int32_t uniformId, const array< float, 3 > &data)=0
Set up a float vec3 uniform value.
virtual void setProgramUniformFloat(int contextIdx, int32_t uniformId, float value)=0
Set up a float uniform value.
Vector3 class representing vector3 mathematical structure and operations with x, y,...
Definition: Vector3.h:20