|
Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
|
Holds the per-frame 2D lights and their GPU UBO. Mirrors MaterialStore's UBO lifecycle (lazy create, dirty upload, device-owned free). More...
#include <LightStore.hpp>
Public Member Functions | |
| void | setDevice (GfxDevice *device) |
| The render path uses this device to create/upload/delete the lighting UBO. | |
| void | clear () |
| void | addAmbient (const glm::vec3 &color) |
| void | addAmbientGround (const glm::vec3 &delta) |
| void | addLight (const GpuLight &light) |
| bool | addTiledLight (const GpuLight &light, const glm::mat4 &viewProjection) |
| void | setTiledView (const glm::mat4 &viewProjection) |
| void | markLoopLights (const glm::mat4 &viewProjection) |
| Says, per screen tile, which of the LOOP's sixteen lights can reach a flat lit surface there: the masks' spare fourth word. | |
| u32 | tiledCount () const |
| u32 | loopTileBits () const |
| u32 | loopTileBits3D () const |
| The tiles the loop's lights reach a 3D surface on, summed over lights (the masks' upper half). | |
| void | setShadowTiles (const glm::mat4 *matrices, const glm::vec4 *tiles, u32 count, const glm::vec4 ¶ms) |
| void | setLightCloudTile (u32 slot, u32 tile) |
Says the directional light in slot reads the sky's cloud shadow from atlas tile tile (GpuLight::spot.x). | |
| void | setLightShadowTiles (u32 slot, u32 first, u32 tiles) |
| bool | setEnvironment (const glm::vec3 *irradiance, const glm::vec4 ¶ms, const glm::vec3 &tint, f32 yaw) |
| bool | hasEnvironment () const |
| void | setReflections (const glm::vec4 ¶ms, const glm::vec4 *boxes, u32 count) |
| Points the frame at a BAKED atlas: its format, and a box per column. | |
| void | setReflectionTone (f32 scale, f32 saturation) |
| How baked reflection columns are shown this frame: their brightness and the colour they keep. | |
| void | isolate (bool direct) |
| What baked indirect light is multiplied by this frame: the day's or the weather's say on a bake of one moment. | |
| void | setBakedTint (const glm::vec3 &tint) |
| void | setLightShadow2DChannel (u32 slot, u32 channel) |
| void | setTiledLightShadow2DChannel (u32 index, u32 channel) |
The same for the index'th light of the tiled list, the ones past the loop's sixteen. | |
| void | setLightShape2DChannel (u32 slot, u32 channel) |
| void | setMask2DRect (const glm::vec4 &rect) |
| void | setWaterSun (const glm::vec4 &rect, const glm::vec4 &depth, const glm::vec4 &sun) |
| void | uploadAndBind () |
| void | free () |
| Frees the GPU UBO. Call while the device is still valid (RenderContext::shutdown). | |
| u32 | count () const |
| const LightConstants & | data () const |
Holds the per-frame 2D lights and their GPU UBO. Mirrors MaterialStore's UBO lifecycle (lazy create, dirty upload, device-owned free).
Definition at line 36 of file LightStore.hpp.
|
inline |
Adds an ambient term (rgb already scaled by intensity). Ambient lights sum rather than occupy a slot. The alpha tracks the active non-ambient light count for shader early-out.
Definition at line 56 of file LightStore.hpp.
|
inline |
How far a hemisphere Ambient light moves the ambient term between a surface facing up and one facing down (ground minus sky, already scaled by intensity). Sums the way the term itself does.
Definition at line 65 of file LightStore.hpp.
|
inline |
Appends a point/directional light. Silently drops past MAX_LIGHTS (the fixed shader loop bound); callers keep the most significant lights first if they exceed the cap.
Definition at line 74 of file LightStore.hpp.
References esengine::MAX_LIGHTS.
|
inline |
Appends a positional light past the loop's sixteen and marks the tiles its sphere reaches through viewProjection. Returns false past MAX_TILED_LIGHTS.
Definition at line 83 of file LightStore.hpp.
References esengine::MAX_TILED_LIGHTS, esengine::TILE_COLUMNS, and esengine::TILE_ROWS.
|
inline |
Begins a frame's collection: zeroes ambient + all light slots (inactive slots contribute nothing because their intensity is 0) and marks the UBO for re-upload.
Definition at line 43 of file LightStore.hpp.
|
inline |
Definition at line 316 of file LightStore.hpp.
Referenced by esengine::SpritePlugin::collect(), setReflections(), and setShadowTiles().
|
inline |
Definition at line 317 of file LightStore.hpp.
Referenced by esengine::SpritePlugin::collect().
| void esengine::LightStore::free | ( | ) |
Frees the GPU UBO. Call while the device is still valid (RenderContext::shutdown).
Definition at line 29 of file LightStore.cpp.
References esengine::Invalid.
|
inline |
Definition at line 214 of file LightStore.hpp.
|
inline |
What baked indirect light is multiplied by this frame: the day's or the weather's say on a bake of one moment.
Keeps one part of the light: direct the lights alone, otherwise everything that is not a light.
For a view that splits lighting (ShadingMode::DirectLighting / IndirectLighting). Direct zeroes the ambient, the environment's both halves (its tint scales the reflection too), the baked columns' and the bake's tint, which together are every term indirectIrradiance and envRadiance read. Indirect drops every light, tiled ones included.
Definition at line 248 of file LightStore.hpp.
|
inline |
How many (screen tile, loop light) pairs the last markLoopLights left set: 192 tiles times the lights when nothing could be told apart, far fewer under local lights. No pixel shows a light that is skipped, so this is what a gate reads.
Definition at line 161 of file LightStore.hpp.
|
inline |
The tiles the loop's lights reach a 3D surface on, summed over lights (the masks' upper half).
Definition at line 163 of file LightStore.hpp.
|
inline |
Says, per screen tile, which of the LOOP's sixteen lights can reach a flat lit surface there: the masks' spare fourth word.
A lit sprite or tile works out every light in the loop for every pixel, and that arithmetic is what 2D lighting costs (docs/GPU_PERFORMANCE_OPTIONS.md, section 9). With this a pixel skips the lights that cannot reach its tile, and a tilemap's strips, which stay on the GPU, need nothing written into them when a light moves. tileInfo.w says the word is there. Call once the loop's lights are all added.
A flat surface measures a light in the plane's XY alone, whatever its depth, so a tile is only a sound answer where the view keeps depth out of the picture's x and y: an orthographic camera looking down the plane's normal. Through any other the word is all ones and nothing is skipped. A directional light reaches every tile.
The word's upper half is the same question for a 3D surface (bits 16-31), which measures a light in space: a light's sphere (its radius, past which its ramp is zero) is marked on the tiles it covers through viewProjection, any view, and that view goes with the masks (tileView) for the surface to find its tile through. Every light of the loop is worked out for every lit 3D pixel without it; a city at night has a dozen lamps, and most reach little of it.
Definition at line 119 of file LightStore.hpp.
References esengine::GpuLight::color, esengine::markLightTiles(), esengine::GpuLight::posDir, esengine::GpuLight::shadow, esengine::TILE_COLUMNS, and esengine::TILE_ROWS.
Referenced by setTiledView().
|
inline |
Definition at line 264 of file LightStore.hpp.
|
inline |
The render path uses this device to create/upload/delete the lighting UBO.
Definition at line 39 of file LightStore.hpp.
|
inline |
The frame's environment. The FIRST ambient light carrying one wins — several do not sum the way flat terms do. yaw turns it about +Y in RADIANS and rides in the tint's alpha, which std140 pads into existence whether it is used or not.
Definition at line 203 of file LightStore.hpp.
Says the directional light in slot reads the sky's cloud shadow from atlas tile tile (GpuLight::spot.x).
Names the atlas tiles light slot casts into. What lets a fragment read the right map once more than one light has rendered one; a slot nobody names keeps the zeroed count, which is a light with no map.
Definition at line 182 of file LightStore.hpp.
Gives light slot a channel of the frame's 2D shadow mask, and says the mask exists. A slot nobody names keeps the -1 it was collected with, which is a light that lights without shadowing.
Definition at line 272 of file LightStore.hpp.
References esengine::MAX_SHADOW_2D_LIGHTS.
Definition at line 188 of file LightStore.hpp.
References esengine::LIGHT_TILE_BITS.
Gives light slot a channel of the frame's shape mask. A slot nobody names keeps -1, which is a light with no shape of its own — it lights a full circle.
Definition at line 287 of file LightStore.hpp.
References esengine::MAX_SHAPE_2D_LIGHTS.
|
inline |
Where the camera about to draw sits inside the masks (xy = low corner, zw = size, as fractions of one). A zero size says the frame has none; set per camera, because two cameras read two different parts of one screen-space target.
Definition at line 296 of file LightStore.hpp.
|
inline |
Points the frame at a BAKED atlas: its format, and a box per column.
Overwrites envParams because the atlas the frame binds is this one — the columns past 0 are the scene's rooms, and column 0 is the sky as the bake saw it. The irradiance and the tint stay the ambient light's: the diffuse half is not what a reflection atlas holds.
Definition at line 224 of file LightStore.hpp.
References count(), and esengine::MAX_REFLECTION_PROBES.
How baked reflection columns are shown this frame: their brightness and the colour they keep.
Definition at line 234 of file LightStore.hpp.
|
inline |
Hands over the shadow tiles a frame rendered: per tile a world -> clip matrix and the atlas rect it was drawn into (bias in w), plus the params whose x is the master switch. Zeroed when nothing cast, so no matrix outlives its map.
Definition at line 168 of file LightStore.hpp.
References count(), and esengine::MAX_SHADOW_TILES.
The same for the index'th light of the tiled list, the ones past the loop's sixteen.
Definition at line 279 of file LightStore.hpp.
References esengine::MAX_SHADOW_2D_LIGHTS.
|
inline |
Reprojects the collected lights for another view without changing their identity, illumination or shadow assignments. Call again with the source view after drawing a reflection; its post-processing also reads this block.
Definition at line 95 of file LightStore.hpp.
References markLoopLights(), esengine::TILE_COLUMNS, and esengine::TILE_ROWS.
|
inline |
Definition at line 301 of file LightStore.hpp.
|
inline |
Definition at line 157 of file LightStore.hpp.
| void esengine::LightStore::uploadAndBind | ( | ) |
Uploads the mirror (when dirty) and binds it at LIGHT_CONSTANTS_BINDING. Called once per frame in flush(); the binding persists, only the contents change. No-op without a device.
Definition at line 14 of file LightStore.cpp.
References esengine::Invalid, esengine::LIGHT_CONSTANTS_BINDING, esengine::GfxContent::retained(), and esengine::Uniform.