Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
f6b6e56
test case
Sep 8, 2018
f1ce6af
calculating light bounds in AABox around frustum in game example for …
Sep 9, 2018
4262193
added tight projection around camera frustum, light projection near a…
Sep 10, 2018
e1eada7
shadow bug dependent on camera direction
Sep 11, 2018
924fc01
imgui reacting to input and drawing on screen from render device
sp0lsh Sep 25, 2018
cceace4
proper init, render deinit and windows created by game
sp0lsh Sep 25, 2018
8d4f0e0
comments
sp0lsh Sep 25, 2018
f16f8d5
comments
sp0lsh Sep 25, 2018
7f23fd5
Merge branch 'dev' into fet/imgui
sp0lsh Sep 27, 2018
ef0e789
commented #pragma failing travis ci
sp0lsh Sep 28, 2018
8befcc8
removed #pragma
sp0lsh Sep 28, 2018
c5f2ab8
removed pragma from resource
sp0lsh Sep 28, 2018
4ac9b58
commented unused components
sp0lsh Sep 28, 2018
c5cab92
commented out wrong variable doh...
sp0lsh Sep 28, 2018
8522b8f
prototype of shadow casters culling
sp0lsh Sep 29, 2018
3c4215e
moved code to rendering device, tested on example scene and on sponza…
sp0lsh Sep 30, 2018
1bd2719
added AABox around every drawn mesh and still fails on sponza
sp0lsh Sep 30, 2018
a999afa
removed shadow casters AABox
sp0lsh Sep 30, 2018
5d78698
stable shadows working on sponza and test scene
sp0lsh Oct 20, 2018
9bd85a7
stable shadowmap
sp0lsh Oct 21, 2018
a121570
interpolated Percentage Closer Filtering
sp0lsh Oct 21, 2018
168d9a4
shadows prototype cleanup
sp0lsh Oct 22, 2018
85866ba
shadow ramblings
sp0lsh Oct 23, 2018
3ee3414
Merge branch 'dev' into fet/imgui
sp0lsh Oct 26, 2018
b2eddea
merged with dev
sp0lsh Oct 26, 2018
1210c94
cmake attempt
sp0lsh Oct 26, 2018
b22bd5a
moved imgui to third parties, cmake updated for Engine, RenderingDevi…
sp0lsh Oct 30, 2018
003f1e7
removed sanity spam
sp0lsh Oct 30, 2018
3d02fa9
resource cleanup
sp0lsh Oct 30, 2018
c4ee972
imguisystem cleanup
sp0lsh Oct 30, 2018
f3aacaf
imgui world component cleanup
sp0lsh Oct 30, 2018
e1711fa
added non windows API attributes to imconfig.h
sp0lsh Oct 30, 2018
d5001ab
moved imgui to pch
sp0lsh Oct 30, 2018
0f58768
silencing third party gcc -Wimplicit-fallthrough=
sp0lsh Oct 30, 2018
2b5a565
enabled -fPIC (Position Independent Code) for imgui static lib to be …
sp0lsh Oct 30, 2018
3113e77
fixing gcc includes
sp0lsh Oct 30, 2018
bc8c094
fixing cgg includes
sp0lsh Oct 30, 2018
78d1a90
made includes same as in GLTextureDeviceProxy
sp0lsh Oct 30, 2018
ab80981
removed commented out code
sp0lsh Oct 30, 2018
b9fb4b7
ImguiUpdate is now in System, Imgui context creation moved to ImguiSy…
sp0lsh Nov 1, 2018
7bd9937
moved Imgui to Engine subdirectory
sp0lsh Nov 2, 2018
32e5d29
Added clipboard support, tweaked mouse handling and input that can be…
sp0lsh Nov 2, 2018
19cca52
added UTF8 char input from keyboard keys
sp0lsh Nov 2, 2018
58e2f9a
fixing input consumption (works on all widowns: engine and game)
sp0lsh Nov 2, 2018
6984d1d
added output queue and events handled by SDL
sp0lsh Nov 3, 2018
f0c1cc5
CI fix
sp0lsh Nov 3, 2018
354c6c4
CI fix and cleanup
sp0lsh Nov 3, 2018
362d1fb
CI fix
sp0lsh Nov 3, 2018
470215d
CI fix
sp0lsh Nov 3, 2018
1572e31
fix
sp0lsh Nov 3, 2018
fd3f38c
Merge branch 'fet/imgui' into rendering/shadows-pt-2
sp0lsh Nov 3, 2018
9d1561b
Moved getting axis vector from MovementSystem to EntityTransform
sp0lsh Nov 4, 2018
23e80d3
shadowmap ortho projection has correct direction based on dir light f…
sp0lsh Nov 5, 2018
e77e88e
shadowmap projection in [0, 1] range
sp0lsh Nov 5, 2018
2351797
stable shadows on frustum transform and properties change
sp0lsh Nov 5, 2018
6a58900
shadows prototype with tight bound around frustum and ortho projectio…
sp0lsh Nov 5, 2018
dbaa34e
more changes
sp0lsh Nov 5, 2018
b28420f
tweaks to AABB intersection tests
sp0lsh Nov 7, 2018
c72f2f5
added tweakable shadow bias and glPolygonOffset
sp0lsh Nov 7, 2018
c9330cf
working evsm2 and evsm4
sp0lsh Nov 15, 2018
b747335
Merge branch 'rendering/shadows-pt-3' into rendering/shadows-pt-2
sp0lsh Nov 15, 2018
3f97ac2
shadow projection working with shadow bounds extended by vertical sha…
sp0lsh Nov 22, 2018
917f185
some EVSM4 shadows that work
sp0lsh Nov 23, 2018
a513a82
created pass with shadowmap
sp0lsh Nov 24, 2018
ab700b3
switched renderer to use Shadommap pass
sp0lsh Nov 24, 2018
f9ce34d
parametrizing shadow types
sp0lsh Nov 25, 2018
7217fce
EVSM2 seems to work as well
sp0lsh Nov 25, 2018
f205054
removed debug light parameters, shadowmap pass has pcf and evsm versions
sp0lsh Nov 25, 2018
1504210
removed debug variables from light and camera components
sp0lsh Nov 25, 2018
6cc8658
Merge branch 'dev' into rendering/shadows-pt-2
sp0lsh Nov 25, 2018
69348dc
CI fix
sp0lsh Nov 25, 2018
74f5b1e
CI fix
sp0lsh Nov 25, 2018
711c1cf
CI fix
sp0lsh Nov 25, 2018
e543a7a
CI fix
sp0lsh Nov 25, 2018
d5d0905
CI Fix
sp0lsh Nov 25, 2018
c68508a
debug rendering cleanup
sp0lsh Nov 25, 2018
e60202e
cleanup and comments
sp0lsh Nov 25, 2018
02279c9
cleanup
sp0lsh Nov 25, 2018
8308170
compilation fix
sp0lsh Nov 25, 2018
78c1a0e
cleanup
sp0lsh Nov 25, 2018
c3d708e
cleanup
sp0lsh Nov 25, 2018
ff522f2
ignore shader dump extension
sp0lsh Nov 25, 2018
e565d53
fix
sp0lsh Nov 25, 2018
ed965e4
Added comment for .dump file extention
sp0lsh Nov 25, 2018
5ff85ae
cleanup
sp0lsh Nov 25, 2018
e1e9eb6
AABB unit tests
sp0lsh Nov 25, 2018
1afdff3
Merge branch 'rendering/shadows-pt-2' of https://github.com/sp0lsh/Po…
sp0lsh Nov 25, 2018
ad72f20
Merge branch 'dev' into rendering/shadows-pt-2
sp0lsh Nov 25, 2018
3b76a3c
CI fix, tabbed documents
sp0lsh Dec 12, 2018
5f36766
CI fix, tabbed documents
sp0lsh Dec 12, 2018
eb4bb6a
review fix, tabbed code
sp0lsh Dec 12, 2018
bbf2823
assert and nullptr fix
sp0lsh Dec 12, 2018
bd69205
None RenderingSettingsComponent fix
sp0lsh Dec 12, 2018
880fb99
review fix
sp0lsh Dec 12, 2018
39baf37
review fix, updated includes
sp0lsh Dec 12, 2018
12abc19
review fix, removed commented code
sp0lsh Dec 12, 2018
6518669
magic variable moved to constant
sp0lsh Dec 12, 2018
54ce36f
CI fix
sp0lsh Dec 12, 2018
2378f9b
CI fix
sp0lsh Dec 12, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions PolyEngine/Core/Src/Math/AABox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ Poly::AABox& Poly::AABox::Expand(const AABox& rhs)
return *this;
}

