-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(rendering): move shadows code to a single folder
- Loading branch information
Showing
35 changed files
with
553 additions
and
498 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 0 additions & 97 deletions
97
engine/include/cubos/engine/render/shadow_atlas/shadow_atlas.hpp
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
engine/include/cubos/engine/render/shadows/atlas/point_atlas.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/// @file | ||
/// @brief Resource @ref cubos::engine::PointShadowAtlas. | ||
/// @ingroup render-shadow-atlas-plugin | ||
|
||
#pragma once | ||
|
||
#include <map> | ||
|
||
#include <glm/vec2.hpp> | ||
|
||
#include <cubos/core/gl/render_device.hpp> | ||
#include <cubos/core/reflection/reflect.hpp> | ||
|
||
#include <cubos/engine/api.hpp> | ||
#include <cubos/engine/render/shadows/atlas/slot.hpp> | ||
|
||
namespace cubos::engine | ||
{ | ||
/// @brief Resource which stores the shadow map atlas for point lights, | ||
/// a large texture that holds the shadow maps for each shadow caster | ||
/// in a quadtree structure, reducing texture switching. | ||
/// @ingroup render-shadow-atlas-plugin | ||
class CUBOS_ENGINE_API PointShadowAtlas | ||
{ | ||
public: | ||
CUBOS_REFLECT; | ||
|
||
/// @brief Gets the size of the shadow atlas texture. | ||
/// @return Size of the shadow atlas texture, in pixels. | ||
glm::uvec2 getSize() const; | ||
|
||
/// @brief Recreates the shadow atlas texture. | ||
/// @param rd Render device used to create the texture. | ||
void resize(cubos::core::gl::RenderDevice& rd); | ||
|
||
/// @brief Configured size of the shadow atlas texture, in pixels. | ||
/// Use this to change the resolution of the atlas. Note that the | ||
/// texture isn't immediately resized; use @ref getSize() to get the | ||
/// actual texture size. | ||
glm::uvec2 configSize = {1024, 1024}; | ||
|
||
/// @brief Whether the shadow atlas texture has already been cleared this frame. | ||
bool cleared = false; | ||
|
||
/// @brief Stores shadow maps for each point shadow caster component. | ||
/// Each texture of the array corresponds to a face of a cubemap. | ||
core::gl::Texture2DArray atlas{nullptr}; | ||
|
||
/// @brief Stores the sizes, offsets, and caster ids of the shadow maps | ||
/// in the atlas. | ||
std::vector<std::shared_ptr<cubos::engine::ShadowMapSlot>> slots; | ||
|
||
/// @brief Maps shadow caster ids to their corresponding slots. | ||
std::map<int, std::shared_ptr<cubos::engine::ShadowMapSlot>> slotsMap; | ||
|
||
private: | ||
/// @brief Size of the shadow atlas texture, in pixels. | ||
glm::uvec2 mSize = {0, 0}; | ||
}; | ||
} // namespace cubos::engine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/// @file | ||
/// @brief Resource @ref cubos::engine::ShadowMapSlot. | ||
/// @ingroup render-shadow-atlas-plugin | ||
|
||
#pragma once | ||
|
||
#include <glm/vec2.hpp> | ||
|
||
#include <cubos/engine/api.hpp> | ||
|
||
namespace cubos::engine | ||
{ | ||
/// @brief Slot for a shadow map in the shadow atlas. | ||
struct ShadowMapSlot | ||
{ | ||
glm::vec2 size; ///< Shadow map size, in normalized coordinates. | ||
glm::vec2 offset; ///< Shadow map offset, in normalized coordinates. | ||
int casterId; ///< Id of the shadow caster (-1 if none). | ||
|
||
/// @brief Constructs. | ||
/// @param size Shadow map size, in normalized coordinates. | ||
/// @param offset Shadow map offset, in normalized coordinates. | ||
/// @param casterId Id of the shadow caster (-1 if none). | ||
ShadowMapSlot(glm::vec2 size, glm::vec2 offset, int casterId) | ||
: size(size) | ||
, offset(offset) | ||
, casterId(casterId) {}; | ||
}; | ||
} // namespace cubos::engine |
59 changes: 59 additions & 0 deletions
59
engine/include/cubos/engine/render/shadows/atlas/spot_atlas.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/// @file | ||
/// @brief Resource @ref cubos::engine::SpotShadowAtlas. | ||
/// @ingroup render-shadow-atlas-plugin | ||
|
||
#pragma once | ||
|
||
#include <map> | ||
|
||
#include <glm/vec2.hpp> | ||
|
||
#include <cubos/core/gl/render_device.hpp> | ||
#include <cubos/core/reflection/reflect.hpp> | ||
|
||
#include <cubos/engine/api.hpp> | ||
#include <cubos/engine/render/shadows/atlas/slot.hpp> | ||
|
||
namespace cubos::engine | ||
{ | ||
/// @brief Resource which stores the shadow map atlas for spot lights, | ||
/// a large texture that holds the shadow maps for each shadow caster | ||
/// in a quadtree structure, reducing texture switching. | ||
/// @ingroup render-shadow-atlas-plugin | ||
class CUBOS_ENGINE_API SpotShadowAtlas | ||
{ | ||
public: | ||
CUBOS_REFLECT; | ||
|
||
/// @brief Gets the size of the shadow atlas texture. | ||
/// @return Size of the shadow atlas texture, in pixels. | ||
glm::uvec2 getSize() const; | ||
|
||
/// @brief Recreates the shadow atlas texture. | ||
/// @param rd Render device used to create the texture. | ||
void resize(cubos::core::gl::RenderDevice& rd); | ||
|
||
/// @brief Configured size of the shadow atlas texture, in pixels. | ||
/// Use this to change the resolution of the atlas. Note that the | ||
/// texture isn't immediately resized; use @ref getSize() to get the | ||
/// actual texture size. | ||
glm::uvec2 configSize = {4096, 4096}; | ||
|
||
/// @brief Whether the shadow atlas texture has already been cleared this frame. | ||
bool cleared = false; | ||
|
||
/// @brief Stores shadow maps for each spot shadow caster component. | ||
core::gl::Texture2D atlas{nullptr}; | ||
|
||
/// @brief Stores the sizes, offsets, and caster ids of the shadow maps | ||
/// in the atlas. | ||
std::vector<std::shared_ptr<cubos::engine::ShadowMapSlot>> slots; | ||
|
||
/// @brief Maps shadow caster ids to their corresponding slots. | ||
std::map<int, std::shared_ptr<cubos::engine::ShadowMapSlot>> slotsMap; | ||
|
||
private: | ||
/// @brief Size of the shadow atlas texture, in pixels. | ||
glm::uvec2 mSize = {0, 0}; | ||
}; | ||
} // namespace cubos::engine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.