Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ set(CUBOS_ENGINE_SOURCE
"src/render/shadow_atlas_rasterizer/shadow_atlas_rasterizer.cpp"
"src/render/cascaded_shadow_maps/plugin.cpp"
"src/render/cascaded_shadow_maps_rasterizer/plugin.cpp"
"src/render/active/plugin.cpp"
"src/render/active/active.cpp"

"src/tools/settings_inspector/plugin.cpp"
"src/tools/selection/plugin.cpp"
Expand Down
20 changes: 20 additions & 0 deletions engine/include/cubos/engine/render/active/active.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/// @file
/// @brief Component @ref cubos::engine::Active
/// @ingroup render-active-plugin

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think this plugin should be a render-plugin. It is also relevant outside it. We'll use it for audio, and probably for collisions too later on. So, it would be better to put it in engine-plugin, and move to active dir to cubos/engine/

#pragma once

#include <cubos/core/reflection/reflect.hpp>

namespace cubos::engine
{
/// @brief Component which stores the active state for an entity.
/// @note Added automatically once a specific camera or light is added.
Comment thread
RodrigoVintem marked this conversation as resolved.
/// @ingroup render-active-plugin
struct Active
{
CUBOS_REFLECT;

/// @brief Whether the entity is active.
bool active = true;
};
} // namespace cubos::engine
10 changes: 10 additions & 0 deletions engine/include/cubos/engine/render/active/plugin.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#pragma once
Comment thread
RodrigoVintem marked this conversation as resolved.

#include <cubos/engine/api.hpp>
#include <cubos/engine/prelude.hpp>
#include <cubos/engine/render/active/active.hpp>

namespace cubos::engine
{
CUBOS_ENGINE_API void activePlugin(Cubos& cubos);
Comment thread
RodrigoVintem marked this conversation as resolved.
}
3 changes: 0 additions & 3 deletions engine/include/cubos/engine/render/camera/camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ namespace cubos::engine
{
CUBOS_REFLECT;

/// @brief Whether the camera is drawing to a target.
bool active{true};

/// @brief Projection matrix of the camera.
glm::mat4 projection{};

Expand Down
9 changes: 9 additions & 0 deletions engine/src/render/active/active.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <cubos/core/ecs/reflection.hpp>
#include <cubos/core/reflection/external/primitives.hpp>

#include <cubos/engine/render/active/active.hpp>

CUBOS_REFLECT_IMPL(cubos::engine::Active)
{
return core::ecs::TypeBuilder<Active>("cubos::engine::Active").withField("active", &Active::active).build();
}
7 changes: 7 additions & 0 deletions engine/src/render/active/plugin.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <cubos/engine/render/active/active.hpp>
#include <cubos/engine/render/active/plugin.hpp>

void cubos::engine::activePlugin(Cubos& cubos)
{
cubos.component<Active>();
}
1 change: 0 additions & 1 deletion engine/src/render/camera/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
CUBOS_REFLECT_IMPL(cubos::engine::Camera)
{
return core::ecs::TypeBuilder<Camera>("cubos::engine::Camera")
.withField("active", &Camera::active)
.withField("projection", &Camera::projection)
.withField("zNear", &Camera::zNear)
.withField("zFar", &Camera::zFar)
Expand Down
13 changes: 13 additions & 0 deletions engine/src/render/camera/plugin.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <glm/gtc/matrix_transform.hpp>

#include <cubos/engine/render/active/active.hpp>
#include <cubos/engine/render/active/plugin.hpp>
#include <cubos/engine/render/camera/camera.hpp>
#include <cubos/engine/render/camera/draws_to.hpp>
#include <cubos/engine/render/camera/orthographic.hpp>
Expand All @@ -13,13 +15,24 @@ using namespace cubos::engine;
void cubos::engine::cameraPlugin(Cubos& cubos)
{
cubos.depends(renderTargetPlugin);
cubos.depends(activePlugin);

cubos.component<Camera>();
cubos.component<PerspectiveCamera>();
cubos.component<OrthographicCamera>();

cubos.relation<DrawsTo>();

cubos.observer("add active component on add Camera")
.onAdd<Camera>()
.without<Active>()
.call([](Commands cmds, Query<Entity> query) {
for (auto [ent] : query)
{
cmds.add(ent, Active{});
}
});

cubos.observer("add Camera on add PerspectiveCamera")
.onAdd<PerspectiveCamera>()
.without<Camera>()
Expand Down
18 changes: 12 additions & 6 deletions engine/src/render/cascaded_shadow_maps/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <cubos/core/io/window.hpp>
#include <cubos/core/reflection/external/primitives.hpp>

#include <cubos/engine/render/active/plugin.hpp>
#include <cubos/engine/render/camera/camera.hpp>
#include <cubos/engine/render/camera/plugin.hpp>
#include <cubos/engine/render/cascaded_shadow_maps/plugin.hpp>
Expand All @@ -26,9 +27,14 @@ void cubos::engine::cascadedShadowMapsPlugin(Cubos& cubos)

cubos.system("create cascaded shadow maps")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think you also need to add cubos.depends(cameraPlugin) here, and the same goes for the other plugins.
Have you tested running the shadows sample? It probably crashes

.tagged(createCascadedShadowMapsTag)
.call([](const Window& window, Query<DirectionalShadowCaster&> query, Query<Entity, const Camera&> cameras) {
for (auto [caster] : query)
.call([](const Window& window, Query<DirectionalShadowCaster&, const Active&> query,
Query<Entity, const Camera&, const Active&> cameras) {
for (auto [caster, active] : query)
{
if (!active.active)
{
continue;
}
// Remove shadow maps for cameras that no longer exist
std::vector<Entity> removedCameras;
for (auto& [cameraEntity, shadowMap] : caster.shadowMaps)
Expand All @@ -38,9 +44,9 @@ void cubos::engine::cascadedShadowMapsPlugin(Cubos& cubos)
removedCameras.push_back(cameraEntity);
}
}
for (auto [entity, camera] : cameras)
for (auto [entity, camera, cameraActive] : cameras)
{
if (!camera.active && caster.shadowMaps.contains(entity))
if (!cameraActive.active && caster.shadowMaps.contains(entity))
{
removedCameras.push_back(entity);
}
Expand All @@ -53,9 +59,9 @@ void cubos::engine::cascadedShadowMapsPlugin(Cubos& cubos)
caster.updateShadowMaps(window->renderDevice());

// Create shadow maps for new cameras
for (auto [entity, camera] : cameras)
for (auto [entity, camera, cameraActive] : cameras)
{
if (camera.active && !caster.shadowMaps.contains(entity))
if (cameraActive.active && !caster.shadowMaps.contains(entity))
{
caster.shadowMaps[entity] = std::make_shared<DirectionalShadowCaster::ShadowMap>();
caster.shadowMaps[entity]->resize(window->renderDevice(), caster.size,
Expand Down
Loading