30 using std::make_unique;
31 using std::unique_ptr;
57 ShadowMap::ShadowMap(
ShadowMapping* shadowMapping, int32_t width, int32_t height)
65 0.5f, 0.0f, 0.0f, 0.0f,
66 0.0f, -0.5f, 0.0f, 0.0f,
67 0.0f, 0.0f, 0.5f, 0.0f,
68 0.5f, 0.5f, 0.5f, 1.0f
72 0.5f, 0.0f, 0.0f, 0.0f,
73 0.0f, 0.5f, 0.0f, 0.0f,
74 0.0f, 0.0f, 0.5f, 0.0f,
75 0.5f, 0.5f, 0.5f, 1.0f
123 auto left = camera->getModelViewProjectionInvertedMatrix().multiply(
125 (2.0f * 0.0f) - 1.0f,
126 1.0f - (2.0f * 0.5f),
127 2.0f * 0.997f - 1.0f,
131 left.
scale(1.0f / left.getW());
134 auto right = camera->getModelViewProjectionInvertedMatrix().multiply(
136 (2.0f * 1.0f) - 1.0f,
137 1.0f - (2.0f * 0.5f),
138 2.0f * 0.997f - 1.0f,
142 right.
scale(1.0f / right.getW());
145 auto center4 = camera->getModelViewProjectionInvertedMatrix().multiply(
147 (2.0f * 0.5f) - 1.0f,
148 1.0f - (2.0f * 1.0f),
153 center4.
scale(1.0f / center4.getW());
156 Vector3 center(
Vector3(center4.getX(), center4.getY(), center4.getZ()));
161 auto lightLookFrom = center.
clone().
sub(lightDirection.clone().scale(width * 0.5f));
173 lightPosition.
scale(1.0f / lightPosition.getW());
174 auto lightPosition3 =
Vector3(lightPosition.getX(), lightPosition.getY(), lightPosition.getZ());
185 auto lightCameraUpVector = Vector3::computeCrossProduct(
lightCamera->getForwardVector(),
lightCamera->getSideVector());
187 auto lightCameraSideVector = Vector3::computeCrossProduct(
lightCamera->getForwardVector(),
lightCamera->getUpVector());
198 switch (entity->getEntityType()) {
203 if (orgEntity !=
nullptr) {
204 if (orgEntity->isContributesShadows() ==
false)
continue;
205 switch(orgEntity->getEntityType()) {
208 auto object =
static_cast<Object*
>(orgEntity);
214 auto lodObject =
static_cast<LODObject*
>(orgEntity);
215 if (lodObject->isContributesShadows() ==
false)
continue;
217 if (
object !=
nullptr) {
230 auto object =
static_cast<Object*
>(entity);
231 if (object->isContributesShadows() ==
false)
continue;
237 auto lodObject =
static_cast<LODObject*
>(entity);
238 if (lodObject->isContributesShadows() ==
false)
continue;
246 if (object->isContributesShadows() ==
false)
continue;
253 if (lodObjectImposter->isContributesShadows() ==
false)
continue;
261 if (opse->isContributesShadows() ==
false)
continue;
262 for (
auto object: opse->getEnabledObjects())
visibleObjects.push_back(
object);
268 for (
auto ps: psg->getParticleSystems()) {
271 if (opse->isContributesShadows() ==
false)
continue;
272 for (
auto object: opse->getEnabledObjects())
visibleObjects.push_back(
object);
279 if (eh->isContributesShadows() ==
false)
continue;
280 for (
auto entity: eh->getEntities()) {
282 auto object =
static_cast<Object*
>(entity);
283 if (object->isEnabled() ==
false)
continue;
306 EntityRenderer::RENDERTYPE_TEXTUREARRAYS_DIFFUSEMASKEDTRANSPARENCY |
307 EntityRenderer::RENDERTYPE_TEXTURES_DIFFUSEMASKEDTRANSPARENCY
@ FRUSTUMMODE_PERSPECTIVE
@ FRUSTUMMODE_ORTHOGRAPHIC
Partition * getPartition()
float getShadowMapLightEyeDistanceScale()
Entity hierarchy to be used with engine class.
static constexpr int RENDERPASS_MAX
@ ENTITYTYPE_OBJECTRENDERGROUP
@ ENTITYTYPE_OBJECTPARTICLESYSTEM
@ ENTITYTYPE_IMPOSTEROBJECT
@ ENTITYTYPE_PARTICLESYSTEMGROUP
@ ENTITYTYPE_LODOBJECTIMPOSTER
@ ENTITYTYPE_ENTITYHIERARCHY
static constexpr int32_t FRAMEBUFFER_DEPTHBUFFER
Imposter object to be used with engine class.
LOD object + imposter to be used with engine class.
LOD object to be used with engine class.
const Vector3 & getSpotDirection() const
bool isDirectional() const
Returns if light is directional light like sun, moon lights.
const Vector4 & getPosition() const
Object particle system entity to be used with engine class.
Object render group for static objects that might be animated by shaders.
Object to be used with engine class.
Particle system group, which combines several particle systems into a group, to be used with engine c...
Axis aligned bounding box used for frustum, this is not directly connectable with physics engine.
Line segment helper functions.
Matrix4x4 & getProjectionMatrix()
RendererType getRendererType()
Matrix4x4 & getModelViewMatrix()
virtual void clear(int32_t mask)=0
Clear render buffer with given mask.
int32_t CONTEXTINDEX_DEFAULT
int32_t CLEAR_DEPTH_BUFFER_BIT
void render(Entity::RenderPass renderPass, const vector< Object * > &objects, bool renderTransparentFaces, int32_t renderTypes)
Renders all given objects.
unique_ptr< FrameBuffer > frameBuffer
void reshape(int32_t width, int32_t height)
Reshape frame buffer.
void initialize()
Initialize shadow map.
void updateDepthBiasMVPMatrix(int contextIdx)
Set up shadow texture matrix computed and stored before.
Matrix4x4 depthBiasMVPMatrix
ShadowMapping * shadowMapping
vector< Object * > visibleObjects
void dispose()
Disposes this shadow map.
void computeDepthBiasMVPMatrix()
Computes shadow texture matrix and stores it.
void createShadowMap(Light *light)
Create shadow map.
void bindDepthBufferTexture(int contextIdx)
Binds frame buffer depth texture.
unique_ptr< Camera > lightCamera
void updateDepthBiasMVPMatrix(int contextIdx, Matrix4x4 &depthBiasMVPMatrix)
Update depth bias mvp matrix with given matrix.
EntityRenderer * entityRenderer
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,...
float computeLength() const
Vector3 clone() const
Clones this vector3.
Vector3 & sub(float scalar)
Subtracts a scalar.
Vector3 & scale(float scalar)
Scales by scalar.
Vector3 & normalize()
Normalizes this vector3.
Vector4 class representing vector4 mathematical structure and operations with x, y,...
Vector4 & scale(float scalar)
Scales this vector4.
virtual const vector< Entity * > & getVisibleEntities(Frustum *frustum)=0
Get visible entities.