78 return std::floor(std::clamp(texels, 0.0f, 16.0f) * 64.0f + 0.5f) + std::clamp(slopeFloor, 0.01f, 0.999f);
98 const i32 lo = std::clamp(layerMin, -128, 127) + 128;
99 const i32 hi = 127 - std::clamp(layerMax, -128, 127);
100 return static_cast<f32>(lo + 256 * hi);
227 for (
u32 i = 0; i < n; ++i) {
229 if (light.
color.a == 0.0f)
continue;
230 const bool directional = light.
posDir.z >= 0.5f && light.
posDir.z < 1.5f;
232 const f32 dx = std::max(std::max(lo.x - light.
posDir.x, light.
posDir.x - hi.x), 0.0f);
233 const f32 dy = std::max(std::max(lo.y - light.
posDir.y, light.
posDir.y - hi.y), 0.0f);
234 const f32 reach = std::max(light.
posDir.w, 0.0001f) * 1.001f + 0.001f;
235 if (dx * dx + dy * dy >= reach * reach)
continue;
249static_assert(
sizeof(GpuLight) == 96,
"GpuLight must be std140-tight (six vec4s)");
250static_assert(
sizeof(LightConstants) <= 16384,
"the block has to fit the 16 KB every device guarantees a uniform block");
251static_assert(
sizeof(LightConstants) == 16 + 96 *
MAX_LIGHTS + 16
253 + 16 + 16 * 9 + 16 + 16
256 "LightConstants must match the std140 GLSL block layout");
The samplers the engine injects into a shader, and the texture unit each is pinned to.
Which screen tiles a light can reach — the half of tiled forward lighting that is decided on the CPU.
Core type definitions and utilities for ESEngine.
constexpr u32 MAX_LIGHTS
Max simultaneous 2D lights packed into the UBO. The injected fragment loop is a fixed bound; inactive...
constexpr u32 SPRITE_LIGHT_REACH_BITS
std::int32_t i32
Signed 32-bit integer.
constexpr u32 MAX_SHADOW_TILES
Max shadow tiles one frame's atlas hands out — the shader's array bound.
f32 packShadowBias(f32 texels, f32 slopeFloor)
constexpr u32 SHADOW_CUBE_FACES
Faces a point light's map is rendered as. Six cones at right angles cover every direction from a poin...
constexpr u32 MAX_SHADOW_2D_LIGHTS
Channels of the 2D shadow mask: the lights that MEET one another and cast at once (see ShadowChannels...
constexpr f32 SPRITE_LIGHT_REACH_STEP
Which of the loop's lights can reach a lit quad rides in the same vertex lane as its layer: -(layer +...
constexpr u32 MAX_SHAPE_2D_LIGHTS
Lights whose SHAPE one frame can carry — the shape mask's four channels.
constexpr f32 LIGHT_TILE_BITS
The sprite layers a light reaches ride in GpuLight::shadowMap.y above the atlas tile count: tiles + 8...
f32 packLightLayerRange(i32 layerMin, i32 layerMax)
The range of sprite layers a light reaches, as the number that rides in shadowMap....
constexpr u32 LIGHT_CONSTANTS_BINDING
Indexed UBO binding point for the per-frame LightConstants block.
std::uint32_t u32
Unsigned 32-bit integer.
constexpr u32 MAX_REFLECTION_PROBES
Columns of the reflection atlas one frame can address — column 0 the environment's,...
constexpr f32 SPRITE_LAYER_BIAS
What a sprite's layer is written as in the vertex lane the lit fragment reads: the layer plus 129,...
constexpr const char * LIGHT_CONSTANTS_BLOCK
GLSL block name; must match ShaderParser's injected block + Shader::compile lookup.
constexpr u32 MAX_TILED_LIGHTS
Lights a frame can carry through tiles, past the sixteen the loop reads directly. Three words of mask...
u32 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,...
constexpr u32 SHADOW_2D_MASK_CHANNELS
Channels one 2D shadow mask carries: an RGBA8 target has four.
f32 packSpriteLightLane(i32 layer, u32 reachMask)
The lane a lit quad carries: its layer and the lights that reach it (lightReachMask2D).
constexpr u32 TILE_COLUMNS
float f32
32-bit floating point
constexpr u32 MAX_SHADOW_CASCADES
Slices one directional shadow map is split into, each covering a stretch of the view — so the near on...
One 2D light, std140-packed (six vec4s, 96 bytes, 16-aligned).
glm::vec4 color
rgb = colour, a = intensity.
CPU mirror of the GLSL LightConstants block (std140).
GpuLight tiledLights[MAX_TILED_LIGHTS]
The lights past the loop's sixteen (point and spot, no shadow map), read through the tile masks below...
glm::mat4 shadowMatrix[MAX_SHADOW_TILES]
glm::vec4 shadowTile[MAX_SHADOW_TILES]
GpuLight lights[MAX_LIGHTS]
glm::vec4 envIrradiance[9]
glm::vec4 reflBox[2 *MAX_REFLECTION_PROBES]
glm::uvec4 tileMask[TILE_COLUMNS *TILE_ROWS]