Poly::AABox& Poly::AABox::Expand(const Vector& rhs)
{
Vector min = Vector::Min(GetMin(), rhs);
Vector max = Vector::Max(GetMax(), rhs);
Pos = min;
Size = max - min;
return *this;
}

//------------------------------------------------------------------------------
namespace Poly {
std::ostream & operator<<(std::ostream& stream, const AABox& rect)
Expand Down
2 changes: 2 additions & 0 deletions PolyEngine/Core/Src/Math/AABox.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ namespace Poly {

AABox& Expand(const AABox& rhs);

AABox& Expand(const Vector& rhs);

CORE_DLLEXPORT friend std::ostream& operator<< (std::ostream& stream, const AABox& color);
private:
Vector Pos;
Expand Down
56 changes: 48 additions & 8 deletions PolyEngine/Engine/Res/Shaders/lightAccumulation.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,44 @@ layout(location = 1) out vec4 oNormal;

const float PI = 3.14159265359;

// 64 samples of poisson disk at:
// https://www.geeks3d.com/20100628/3d-programming-ready-to-use-64-sample-poisson-disc/
// 32 samples produce similar results on shadow PCF
uniform vec2 poissonDisk[32] = vec2[] (
vec2(-0.613392, 0.617481),
vec2( 0.170019, -0.040254),
vec2(-0.299417, 0.791925),
vec2( 0.645680, 0.493210),
vec2(-0.651784, 0.717887),
vec2( 0.421003, 0.027070),
vec2(-0.817194, -0.271096),
vec2(-0.705374, -0.668203),
vec2( 0.977050, -0.108615),
vec2( 0.063326, 0.142369),
vec2( 0.203528, 0.214331),
vec2(-0.667531, 0.326090),
vec2(-0.098422, -0.295755),
vec2(-0.885922, 0.215369),
vec2( 0.566637, 0.605213),
vec2( 0.039766, -0.396100),
vec2( 0.751946, 0.453352),
vec2( 0.078707, -0.715323),
vec2(-0.075838, -0.529344),
vec2( 0.724479, -0.580798),
vec2( 0.222999, -0.215125),
vec2(-0.467574, -0.405438),
vec2(-0.248268, -0.814753),
vec2( 0.354411, -0.887570),
vec2( 0.175817, 0.382366),
vec2( 0.487472, -0.063082),
vec2(-0.084078, 0.898312),
vec2( 0.488876, -0.783441),
vec2( 0.470016, 0.217933),
vec2(-0.696890, -0.549791),
vec2(-0.149693, 0.605762),
vec2( 0.034211, 0.979980)
);

float DistributionGGX(vec3 N, vec3 H, float roughness)
{
float a = roughness*roughness;
Expand Down Expand Up @@ -130,6 +168,12 @@ vec3 fresnelSchlickRoughness(float cosTheta, vec3 F0, float roughness)
return F0 + (max(vec3(1.0 - roughness), F0) - F0) * pow(clamp(1.0 - cosTheta, 0.001, 1.0), 5.0); // clamp to prevent NaNs
}

float hash(vec4 seed)
{
float dot_product = dot(seed, vec4(12.9898, 78.233, 45.164, 94.673));
return fract(sin(dot_product) * 43758.5453);
}

float calcShadow(vec4 fragPosInDirLight, float NdotL)
{
// perform perspective divide
Expand All @@ -150,16 +194,12 @@ float calcShadow(vec4 fragPosInDirLight, float NdotL)

float shadow = 0.0;
vec2 texelSize = 1.0 / textureSize(uDirShadowMap, 0);
for (int x = -1; x <= 1; ++x)
for (int i = 0; i <= 5; ++i)
{
for (int y = -1; y <= 1; ++y)
{
float pcfDepth = texture(uDirShadowMap, projCoords.xy + vec2(x, y) * texelSize).r;
shadow += currentDepth - bias > pcfDepth ? 0.0 : 1.0;
}
int index = int(32.0 * hash(vec4(gl_FragCoord.xyy, i))) % 32;
float pcfDepth = texture(uDirShadowMap, projCoords.xy + poissonDisk[index] * texelSize).r;
shadow += currentDepth - bias > pcfDepth ? 0.0 : 0.2;
}
shadow /= 9.0;


return shadow;
}
Expand Down
2 changes: 1 addition & 1 deletion PolyEngine/Engine/Src/ECS/ComponentBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace Poly {
const EnumFlags<eComponentBaseFlags>& GetFlags() { return Flags; }
bool CheckFlags(const EnumFlags<eComponentBaseFlags>& rhs) const { return (Flags & rhs) == rhs; }

virtual Optional<AABox> GetBoundingBox(eEntityBoundingChannel channel) { return {}; }
virtual Optional<AABox> GetBoundingBox(eEntityBoundingChannel channel) const { return {}; }

private:
Entity* Owner = nullptr;
Expand Down
6 changes: 4 additions & 2 deletions PolyEngine/Engine/Src/Rendering/MeshRenderingComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ RTTI_DEFINE_COMPONENT(::Poly::MeshRenderingComponent)
MeshRenderingComponent::MeshRenderingComponent(const String& meshPath, eResourceSource source)
{
Mesh = ResourceManager<MeshResource>::Load(meshPath, source);
if (Mesh) {

if (Mesh)
{
size_t materialsNum = GetMesh()->GetSubMeshes().GetSize();
Materials.Resize(materialsNum);
for (size_t i = 0; i < materialsNum; ++i)
Expand All @@ -27,7 +29,7 @@ Poly::MeshRenderingComponent::~MeshRenderingComponent()
ResourceManager<MeshResource>::Release(Mesh);
}

Optional<AABox> Poly::MeshRenderingComponent::GetBoundingBox(eEntityBoundingChannel channel)
Optional<AABox> Poly::MeshRenderingComponent::GetBoundingBox(eEntityBoundingChannel channel) const
{
if (channel != eEntityBoundingChannel::RENDERING || !Mesh)
return {};
Expand Down
2 changes: 1 addition & 1 deletion PolyEngine/Engine/Src/Rendering/MeshRenderingComponent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ namespace Poly {
void SetShadingModel(eShadingMode value) { ShadingMode = value; }
void SetBlendingMode(eBlendingMode value) { BlendingMode = value; }

Optional<AABox> GetBoundingBox(eEntityBoundingChannel channel) const override;

Optional<AABox> GetBoundingBox(eEntityBoundingChannel channel) override;
private:
MeshResource* Mesh = nullptr;
Dynarray<Material> Materials;
Expand Down
9 changes: 6 additions & 3 deletions PolyEngine/Engine/Src/Resources/MeshResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ MeshResource::MeshResource(const String& path)
Assimp::Importer importer;
const aiScene *scene = importer.ReadFile(path.GetCStr(), aiProcessPreset_TargetRealtime_Fast);

if (!scene) {
if (!scene)
{
gConsole.LogError("Error Importing Asset: {}", importer.GetErrorString());
throw ResourceLoadFailedException();
}
Expand All @@ -22,14 +23,16 @@ MeshResource::MeshResource(const String& path)
Vector min(maxFloat, maxFloat, maxFloat);
Vector max(-maxFloat, -maxFloat, -maxFloat);

for (unsigned int i = 0; i < scene->mNumMeshes; ++i) {
for (unsigned int i = 0; i < scene->mNumMeshes; ++i)
{
SubMeshes.PushBack(new SubMesh(path, scene->mMeshes[i], scene->mMaterials[scene->mMeshes[i]->mMaterialIndex]));

min = Vector::Min(min, SubMeshes[i]->GetAABox().GetMin());
max = Vector::Max(max, SubMeshes[i]->GetAABox().GetMax());
}

for (size_t i = 0; i < scene->mNumAnimations; ++i) {
for (size_t i = 0; i < scene->mNumAnimations; ++i)
{
Animations.PushBack(new Animation(scene->mAnimations[i]));
}

Expand Down
12 changes: 6 additions & 6 deletions PolyEngine/RenderingDevice/OpenGL/Src/ForwardRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,30 @@ void ForwardRenderer::Render(const SceneView& sceneView)
switch (renderingMode)
{
case eRenderingModeType::LIT:
RenderLit(sceneView.WorldData, sceneView.Rect, sceneView.CameraCmp);
RenderLit(sceneView.SceneData, sceneView.Rect, sceneView.CameraCmp);
break;

case eRenderingModeType::UNLIT:
RenderUnlit(sceneView.WorldData, sceneView.Rect, sceneView.CameraCmp);
RenderUnlit(sceneView.SceneData, sceneView.Rect, sceneView.CameraCmp);
break;

case eRenderingModeType::WIREFRAME:
RenderWireframe(sceneView.WorldData, sceneView.Rect, sceneView.CameraCmp);
RenderWireframe(sceneView.SceneData, sceneView.Rect, sceneView.CameraCmp);
break;

case eRenderingModeType::DEBUG_NORMALS:
RenderNormals(sceneView.WorldData, sceneView.Rect, sceneView.CameraCmp);
RenderNormals(sceneView.SceneData, sceneView.Rect, sceneView.CameraCmp);
break;

case eRenderingModeType::DEBUG_NORMALS_WIREFRAME:
RenderNormalsWireframe(sceneView.WorldData, sceneView.Rect, sceneView.CameraCmp);
RenderNormalsWireframe(sceneView.SceneData, sceneView.Rect, sceneView.CameraCmp);
break;

default:
ASSERTE(false, "Uknown eRenderingModeType");
}

PostRender(sceneView.WorldData, sceneView.CameraCmp, sceneView.Rect);
PostRender(sceneView.SceneData, sceneView.CameraCmp, sceneView.Rect);
}

void ForwardRenderer::PostRender(Scene* world, const CameraComponent* cameraCmp, const AARect& rect)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ namespace Poly
void CreateUtilityTextures();

void FillSceneView(SceneView& sceneView);
void FillDirLightQueue(SceneView& sceneView, const Dynarray<const MeshRenderingComponent*>& meshCmp);
void EndFrame();

void CleanUpResources();
Expand Down
140 changes: 131 additions & 9 deletions PolyEngine/RenderingDevice/OpenGL/Src/GLWorldRendering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

#include "GLRenderingDevice.hpp"

#include <algorithm> // std::min

#include "Proxy/GLTextFieldBufferDeviceProxy.hpp"
#include "Proxy/GLTextureDeviceProxy.hpp"
#include "Pipeline/RenderingPassBase.hpp"
#include "Proxy/GLMeshDeviceProxy.hpp"
#include "Common/GLUtils.hpp"
#include "Common/PrimitiveCube.hpp"
#include "Common/PrimitiveQuad.hpp"

#include "Debugging//DebugDrawSystem.hpp"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnessecary double forwardslash

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

#include "ForwardRenderer.hpp"
#include "TiledForwardRenderer.hpp"

Expand Down Expand Up @@ -69,10 +71,24 @@ void GLRenderingDevice::RenderWorld(Scene* world)

void GLRenderingDevice::FillSceneView(SceneView& sceneView)
{
for (const auto componentsTuple : sceneView.WorldData->IterateComponents<MeshRenderingComponent>())
for (const auto componentsTuple : sceneView.SceneData->IterateComponents<DirectionalLightComponent>())
{
sceneView.DirectionalLights.PushBack(std::get<DirectionalLightComponent*>(componentsTuple));
}

for (const auto componentsTuple : sceneView.SceneData->IterateComponents<PointLightComponent>())
{
const MeshRenderingComponent* meshCmp = std::get<MeshRenderingComponent*>(componentsTuple);
sceneView.PointLights.PushBack(std::get<PointLightComponent*>(componentsTuple));
}

Dynarray<const MeshRenderingComponent*> meshCmps;
for (const auto componentsTuple : sceneView.SceneData->IterateComponents<MeshRenderingComponent>())
{
meshCmps.PushBack(std::get<MeshRenderingComponent*>(componentsTuple));
}

for ( auto meshCmp : meshCmps)
{
if (sceneView.CameraCmp->IsVisibleToCamera(meshCmp->GetOwner()))
{
if (meshCmp->GetBlendingMode() == eBlendingMode::OPAUQE)
Expand All @@ -84,21 +100,127 @@ void GLRenderingDevice::FillSceneView(SceneView& sceneView)
sceneView.TranslucentQueue.PushBack(meshCmp);
}
}
else
}

if (sceneView.DirectionalLights.GetSize() > 0)
{
FillDirLightQueue(sceneView, meshCmps);
}
}

void GLRenderingDevice::FillDirLightQueue(SceneView& sceneView, const Dynarray<const MeshRenderingComponent*>& meshCmps)
{
// based on:
// https://gamedev.stackexchange.com/questions/73851/how-do-i-fit-the-camera-frustum-inside-directional-light-space
// https://docs.microsoft.com/pl-pl/windows/desktop/DxTechArts/common-techniques-to-improve-shadow-depth-maps

ASSERTE(sceneView.DirectionalLights.GetSize() > 0, "Filling Dir light opaque geometry queue when no Dir light is present in the scene!");
const DirectionalLightComponent* dirLight = sceneView.DirectionalLights[0];

// Create AABB in DirLightSpace around camera frustum
const Optional<Frustum> frustum = sceneView.CameraCmp->GetCameraFrustum();
const EntityTransform& cameraTrans = sceneView.CameraCmp->GetOwner()->GetTransform();
ASSERTE(frustum.HasValue(), "Frustum value of camera is not present at stage of filling opague geometry for shadow rendering!");

// Transform frustum corners to DirLightSpace
Dynarray<Vector> cornersInNDC = Dynarray<Vector>{
Vector(-1.0f, -1.0f, 1.0f),
Vector(-1.0f, 1.0f, 1.0f),
Vector(-1.0f, -1.0f, -1.0f),
Vector(-1.0f, 1.0f, -1.0f),
Vector( 1.0f, -1.0f, 1.0f),
Vector( 1.0f, 1.0f, 1.0f),
Vector( 1.0f, -1.0f, -1.0f),
Vector( 1.0f, 1.0f, -1.0f)
};

// Transform frustum corners from NDC to World
// could be done in one iteration but we need to do perspective division by W
Matrix worldFromClip = sceneView.CameraCmp->GetClipFromWorld().GetInversed();
Dynarray<Vector> cornersInWorld;
for (Vector posInClip : cornersInNDC)
{
Vector world = worldFromClip * posInClip;
world.X /= world.W;
world.Y /= world.W;
world.Z /= world.W;
cornersInWorld.PushBack(world);
}

// Transform frustum corners from World to DirLight
Matrix dirLightFromWorld = dirLight->GetTransform().GetWorldFromModel().GetInversed();

// find min and max corners and create AABB in DirLightSpace
const float maxFloat = std::numeric_limits<float>::max();
Vector min(maxFloat, maxFloat, maxFloat);
Vector max(-maxFloat, -maxFloat, -maxFloat);

Dynarray<Vector> cornersInDirLight;
for (Vector posInWorld : cornersInWorld)
{
Vector posInDirLight = dirLightFromWorld * posInWorld;
min = Vector::Min(min, posInDirLight);
max = Vector::Max(max, posInDirLight);
}

AABox dirLightAABB(min, max - min);
// DebugDrawSystem::DrawBox(sceneView.SceneData, dirLightAABB, Color::BLACK);

// transform meshes AABB to DirLightSpace
Dynarray<std::tuple<AABox, const MeshRenderingComponent*>> meshBoxes;
for (auto meshCmp : meshCmps)
{
const Matrix& dirLightFromModel = dirLightFromWorld * meshCmp->GetTransform().GetWorldFromModel();

Optional<AABox> boxInLightOptional = meshCmp->GetBoundingBox(eEntityBoundingChannel::RENDERING);
if (boxInLightOptional.HasValue())
{
sceneView.DirShadowOpaqueQueue.PushBack(meshCmp);
AABox boxInLight = boxInLightOptional.Value();
boxInLight = boxInLight.GetTransformed(dirLightFromModel);
meshBoxes.PushBack(std::tuple(boxInLight, meshCmp));
}
}

for (const auto componentsTuple : sceneView.WorldData->IterateComponents<DirectionalLightComponent>())
// find min Z for near clipping plane and max Z for far clipping plane
float minZ = maxFloat;
float maxZ = -maxFloat;
for (auto kv : meshBoxes)
{
sceneView.DirectionalLights.PushBack(std::get<DirectionalLightComponent*>(componentsTuple));
AABox box = std::get<0>(kv);
minZ = std::min(minZ, box.GetMin().Z);
maxZ = std::max(maxZ, box.GetMax().Z);
}

for (const auto componentsTuple : sceneView.WorldData->IterateComponents<PointLightComponent>())
dirLightAABB.Expand(Vector(0.0f, 0.0f, minZ))
.Expand(Vector(0.0f, 0.0f, maxZ));

// DebugDrawSystem::DrawBox(sceneView.SceneData, dirLightAABB, Color::WHITE);

// find all meshes that are inside extended DirLights AABB box
int shadowCastersCounter = 0;
for (auto kv : meshBoxes)
{
sceneView.PointLights.PushBack(std::get<PointLightComponent*>(componentsTuple));
AABox box = std::get<0>(kv);
const MeshRenderingComponent* meshCmp = std::get<1>(kv);

bool isInside = false;
for (auto vert : box.GetVertices())
isInside |= dirLightAABB.Contains(vert);

if (isInside || dirLightAABB.Intersects(box))
{
sceneView.DirShadowOpaqueQueue.PushBack(meshCmp);

// DebugDrawSystem::DrawBox(sceneView.SceneData, box, Color::GREEN);
shadowCastersCounter++;
}
}

// remember dir light AABB for orthographic projection size
// sceneView.ShadowAABB = dirLightAABB.GetTransformed(dirLight->GetTransform().GetWorldFromModel());
sceneView.ShadowAABB = dirLightAABB;

// gConsole.LogInfo("GLRenderingDevice::FillDirLightQueue shadowCastersCounter: {}", shadowCastersCounter);
}

void GLRenderingDevice::CreateUtilityTextures()
Expand Down
Loading