401 {
403
405 {
406 directionalLight[i] = glm::mat4(1.0f);
407 }
408
409 TransformComponent camTranComp;
410 float ratio;
411
412 IterWorldCompWithBreak<CameraComponent>(
413 frameInfo,
414 [&](
415 int entityId,
416 TransformComponent& tranComp,
417 CameraComponent& camComp
418 ) {
419 camTranComp = tranComp;
420 ratio = camComp.GetCamera()->GetAspectRatio();
421 return true;
422 });
423
424 int index = 0;
425 IterWorldCompWithBreak<DirectionalLightComponent>(
426 frameInfo,
427 [&](
428 int entityId ,
429 TransformComponent& tranComp ,
430 DirectionalLightComponent& dirlightComp
431 ) {
432 TransformComponent tempComp;
433 tempComp.SetPosition(camTranComp.GetPosition());
434 tempComp.SetRotation(camTranComp.GetRotation());
435
436 const glm::mat4 view = tempComp.GetModelMatrix();
437 const glm::mat4 projection =
OtrhographicMatrix(-ratio * 30, ratio * 30, -1.0f * 30, 1.0f * 30, -100000.0f, 100000.0f);
438
439 directionalLight[index] = projection * glm::inverse(view);
440 index++;
441 return false;
442 });
443 }
static constexpr uint32_t MAX_DIRECTIONALLIGHT_NUM
#define SPICES_PROFILE_ZONE
glm::mat4 OtrhographicMatrix(float left, float right, float top, float bottom, float nearPlane, float farPlane)
Calculate Otrhographic Matrix.