feat: add spot light shadows with a tilled buffer
This commit is contained in:
@@ -35,6 +35,8 @@
|
||||
#include <destrum/Graphics/Resources/PrimitiveMeshes.h>
|
||||
#include <destrum/Graphics/Managers/Renderer2D.h>
|
||||
#include <destrum/Graphics/Resources/Font.h>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <destrum/Graphics/Frustum.h>
|
||||
#include <destrum/Components/LightComponent.h>
|
||||
#include <destrum/Components/Physics/Rigidbody.h>
|
||||
#include <destrum/Graphics/Material.h>
|
||||
@@ -511,6 +513,33 @@ namespace {
|
||||
SceneManager::GetInstance().Destroy();
|
||||
}
|
||||
|
||||
void testFrustumFromViewProj()
|
||||
{
|
||||
const auto lookingAlongPositiveZ = [](const glm::vec3& position, float range) {
|
||||
const glm::mat4 view = glm::lookAt(position, position + glm::vec3{0.0f, 0.0f, 1.0f}, glm::vec3{0.0f, 1.0f, 0.0f});
|
||||
return glm::perspectiveRH_ZO(glm::radians(60.0f), 1.0f, 0.1f, range) * view;
|
||||
};
|
||||
|
||||
const glm::mat4 viewProj = lookingAlongPositiveZ(glm::vec3{0.0f}, 20.0f);
|
||||
const Frustum frustum = edge::createFrustumFromViewProj(viewProj);
|
||||
|
||||
check(edge::isInFrustum(frustum, Sphere{{0.0f, 0.0f, 10.0f}, 0.5f}), "a sphere in front must be inside");
|
||||
check(!edge::isInFrustum(frustum, Sphere{{0.0f, 0.0f, -5.0f}, 0.5f}), "a sphere behind must be outside");
|
||||
check(!edge::isInFrustum(frustum, Sphere{{0.0f, 0.0f, 30.0f}, 0.5f}), "a sphere past the far plane must be outside");
|
||||
check(!edge::isInFrustum(frustum, Sphere{{15.0f, 0.0f, 10.0f}, 0.5f}), "a sphere to the side must be outside");
|
||||
|
||||
const auto corners = edge::calculateFrustumCorners(viewProj);
|
||||
const bool cornersOnNearAndFar = std::ranges::all_of(corners, [](const glm::vec3& corner) {
|
||||
return std::abs(corner.z - 0.1f) < 0.001f || std::abs(corner.z - 20.0f) < 0.01f;
|
||||
});
|
||||
check(cornersOnNearAndFar, "frustum corners must lie on the near and far planes");
|
||||
|
||||
check(edge::frustumsOverlap(frustum, lookingAlongPositiveZ(glm::vec3{0.0f, 0.0f, 5.0f}, 10.0f)),
|
||||
"a frustum in front of the camera must overlap");
|
||||
check(!edge::frustumsOverlap(frustum, lookingAlongPositiveZ(glm::vec3{0.0f, 0.0f, -30.0f}, 10.0f)),
|
||||
"a frustum entirely behind the camera must not overlap");
|
||||
}
|
||||
|
||||
void testRenderer2DShapes()
|
||||
{
|
||||
auto& r2d = Renderer2D::GetInstance();
|
||||
@@ -1305,6 +1334,7 @@ int main()
|
||||
testPrimitiveBoxMesh();
|
||||
testColliderCenterOffset();
|
||||
testCapsuleColliderDebugLines();
|
||||
testFrustumFromViewProj();
|
||||
testRenderer2DShapes();
|
||||
testFontAtlasAndLayout();
|
||||
std::cout << "destrum tests passed\n";
|
||||
|
||||
Reference in New Issue
Block a user