Struct ShadowSystem
Owns per-light GPU resources, shadow maps, and shadow computation. More...
#include <ShadowSystem.h>
Classes
| Type | Name |
|---|---|
| struct | AreaStruct GPU layout for area light data. |
| struct | PointStruct GPU layout for point light data. |
| struct | PolyStruct GPU layout for polygonal light header data. |
| struct | PolyVertStruct GPU layout for polygonal light vertex data. |
| struct | SceneInfo Light count statistics for current scene. |
| struct | SpotStruct GPU layout for spot light data. |
| struct | SunStruct GPU layout for sun/directional light data. |
Public Attributes
| Type | Name |
|---|---|
| StorageBuffer | area_buffer GPU buffer for area light data. |
| std::vector< AreaStruct > | area_list List of area lights for GPU upload. |
| UniformBuffer | info GPU buffer for SceneInfo metadata. |
| StorageBuffer | point_buffer GPU buffer for point light data. |
| std::vector< PointStruct > | point_list List of point lights for GPU upload. |
| StorageBuffer | poly_buffer GPU buffer for polygonal light header data. |
| std::vector< PolyStruct > | poly_list List of polygonal light headers for GPU upload. |
| std::vector< PolyVertStruct > | poly_verts List of polygonal light vertices for GPU upload. |
| StorageBuffer | poly_verts_buffer GPU buffer for polygonal light vertex data. |
| std::unordered_map< int, glm::mat4 > | proj_matrices Per-light projection matrices for shadow rendering. |
| std::unordered_map< int, Texture > | shadow_cache Processed shadow cache per light (light ID -> texture) |
| std::unordered_map< int, Texture > | shadow_maps Raw per-light shadow map textures (depth / moment) |
| StorageBuffer | spot_buffer GPU buffer for spot light data. |
| std::vector< SpotStruct > | spot_list List of spot lights for GPU upload. |
| StorageBuffer | sun_buffer GPU buffer for sun light data. |
| std::vector< SunStruct > | sun_list List of sun lights for GPU upload. |
Public Static Attributes
| Type | Name |
|---|---|
| const GLuint | Sizeof_Area = sizeof([**AreaStruct**](structShadowSystem_1_1AreaStruct.md))Size of AreaStruct in bytes. |
| const GLuint | Sizeof_Point = sizeof([**PointStruct**](structShadowSystem_1_1PointStruct.md))Size of PointStruct in bytes. |
| const GLuint | Sizeof_Poly = sizeof([**PolyStruct**](structShadowSystem_1_1PolyStruct.md))Size of PolyStruct in bytes. |
| const GLuint | Sizeof_PolyVert = sizeof([**PolyVertStruct**](structShadowSystem_1_1PolyVertStruct.md))Size of PolyVertStruct in bytes. |
| const GLuint | Sizeof_Spot = sizeof([**SpotStruct**](structShadowSystem_1_1SpotStruct.md))Size of SpotStruct in bytes. |
| const GLuint | Sizeof_Sun = sizeof([**SunStruct**](structShadowSystem_1_1SunStruct.md))Size of SunStruct in bytes. |
| constexpr int | shadow_slot = {31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16}Texture slots for shadow maps (GL_TEXTURE16-31) |
Public Functions
| Type | Name |
|---|---|
| void | Bind () const Binds all light buffers to shader binding points. |
| void | BindShadowMap () const Binds all shadow map textures to shader slots. |
| void | BindShadowMapBuffer (Light * light, Texture & shadow_map) Binds the shadow map framebuffer for a light, targeting its shadow map texture. |
| void | BindShadowMapShader (Light * light, const glm::mat4 & proj) Binds the shadow map generation shader and sets per-light uniforms. |
| void | BindTargetTrans (Light * light, const glm::mat4 & _trans) Sets the model matrix uniform for a shadow-casting object. |
| void | ConstructSAT (Light * light, const RenderConfigs * config) Constructs Summed Area Table (SAT) for soft shadows. |
| SceneInfo | GetSceneInfo () const Returns light count statistics for current scene. |
| GLuint | GetSlotOffset (LightType _type) const Returns shadow map slot offset for a given light type. |
| GLsizei | GetTotalCount () const Returns total number of lights across all types. |
| void | Init () Initializes GPU buffers. |
| void | InitShadowMap (Light * light, bool using_moment_shadow) Initializes the raw shadow map texture for a single light. |
| void | ParseLightData (const std::unordered_map< int, std::shared_ptr< Light > > & light_list, bool using_moment_shadow=false) Parses basic lights (point, sun, spot, area) into GPU buffers. |
| void | ParsePolygonLightData (const std::unordered_map< int, std::shared_ptr< PolygonLight > > & poly_light_list) Parses polygonal lights into GPU buffers. |
| void | Resize (GLuint _w, GLuint _h) Resizes all cached shadow maps. |
| ShadowSystem () Constructs an empty ShadowSystem . |
|
| void | Update (int frame, RenderConfigs * config) Updates shadow maps for the current frame. |
| void | UpdateLight (Light * light) Updates a single light's GPU data. |
| void | UpdateProjMatrix (Light * light) Computes and stores the projection matrix for a light. |
| ~ShadowSystem () Destroys the ShadowSystem and releases GPU resources. |
Public Static Functions
| Type | Name |
|---|---|
| void | EnableShadowMap () Initializes static shadow map framebuffers and shaders. |
Detailed Description
ShadowSystem aggregates all lights in the scene and packs them into typed storage buffers (SSBO) for efficient GPU access. It also owns the per-light shadow map textures and projection matrices that were previously held by Light.
GPU Layout: * PointStruct: Point lights (position, color, power, radius, shadow flag) * SunStruct: Directional sun lights (direction, projection matrix) * SpotStruct: Spot lights (position, direction, cone angles) * AreaStruct: Rectangular area lights (transform, aspect ratio) * PolyStruct + PolyVertStruct: Polygonal area lights (vertex list)
Shadow Map Management: * Owns shadow map textures per-light (raw depth / moment maps) * Owns projection matrices per-light * Handles shadow map resizing on viewport changes * Binds shadow maps to dedicated texture slots (16-31)
Note:
All structs use explicit alignment (alignas) to match GLSL std140/std430 layout.
Note:
Thread-safety: Not thread-safe. Access from main thread only.
Public Attributes Documentation
variable area_buffer
GPU buffer for area light data.
StorageBuffer ShadowSystem::area_buffer;
variable area_list
List of area lights for GPU upload.
std::vector<AreaStruct> ShadowSystem::area_list;
variable info
GPU buffer for SceneInfo metadata.
UniformBuffer ShadowSystem::info;
variable point_buffer
GPU buffer for point light data.
StorageBuffer ShadowSystem::point_buffer;
variable point_list
List of point lights for GPU upload.
std::vector<PointStruct> ShadowSystem::point_list;
variable poly_buffer
GPU buffer for polygonal light header data.
StorageBuffer ShadowSystem::poly_buffer;
variable poly_list
List of polygonal light headers for GPU upload.
std::vector<PolyStruct> ShadowSystem::poly_list;
variable poly_verts
List of polygonal light vertices for GPU upload.
std::vector<PolyVertStruct> ShadowSystem::poly_verts;
variable poly_verts_buffer
GPU buffer for polygonal light vertex data.
StorageBuffer ShadowSystem::poly_verts_buffer;
variable proj_matrices
Per-light projection matrices for shadow rendering.
std::unordered_map<int, glm::mat4> ShadowSystem::proj_matrices;
variable shadow_cache
Processed shadow cache per light (light ID -> texture)
std::unordered_map<int, Texture> ShadowSystem::shadow_cache;
variable shadow_maps
Raw per-light shadow map textures (depth / moment)
std::unordered_map<int, Texture> ShadowSystem::shadow_maps;
variable spot_buffer
GPU buffer for spot light data.
StorageBuffer ShadowSystem::spot_buffer;
variable spot_list
List of spot lights for GPU upload.
std::vector<SpotStruct> ShadowSystem::spot_list;
variable sun_buffer
GPU buffer for sun light data.
StorageBuffer ShadowSystem::sun_buffer;
variable sun_list
List of sun lights for GPU upload.
std::vector<SunStruct> ShadowSystem::sun_list;
Public Static Attributes Documentation
variable Sizeof_Area
Size of AreaStruct in bytes.
const GLuint ShadowSystem::Sizeof_Area;
variable Sizeof_Point
Size of PointStruct in bytes.
const GLuint ShadowSystem::Sizeof_Point;
variable Sizeof_Poly
Size of PolyStruct in bytes.
const GLuint ShadowSystem::Sizeof_Poly;
variable Sizeof_PolyVert
Size of PolyVertStruct in bytes.
const GLuint ShadowSystem::Sizeof_PolyVert;
variable Sizeof_Spot
Size of SpotStruct in bytes.
const GLuint ShadowSystem::Sizeof_Spot;
variable Sizeof_Sun
Size of SunStruct in bytes.
const GLuint ShadowSystem::Sizeof_Sun;
variable shadow_slot
Texture slots for shadow maps (GL_TEXTURE16-31)
constexpr int ShadowSystem::shadow_slot[16];
Public Functions Documentation
function Bind
Binds all light buffers to shader binding points.
void ShadowSystem::Bind () const
Note:
Called before rendering to make light data accessible to shaders.
function BindShadowMap
Binds all shadow map textures to shader slots.
void ShadowSystem::BindShadowMap () const
Note:
Binds cached shadow maps to slots 16-31 for shader sampling.
function BindShadowMapBuffer
Binds the shadow map framebuffer for a light, targeting its shadow map texture.
void ShadowSystem::BindShadowMapBuffer (
Light * light,
Texture & shadow_map
)
Parameters:
lightLight whose shadow map framebuffer to bindshadow_mapShadow map texture to use as render target
function BindShadowMapShader
Binds the shadow map generation shader and sets per-light uniforms.
void ShadowSystem::BindShadowMapShader (
Light * light,
const glm::mat4 & proj
)
Parameters:
lightLight providing position, direction, and type-specific parametersprojLight-space projection matrix for this light
function BindTargetTrans
Sets the model matrix uniform for a shadow-casting object.
void ShadowSystem::BindTargetTrans (
Light * light,
const glm::mat4 & _trans
)
Parameters:
lightLight whose shadow shader is currently bound_transModel matrix of the geometry to render into the shadow map
function ConstructSAT
Constructs Summed Area Table (SAT) for soft shadows.
void ShadowSystem::ConstructSAT (
Light * light,
const RenderConfigs * config
)
Parameters:
lightLight whose shadow map should be processedconfigRender configuration specifying shadow quality
Note:
SAT enables efficient variable-size blur for soft shadow filtering.
function GetSceneInfo
Returns light count statistics for current scene.
SceneInfo ShadowSystem::GetSceneInfo () const
Returns:
SceneInfo struct with counts per light type
function GetSlotOffset
Returns shadow map slot offset for a given light type.
GLuint ShadowSystem::GetSlotOffset (
LightType _type
) const
Parameters:
_typeLight type (POINTLIGHT, SUNLIGHT, etc.)
Returns:
Starting texture slot index for this light type
function GetTotalCount
Returns total number of lights across all types.
GLsizei ShadowSystem::GetTotalCount () const
Returns:
Sum of all light counts (point + sun + spot + area + poly)
function Init
Initializes GPU buffers.
void ShadowSystem::Init ()
Note:
Must be called after OpenGL context creation.
function InitShadowMap
Initializes the raw shadow map texture for a single light.
void ShadowSystem::InitShadowMap (
Light * light,
bool using_moment_shadow
)
Parameters:
lightLight to initialize shadow map forusing_moment_shadowUse moment-based (HDR) format instead of depth
Note:
Allocates GPU texture based on light type (2D for sun/spot, cubemap for point).
function ParseLightData
Parses basic lights (point, sun, spot, area) into GPU buffers.
void ShadowSystem::ParseLightData (
const std::unordered_map< int, std::shared_ptr< Light > > & light_list,
bool using_moment_shadow=false
)
Parameters:
light_listMap of light ID to Light shared_ptrusing_moment_shadowInitialize shadow maps with moment-based (HDR) format
Note:
Populates point_list, sun_list, spot_list, area_list and uploads to GPU.
Note:
Also initializes shadow_maps and proj_matrices for each light.
function ParsePolygonLightData
Parses polygonal lights into GPU buffers.
void ShadowSystem::ParsePolygonLightData (
const std::unordered_map< int, std::shared_ptr< PolygonLight > > & poly_light_list
)
Parameters:
poly_light_listMap of polygon light ID to PolygonLight shared_ptr
Note:
Populates poly_list and poly_verts, then uploads to GPU.
function Resize
Resizes all cached shadow maps.
void ShadowSystem::Resize (
GLuint _w,
GLuint _h
)
Parameters:
_wNew shadow map width_hNew shadow map height
Note:
Called on viewport resize to match shadow map resolution.
function ShadowSystem
Constructs an empty ShadowSystem .
ShadowSystem::ShadowSystem ()
function Update
Updates shadow maps for the current frame.
void ShadowSystem::Update (
int frame,
RenderConfigs * config
)
Parameters:
frameCurrent frame numberconfigRender configuration for shadow quality
Note:
Manages per-light shadow cache updates and format changes.
function UpdateLight
Updates a single light's GPU data.
void ShadowSystem::UpdateLight (
Light * light
)
Parameters:
lightPointer to modified Light object
Note:
Incrementally updates GPU buffer without full re-upload.
function UpdateProjMatrix
Computes and stores the projection matrix for a light.
void ShadowSystem::UpdateProjMatrix (
Light * light
)
Parameters:
lightLight whose projection matrix should be updated
Note:
Result is stored in proj_matrices keyed by light ID.
function ~ShadowSystem
Destroys the ShadowSystem and releases GPU resources.
ShadowSystem::~ShadowSystem ()
Public Static Functions Documentation
function EnableShadowMap
Initializes static shadow map framebuffers and shaders.
static void ShadowSystem::EnableShadowMap ()
Note:
Must be called once after OpenGL context creation, before rendering any shadows.
The documentation for this class was generated from the following file src/render/ShadowSystem.h