Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
LightConstants.hpp File Reference

Per-frame 2D lighting constants — the third tier of the engine's constant-buffer layering (after per-frame FrameConstants at 0 and per-material MaterialConstants at 1). More...

#include "../../core/Types.hpp"
#include "./EngineTextureUnits.hpp"
#include "./TiledLights.hpp"
#include <algorithm>
#include <cmath>
#include <glm/glm.hpp>
Include dependency graph for LightConstants.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  esengine::GpuLight
 One 2D light, std140-packed (six vec4s, 96 bytes, 16-aligned). More...
struct  esengine::LightConstants
 CPU mirror of the GLSL LightConstants block (std140). More...

Namespaces

namespace  esengine

Functions

f32 esengine::packShadowBias (f32 texels, f32 slopeFloor)
f32 esengine::packLightLayerRange (i32 layerMin, i32 layerMax)
 The range of sprite layers a light reaches, as the number that rides in shadowMap.y above the tile count. 0 is every layer.
u32 esengine::lightReachMask2D (const GpuLight *lights, u32 count, const glm::vec2 &lo, const glm::vec2 &hi)
 Bit i set when loop light i can put any light on the box lo .. hi (the plane's XY, the space the vertices are in).
f32 esengine::packSpriteLightLane (i32 layer, u32 reachMask)
 The lane a lit quad carries: its layer and the lights that reach it (lightReachMask2D).

Variables

constexpr u32 esengine::LIGHT_CONSTANTS_BINDING = 2
 Indexed UBO binding point for the per-frame LightConstants block.
constexpr const char * esengine::LIGHT_CONSTANTS_BLOCK = "LightConstants"
 GLSL block name; must match ShaderParser's injected block + Shader::compile lookup.
constexpr u32 esengine::MAX_LIGHTS = 16
 Max simultaneous 2D lights packed into the UBO. The injected fragment loop is a fixed bound; inactive slots are zeroed (intensity 0) so they contribute nothing. Must match the u_lights[..] array size in ShaderParser's injected GLSL.
constexpr u32 esengine::MAX_SHAPE_2D_LIGHTS = 4
 Lights whose SHAPE one frame can carry — the shape mask's four channels.
constexpr u32 esengine::SHADOW_2D_MASK_CHANNELS = 4
 Channels one 2D shadow mask carries: an RGBA8 target has four.
constexpr u32 esengine::MAX_SHADOW_2D_LIGHTS = 8
 Channels of the 2D shadow mask: the lights that MEET one another and cast at once (see ShadowChannels2D.hpp).
constexpr u32 esengine::MAX_SHADOW_CASCADES = 4
 Slices one directional shadow map is split into, each covering a stretch of the view — so the near one spends its texels on what is near instead of on the whole scene. Where they LAND is the atlas's answer, not this number's: a cascade claims a tile like anything else that casts.
constexpr u32 esengine::SHADOW_CUBE_FACES = 6
 Faces a point light's map is rendered as. Six cones at right angles cover every direction from a point, and each is a tile like any other — which is what spares the pass a projection nothing else in it understands.
constexpr u32 esengine::MAX_SHADOW_TILES = 16
 Max shadow tiles one frame's atlas hands out — the shader's array bound.
constexpr u32 esengine::MAX_REFLECTION_PROBES = 15
 Columns of the reflection atlas one frame can address — column 0 the environment's, so fifteen probes and a sky.
constexpr f32 esengine::LIGHT_TILE_BITS = 8.0f
 The sprite layers a light reaches ride in GpuLight::shadowMap.y above the atlas tile count: tiles + 8 * range.
constexpr f32 esengine::SPRITE_LAYER_BIAS = 129.0f
 What a sprite's layer is written as in the vertex lane the lit fragment reads: the layer plus 129, so 0 is "no layer to test".
constexpr f32 esengine::SPRITE_LIGHT_REACH_STEP = 512.0f
 Which of the loop's lights can reach a lit quad rides in the same vertex lane as its layer: -(layer + 129 + 512 * reach).
constexpr u32 esengine::SPRITE_LIGHT_REACH_BITS = 15

Detailed Description

Per-frame 2D lighting constants — the third tier of the engine's constant-buffer layering (after per-frame FrameConstants at 0 and per-material MaterialConstants at 1).

A Lit-domain material shader (#pragma domain Lit) gets a layout(std140) uniform LightConstants { ... } block auto-injected by ShaderParser, and Shader::compile links it to LIGHT_CONSTANTS_BINDING. LightStore (owned by RenderContext) collects the scene's Light components into this CPU mirror each frame and uploads it once. The GLSL struct layout MUST match this std140 mirror exactly — a mismatch silently corrupts lighting.

Definition in file LightConstants.hpp.