21 using std::make_unique;
24 using std::unique_ptr;
31 using tdme::engine::subsystems::shadowmapping::ShadowMapping_RunState;
48 runState = ShadowMapping_RunState::NONE;
60 runState = ShadowMapping_RunState::CREATE;
68 if (light->isEnabled() ==
true &&
69 light->getSpotDirection().computeLengthSquared() > Math::square(Math::EPSILON)) {
92 runState = ShadowMapping_RunState::NONE;
98 for (
auto object: visibleObjects) {
99 if (object->isReceivesShadows() ==
false)
continue;
106 runState = ShadowMapping_RunState::RENDER;
112 shader->useProgram(
engine);
116 for (
auto i = 0; i <
shadowMaps.size(); i++) {
123 shader->setRenderLightId(i);
126 for (
auto j = 0; j < contextCount; j++) {
130 shadowMap->updateDepthBiasMVPMatrix(contextIdx);
135 shadowMap->bindDepthBufferTexture(contextIdx);
147 EntityRenderer::RENDERTYPE_NORMALS |
148 EntityRenderer::RENDERTYPE_TEXTUREARRAYS_DIFFUSEMASKEDTRANSPARENCY |
149 EntityRenderer::RENDERTYPE_TEXTURES_DIFFUSEMASKEDTRANSPARENCY |
150 EntityRenderer::RENDERTYPE_SHADOWMAPPING
159 shader->unUseProgram();
162 for (
auto j = 0; j < contextCount; j++) {
179 runState = ShadowMapping_RunState::NONE;
185 for (
auto i = 0; i <
shadowMaps.size(); i++) {
195 if (
runState != ShadowMapping_RunState::RENDER)
211 if (
runState != ShadowMapping_RunState::RENDER)
219 if (
runState == ShadowMapping_RunState::NONE)
return;
223 case ShadowMapping_RunState::CREATE:
226 case ShadowMapping_RunState::RENDER:
230 Console::println(
string(
"ShadowMapping::updateTextureMatrix(): unsupported run state '" + to_string(
runState)));
236 if (
runState == ShadowMapping_RunState::NONE)
return;
240 case ShadowMapping_RunState::CREATE:
243 case ShadowMapping_RunState::RENDER:
247 Console::println(
string(
"ShadowMapping::updateMatrices(): unsupported run state '" + to_string(
runState)));
252 if (
runState == ShadowMapping_RunState::NONE)
257 case ShadowMapping_RunState::CREATE:
260 case ShadowMapping_RunState::RENDER:
264 Console::println(
string(
"ShadowMapping::updateMaterial(): unsupported run state '" + to_string(
runState)));
269 if (
runState == ShadowMapping_RunState::RENDER) {
275 if (
runState == ShadowMapping_RunState::NONE)
280 case ShadowMapping_RunState::CREATE:
283 case ShadowMapping_RunState::RENDER:
287 Console::println(
string(
"ShadowMapping::bindTexture(): unsupported run state '" + to_string(
runState)));
293 if (
runState != ShadowMapping_RunState::RENDER)
304 if (
runState != ShadowMapping_RunState::RENDER)
312 if (
runState == ShadowMapping_RunState::NONE)
317 case ShadowMapping_RunState::CREATE:
320 case ShadowMapping_RunState::RENDER:
324 Console::println(
string(
"ShadowMapping::setShader(): unsupported run state '" + to_string(
runState)));
329 if (
runState == ShadowMapping_RunState::NONE)
334 case ShadowMapping_RunState::CREATE:
337 case ShadowMapping_RunState::RENDER:
341 Console::println(
string(
"ShadowMapping::updateShaderParameters(): unsupported run state '" + to_string(
runState)));
Light * getLightAt(int32_t idx)
Returns light at idx (0 <= idx < 8)
static ShadowMapRenderShader * getShadowMapRenderShader()
static int32_t getShadowMapWidth()
static int32_t getShadowMapHeight()
static int getThreadCount()
static ShadowMapCreationShader * getShadowMapCreationShader()
static constexpr int RENDERPASS_MAX
virtual void setTextureUnit(int contextIdx, int32_t textureUnit)=0
Sets up texture unit.
virtual bool isSupportingMultithreadedRendering()=0
virtual void enableDepthBufferWriting()=0
Enable depth buffer writing.
virtual void setCullFace(int32_t cullFace)=0
Sets up which face will be culled.
virtual int32_t getTextureUnit(int contextIdx)=0
Get texture unit.
virtual void enableBlending()=0
Enables blending.
virtual void disableBlending()=0
Disables blending.
virtual void setColorMask(bool red, bool green, bool blue, bool alpha)=0
Set up GL rendering colormask.
virtual void bindTexture(int contextIdx, int32_t textureId)=0
Binds a texture with given id or unbinds when using ID_NONE.
virtual void disableDepthBufferWriting()=0
Disable depth buffer writing.
void render(Entity::RenderPass renderPass, const vector< Object * > &objects, bool renderTransparentFaces, int32_t renderTypes)
Renders all given objects.
Shadow mapping shader to create a shadow map.
void updateMatrices(int contextIdx)
Set up matrices.
void useProgram(Engine *engine)
Use shadow map creation shader program.
void setShader(int contextIdx, const string &id)
Set shader.
void updateTextureMatrix(int contextIdx)
Set up texture matrix.
void updateShaderParameters(int contextIdx)
Update shader parameters.
void updateMaterial(int contextIdx)
Update material.
void bindTexture(int contextIdx, int32_t textureId)
Bind texture.
void unUseProgram()
Unuse shadow map creation shader program.
Shadow mapping shader to render shadow maps.
void updateLight(int contextIdx, int32_t lightId)
Update light.
void updateMatrices(int contextIdx)
Update matrices.
void setDepthBiasMVPMatrix(int contextIdx, const Matrix4x4 &depthBiasMVPMatrix)
Set up program depth bias mvp matrix.
void setShader(int contextIdx, const string &id)
Set shader.
void updateTextureMatrix(int contextIdx)
Update up texture matrix.
void updateShaderParameters(int contextIdx)
Update shader parameters.
void updateMaterial(int contextIdx)
Update material.
void bindTexture(int contextIdx, int32_t textureId)
Bind texture.
static constexpr int32_t TEXTUREUNIT
void updateDepthBiasMVPMatrix(int contextIdx, Matrix4x4 &depthBiasMVPMatrix)
Update depth bias mvp matrix with given matrix.
Matrix4x4 shadowTransformMatrix
void reshape(int32_t width, int32_t height)
Reshape shadow maps.
ShadowMapping_RunState runState
void updateLight(int contextIdx, int32_t lightId)
Update light.
void updateMatrices(int contextIdx)
Update matrices.
~ShadowMapping()
Destructor.
Matrix4x4 depthBiasMVPMatrix
void createShadowMaps()
Create shadow maps.
void setShader(int contextIdx, const string &id)
Set shader.
EntityRenderer * entityRenderer
void updateTextureMatrix(int contextIdx)
Update texture matrix.
void updateShaderParameters(int contextIdx)
Update shader parameters.
vector< unique_ptr< ShadowMap > > shadowMaps
void dispose()
Dispose shadow maps.
void startObjectTransform(int contextIdx, Matrix4x4 &transformMatrix)
Start object transform.
void updateMaterial(int contextIdx)
Update material.
void renderShadowMaps(const vector< Object * > &visibleObjects)
Render shadow maps to world.
void bindTexture(int contextIdx, int32_t textureId)
Bind texture.
void endObjectTransform()
End object transform.
vector< Object * > visibleObjectsReceivingShadows
Matrix4x4 class representing matrix4x4 mathematical structure and operations for 3d space.
Matrix4x4 & identity()
Creates identity matrix.
Vector3 multiply(const Vector3 &vector3) const
Multiplies this matrix with vector3.
Matrix4x4 & set(float r0c0, float r0c1, float r0c2, float r0c3, float r1c0, float r1c1, float r1c2, float r1c3, float r2c0, float r2c1, float r2c2, float r2c3, float r3c0, float r3c1, float r3c2, float r3c3)
Sets this matrix by its components.
Vector3 class representing vector3 mathematical structure and operations with x, y,...
Vector4 class representing vector4 mathematical structure and operations with x, y,...