TDME2 1.9.121
PostProcessingShaderSSAOMapImplementation.cpp
Go to the documentation of this file.
1#include <array>
2#include <string>
3
4#include <tdme/tdme.h>
11#include <tdme/engine/Engine.h>
12#include <tdme/math/Vector3.h>
13
14using std::array;
15using std::string;
16using std::to_string;
17
25
26bool PostProcessingShaderSSAOMapImplementation::isSupported(Renderer* renderer) {
27 return renderer->getShaderVersion() == "gl3";
28}
29
31{
32}
33
35{
36 auto shaderVersion = renderer->getShaderVersion();
37
38 // fragment shader
41 "shader/" + shaderVersion + "/postprocessing",
42 "ssao_map_fragmentshader.frag"
43 );
44 if (fragmentShaderId == 0) return;
45
46 // vertex shader
49 "shader/" + shaderVersion + "/postprocessing",
50 "ssao_map_vertexshader.vert"
51 );
52 if (vertexShaderId == 0) return;
53
54 // create, attach and link program
58
59 //
61
62 //
63 if (initialized == false) return;
64
65 // custom initialization
66 for (auto i = 0; i < uniformSphere.size(); i++) {
67 uniformSphere[i] = renderer->getProgramUniformLocation(programId, "sphere[" + to_string(i) + "]");
68 if (uniformSphere[i] == -1) {
69 initialized = false;
70 return;
71 }
72 }
74 if (uniformRandomTextureUnit == -1) {
75 initialized = false;
76 return;
77 }
78 auto randomTexture = TextureReader::read("resources/engine/textures", "random.png");
79 randomTexture->setUseMipMap(false);
81
82 // register shader
83 Engine::registerShader(Engine::ShaderType::SHADERTYPE_POSTPROCESSING, "ssaomap");
84}
85
88 renderer->setProgramUniformFloatVec3(contextIdx, uniformSphere[0], Vector3( 0.5381f, 0.1856f,-0.4319f).getArray());
89 renderer->setProgramUniformFloatVec3(contextIdx, uniformSphere[1], Vector3( 0.1379f, 0.2486f, 0.4430f).getArray());
90 renderer->setProgramUniformFloatVec3(contextIdx, uniformSphere[2], Vector3( 0.3371f, 0.5679f,-0.0057f).getArray());
91 renderer->setProgramUniformFloatVec3(contextIdx, uniformSphere[3], Vector3(-0.6999f,-0.0451f,-0.0019f).getArray());
92 renderer->setProgramUniformFloatVec3(contextIdx, uniformSphere[4], Vector3( 0.0689f,-0.1598f,-0.8547f).getArray());
93 renderer->setProgramUniformFloatVec3(contextIdx, uniformSphere[5], Vector3( 0.0560f, 0.0069f,-0.1843f).getArray());
94 renderer->setProgramUniformFloatVec3(contextIdx, uniformSphere[6], Vector3(-0.0146f, 0.1402f, 0.0762f).getArray());
95 renderer->setProgramUniformFloatVec3(contextIdx, uniformSphere[7], Vector3( 0.0100f,-0.1924f,-0.0344f).getArray());
96 renderer->setProgramUniformFloatVec3(contextIdx, uniformSphere[8], Vector3(-0.3577f,-0.5301f,-0.4358f).getArray());
97 renderer->setProgramUniformFloatVec3(contextIdx, uniformSphere[9], Vector3(-0.3169f, 0.1063f, 0.0158f).getArray());
98 renderer->setProgramUniformFloatVec3(contextIdx, uniformSphere[10], Vector3( 0.0103f,-0.5869f, 0.0046f).getArray());
99 renderer->setProgramUniformFloatVec3(contextIdx, uniformSphere[11], Vector3(-0.0897f,-0.4940f, 0.3287f).getArray());
100 renderer->setProgramUniformFloatVec3(contextIdx, uniformSphere[12], Vector3( 0.7119f,-0.0154f,-0.0918f).getArray());
101 renderer->setProgramUniformFloatVec3(contextIdx, uniformSphere[13], Vector3(-0.0533f, 0.0596f,-0.5411f).getArray());
102 renderer->setProgramUniformFloatVec3(contextIdx, uniformSphere[14], Vector3( 0.0352f,-0.0631f, 0.5460f).getArray());
103 renderer->setProgramUniformFloatVec3(contextIdx, uniformSphere[15], Vector3(-0.4776f, 0.2847f,-0.0271f).getArray());
104 renderer->setTextureUnit(contextIdx, 4);
107}
108
110}
Engine main class.
Definition: Engine.h:122
static void registerShader(ShaderType type, const string &shaderId, const map< string, ShaderParameter > &parameterDefaults={})
Register shader.
Definition: Engine.cpp:2122
static TextureManager * getTextureManager()
Definition: Engine.h:564
static Engine * getInstance()
Returns engine instance.
Definition: Engine.h:554
TextureManager_TextureManaged * addTexture(const string &id, bool &created)
Adds a texture to manager.
virtual void setShaderParameters(int contextIdx, Engine *engine) override
Set shader parameters.
virtual void setTextureUnit(int contextIdx, int32_t textureUnit)=0
Sets up texture unit.
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 setProgramUniformInteger(int contextIdx, int32_t uniformId, int32_t value)=0
Set up a integer uniform value.
virtual void bindTexture(int contextIdx, int32_t textureId)=0
Binds a texture with given id or unbinds when using ID_NONE.
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.
3D vector 3 class
Definition: Vector3.h:22