|
ASW Lib
A.D.S. Games SDL Wrapper Library. A library targeted at Allegro4 users who want to switch to SDL3 and use modern c++.
|
A screen sized texture of light, multiplied over the scene. More...
#include <lighting.h>
Classes | |
| struct | Glow |
| struct | Tiles |
Public Member Functions | |
| void | set_ambient (const asw::Color &color) |
| Set the colour of unlit areas. Black is pitch dark, white is fully lit. | |
| asw::Color | get_ambient () const |
| Get the colour of unlit areas. | |
| void | set_camera (const asw::Camera *camera) |
| Take positions in world space and convert them with a camera. The camera must outlive the light map, or be cleared first. | |
| void | set_shadow_mode (ShadowMode mode) |
| Set how occluders block light. | |
| ShadowMode | get_shadow_mode () const |
| Get how occluders block light. | |
| void | update (float dt) |
| Advance flicker and pulse. Call once per update. | |
| void | clear () |
| Remove the lights, glows and tiles added this frame. | |
| void | add (const Light &light) |
| Add a light for this frame. | |
| void | add_glow (const asw::Texture &texture, const asw::Quad< float > &dest, const asw::Color &tint=asw::Color(255, 255, 255)) |
| Add a texture that gives off light, such as lava or a lamp sprite. Its colours are added to the light map. | |
| void | add_tiles (const TileLight &tile_light, const asw::Vec2< float > &position={ }) |
| Add tile lighting for this frame. The grid must outlive the next render() or draw(). | |
| void | add_occluder (const asw::Polygonf &polygon) |
| Add a polygon that blocks light. | |
| void | add_occluder (const asw::Quad< float > &rect) |
| Add a rectangle that blocks light. | |
| void | clear_occluders () |
| Remove all occluders. | |
| const std::vector< asw::Polygonf > & | get_occluders () const |
| Get the occluders. | |
| void | draw () |
| Draw the light map and multiply it over the current render target. | |
| const asw::Texture & | render () |
| Render the light map without drawing it, to draw it yourself. The render target is the same afterwards as before. | |
Private Member Functions | |
| asw::Vec2< float > | to_screen (const asw::Vec2< float > &point) const |
| asw::Quad< float > | to_screen (const asw::Quad< float > &rect) const |
| const asw::Texture & | gradient (asw::Falloff falloff) |
| void | prepare_occluders () |
| bool | has_blockers (const asw::Quad< float > &reach) const |
| void | draw_light (const Light &light) |
| void | draw_shadows (const asw::Vec2< float > ¢er, const asw::Quad< float > &reach) |
Private Attributes | |
| asw::Color | ambient { 0, 0, 0 } |
| const asw::Camera * | camera { nullptr } |
| ShadowMode | shadow_mode { ShadowMode::None } |
| double | time { 0.0 } |
| std::vector< Light > | lights |
| std::vector< Glow > | glows |
| std::vector< Tiles > | tiles |
| std::vector< asw::Polygonf > | occluders |
| std::vector< asw::Polygonf > | screen_occluders |
| std::vector< asw::Quad< float > > | screen_bounds |
| std::vector< float > | screen_winding |
| asw::Polygonf | seen |
| std::vector< SDL_Vertex > | shadow_vertices |
| std::vector< int > | shadow_indices |
| asw::Texture | map |
| asw::Texture | scratch |
| asw::Vec2< int > | map_size |
| std::vector< std::pair< asw::Falloff, asw::Texture > > | gradients |
A screen sized texture of light, multiplied over the scene.
Each frame: clear(), then add lights, glows and tiles, then draw the scene and call draw(). Occluders stay until clear_occluders(), so walls only need adding once.
Definition at line 204 of file lighting.h.
| void asw::lighting::LightMap::add | ( | const Light & | light | ) |
Add a light for this frame.
Definition at line 377 of file lighting.cpp.
| void asw::lighting::LightMap::add_glow | ( | const asw::Texture & | texture, |
| const asw::Quad< float > & | dest, | ||
| const asw::Color & | tint = asw::Color(255, 255, 255) ) |
Add a texture that gives off light, such as lava or a lamp sprite. Its colours are added to the light map.
| texture | The texture. |
| dest | Where to draw it. |
| tint | Colour to multiply the texture by. |
Definition at line 382 of file lighting.cpp.
| void asw::lighting::LightMap::add_occluder | ( | const asw::Polygonf & | polygon | ) |
Add a polygon that blocks light.
Definition at line 394 of file lighting.cpp.
| void asw::lighting::LightMap::add_occluder | ( | const asw::Quad< float > & | rect | ) |
Add a rectangle that blocks light.
Definition at line 399 of file lighting.cpp.
| void asw::lighting::LightMap::add_tiles | ( | const TileLight & | tile_light, |
| const asw::Vec2< float > & | position = { } ) |
Add tile lighting for this frame. The grid must outlive the next render() or draw().
| tile_light | The grid, after compute(). |
| position | Where the top left of the grid is. |
Definition at line 388 of file lighting.cpp.
| void asw::lighting::LightMap::clear | ( | ) |
Remove the lights, glows and tiles added this frame.
Definition at line 370 of file lighting.cpp.
| void asw::lighting::LightMap::clear_occluders | ( | ) |
Remove all occluders.
Definition at line 406 of file lighting.cpp.
| void asw::lighting::LightMap::draw | ( | ) |
Draw the light map and multiply it over the current render target.
Definition at line 685 of file lighting.cpp.
|
private |
Definition at line 529 of file lighting.cpp.
|
private |
Definition at line 472 of file lighting.cpp.
| asw::Color asw::lighting::LightMap::get_ambient | ( | ) | const |
Get the colour of unlit areas.
Definition at line 345 of file lighting.cpp.
| const std::vector< asw::Polygonf > & asw::lighting::LightMap::get_occluders | ( | ) | const |
Get the occluders.
Definition at line 411 of file lighting.cpp.
| asw::lighting::ShadowMode asw::lighting::LightMap::get_shadow_mode | ( | ) | const |
Get how occluders block light.
Definition at line 360 of file lighting.cpp.
|
private |
Definition at line 426 of file lighting.cpp.
|
private |
Definition at line 460 of file lighting.cpp.
|
private |
Definition at line 443 of file lighting.cpp.
| const asw::Texture & asw::lighting::LightMap::render | ( | ) |
Render the light map without drawing it, to draw it yourself. The render target is the same afterwards as before.
Definition at line 617 of file lighting.cpp.
| void asw::lighting::LightMap::set_ambient | ( | const asw::Color & | color | ) |
Set the colour of unlit areas. Black is pitch dark, white is fully lit.
Definition at line 340 of file lighting.cpp.
| void asw::lighting::LightMap::set_camera | ( | const asw::Camera * | camera | ) |
Take positions in world space and convert them with a camera. The camera must outlive the light map, or be cleared first.
Definition at line 350 of file lighting.cpp.
| void asw::lighting::LightMap::set_shadow_mode | ( | ShadowMode | mode | ) |
Set how occluders block light.
Definition at line 355 of file lighting.cpp.
|
private |
Definition at line 421 of file lighting.cpp.
|
private |
Definition at line 416 of file lighting.cpp.
| void asw::lighting::LightMap::update | ( | float | dt | ) |
Advance flicker and pulse. Call once per update.
| dt | The time in seconds since the last update. |
Definition at line 365 of file lighting.cpp.
|
private |
Definition at line 308 of file lighting.h.
|
private |
Definition at line 309 of file lighting.h.
|
private |
Definition at line 316 of file lighting.h.
|
private |
Definition at line 334 of file lighting.h.
|
private |
Definition at line 315 of file lighting.h.
|
private |
Definition at line 331 of file lighting.h.
|
private |
Definition at line 333 of file lighting.h.
|
private |
Definition at line 318 of file lighting.h.
|
private |
Definition at line 332 of file lighting.h.
|
private |
Definition at line 323 of file lighting.h.
|
private |
Definition at line 322 of file lighting.h.
|
private |
Definition at line 324 of file lighting.h.
|
private |
Definition at line 327 of file lighting.h.
|
private |
Definition at line 329 of file lighting.h.
|
private |
Definition at line 310 of file lighting.h.
|
private |
Definition at line 328 of file lighting.h.
|
private |
Definition at line 317 of file lighting.h.
|
private |
Definition at line 313 of file lighting.h.