TDME2 1.9.121
ShadowMapCreationShaderBaseImplementation.cpp
Go to the documentation of this file.
2
3#include <tdme/tdme.h>
13
24
25ShadowMapCreationShaderBaseImplementation::ShadowMapCreationShaderBaseImplementation(Renderer* renderer)
26{
27 this->renderer = renderer;
28 initialized = false;
29}
30
32}
33
35{
36 return initialized;
37}
38
40{
41 // map inputs to attributes
46 }
47 // link
48 if (renderer->linkProgram(programId) == false) return;
49
50 // uniforms
52 // uniforms
54 if (uniformProjectionMatrix == -1) return;
56 if (uniformCameraMatrix == -1) return;
57 } else {
58 // uniforms
60 if (uniformMVPMatrix == -1) return;
62 }
64 if (uniformTextureMatrix == -1) return;
66 if (uniformTextureAtlasSize == -1) return;
68 if (uniformTextureAtlasPixelDimension == -1) return;
70 if (uniformDiffuseTextureUnit == -1) return;
72 if (uniformDiffuseTextureAvailable == -1) return;
77
78 //
80
81 //
82 initialized = true;
83}
84
86{
87 renderer->useProgram(contextIdx, programId);
89 renderer->setProgramUniformInteger(contextIdx, uniformDiffuseTextureUnit, LightingShaderConstants::SPECULAR_TEXTUREUNIT_DIFFUSE);
90 if (uniformTime != -1) renderer->setProgramUniformFloat(contextIdx, uniformTime, static_cast<float>(engine->getTiming()->getTotalTime()) / 1000.0f);
91}
92
94{
95}
96
98{
102 } else {
103 Matrix4x4 mvpMatrix;
104 Vector3 modelTranslation;
105 // model view projection matrix
107 // model translation
108 renderer->getModelViewMatrix().getTranslation(modelTranslation);
111 }
112}
113
116}
117
119{
120 auto material = renderer->getSpecularMaterial(contextIdx);
121 renderer->setProgramUniformInteger(contextIdx, uniformDiffuseTextureMaskedTransparency, material.diffuseTextureMaskedTransparency);
122 renderer->setProgramUniformFloat(contextIdx, uniformDiffuseTextureMaskedTransparencyThreshold, material.diffuseTextureMaskedTransparencyThreshold);
123 renderer->setProgramUniformInteger(contextIdx, uniformTextureAtlasSize, material.textureAtlasSize);
124 renderer->setProgramUniformFloatVec2(contextIdx, uniformTextureAtlasPixelDimension, material.textureAtlasPixelDimension);
125}
126
127void ShadowMapCreationShaderBaseImplementation::bindTexture(Renderer* renderer, int contextIdx, int32_t textureId)
128{
129 switch (renderer->getTextureUnit(contextIdx)) {
130 case LightingShaderConstants::SPECULAR_TEXTUREUNIT_DIFFUSE:
131 renderer->setProgramUniformInteger(contextIdx, uniformDiffuseTextureAvailable, textureId == 0 ? 0 : 1);
132 break;
133 }
134}
Engine main class.
Definition: Engine.h:122
Timing * getTiming()
Definition: Engine.h:900
Timing class.
Definition: Timing.h:17
int64_t getTotalTime()
Definition: Timing.h:61
Interface to lighting shader program.
Renderer_SpecularMaterial & getSpecularMaterial(int contextIdx)
Get specular material.
Definition: Renderer.h:1142
virtual void setProgramUniformFloatVec2(int contextIdx, int32_t uniformId, const array< float, 2 > &data)=0
Set up a float vec2 uniform value.
virtual int32_t getTextureUnit(int contextIdx)=0
Get texture unit.
virtual void setProgramAttributeLocation(int32_t programId, int32_t location, const string &name)=0
Bind attribute to a input location.
virtual void setProgramUniformInteger(int contextIdx, int32_t uniformId, int32_t value)=0
Set up a integer uniform value.
virtual bool linkProgram(int32_t programId)=0
Links attached shaders to a program.
virtual void setProgramUniformFloatMatrix3x3(int contextIdx, int32_t uniformId, const array< float, 9 > &value)=0
Set up a float matrix 3x3 uniform value.
void setLighting(int contextIdx, int32_t lighting)
Set current lighting model.
Definition: Renderer.h:503
virtual bool isInstancedRenderingAvailable()=0
Checks if instanced rendering is available.
virtual void setProgramUniformFloatMatrix4x4(int contextIdx, int32_t uniformId, const array< float, 16 > &value)=0
Set up a float matrix 4x4 uniform value.
virtual int32_t getProgramUniformLocation(int32_t programId, const string &name)=0
Returns location of given uniform variable.
Matrix2D3x3 & getTextureMatrix(int contextIdx)
Get texture matrix.
Definition: Renderer.h:578
virtual void useProgram(int contextIdx, int32_t programId)=0
Use shader program.
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.
virtual void updateTextureMatrix(Renderer *renderer, int contextIdx) override
Set up program texture matrix.
virtual void updateMaterial(Renderer *renderer, int contextIdx) override
Update material.
virtual void bindTexture(Renderer *renderer, int contextIdx, int32_t textureId) override
Bind texture.
virtual void unUseProgram(int contextIdx) override
Unuse shadow map creation program.
virtual void useProgram(Engine *engine, int contextIdx) override
Use shadow map creation program.
array< float, 9 > & getArray() const
Returns array data.
Definition: Matrix2D3x3.h:348
4x4 3D Matrix class
Definition: Matrix4x4.h:24
Matrix4x4 & set(float r0c0, float r1c0, float r2c0, float r3c0, float r0c1, float r1c1, float r2c1, float r3c1, float r0c2, float r1c2, float r2c2, float r3c2, float r0c3, float r1c3, float r2c3, float r3c3)
Set up matrix by values.
Definition: Matrix4x4.h:95
void getTranslation(Vector3 &translation) const
Get translation.
Definition: Matrix4x4.h:261
Vector3 multiply(const Vector3 &v) const
Multiplies a vector3 with this matrix into destination vector.
Definition: Matrix4x4.h:351
array< float, 16 > & getArray() const
Returns array data.
Definition: Matrix4x4.h:616
3D vector 3 class
Definition: Vector3.h:22
array< float, 3 > & getArray() const
Definition: Vector3.h:171
File system singleton class.
Definition: FileSystem.h:14
Console class.
Definition: Console.h:26