112 std::vector<std::pair<float, asw::Color>>
keys;
180 bool in_grid(
int x,
int y)
const;
334 std::vector<std::pair<asw::Falloff, asw::Texture>>
gradients;
2D camera for scrolling worlds
2D camera that follows a target, stays inside the world and shakes.
Ambient colour that changes over a repeating cycle, such as a day.
float get_length() const
Get the length of one cycle.
AmbientCycle(float length=1.0F)
Create a cycle.
asw::Color at(float time) const
Get the colour at a time. Times past the length wrap around.
void add(float time, const asw::Color &color)
Add a key colour. Colours between keys are blended.
std::vector< std::pair< float, asw::Color > > keys
A screen sized texture of light, multiplied over the scene.
void clear()
Remove the lights, glows and tiles added 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...
std::vector< float > screen_winding
void add_occluder(const asw::Polygonf &polygon)
Add a polygon that blocks light.
void set_ambient(const asw::Color &color)
Set the colour of unlit areas. Black is pitch dark, white is fully lit.
std::vector< Light > lights
void draw_light(const Light &light)
const asw::Texture & gradient(asw::Falloff falloff)
std::vector< std::pair< asw::Falloff, asw::Texture > > gradients
asw::Vec2< int > map_size
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,...
const std::vector< asw::Polygonf > & get_occluders() const
Get the occluders.
std::vector< int > shadow_indices
std::vector< Glow > glows
bool has_blockers(const asw::Quad< float > &reach) const
std::vector< Tiles > tiles
std::vector< asw::Polygonf > screen_occluders
void draw_shadows(const asw::Vec2< float > ¢er, const asw::Quad< float > &reach)
std::vector< asw::Quad< float > > screen_bounds
void draw()
Draw the light map and multiply it over the current render target.
std::vector< asw::Polygonf > occluders
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 update(float dt)
Advance flicker and pulse. Call once per update.
void clear_occluders()
Remove all occluders.
const asw::Texture & render()
Render the light map without drawing it, to draw it yourself. The render target is the same afterward...
std::vector< SDL_Vertex > shadow_vertices
asw::Color get_ambient() const
Get the colour of unlit areas.
asw::Vec2< float > to_screen(const asw::Vec2< float > &point) const
void set_shadow_mode(ShadowMode mode)
Set how occluders block light.
void add(const Light &light)
Add a light for this frame.
const asw::Camera * camera
ShadowMode get_shadow_mode() const
Get how occluders block light.
Light that spreads across a grid of tiles and stops at solid tiles.
bool is_solid(int x, int y) const
Get whether a tile blocks light. Tiles off the grid are solid.
std::vector< uint8_t > pixels
std::vector< uint8_t > solid
void compute()
Spread the lights and update the texture. Call after lights or solid tiles change.
std::vector< Source > sources
void add_light(int x, int y, const asw::Color &color)
Add a light at a tile.
asw::Color get(int x, int y) const
Get the light at a tile after compute().
asw::Vec2< float > get_size() const
Get the size of the grid in pixels.
std::vector< float > level
const asw::Texture & get_texture() const
Get the texture, with one pixel per tile. Empty before compute().
std::vector< std::size_t > open
void clear_lights()
Remove all lights.
bool in_grid(int x, int y) const
TileLight(int width, int height, float tile_size)
Create a grid with no solid tiles and no lights.
void set_falloff(float amount)
Set how much light is lost per tile, from 0 to 1.
std::vector< float > light
void set_solid(int x, int y, bool solid)
Set whether a tile blocks light. A solid tile is lit, but does not pass light on.
ShadowMode
How lights are blocked by occluders.
@ None
Light goes through occluders.
Polygon< float > Polygonf
std::shared_ptr< SDL_Texture > Texture
Alias for a shared pointer to an SDL_Texture.
Falloff
How a gradient or light fades from its centre to its edge.
@ Smooth
Soft at the centre and at the edge.
RGBA color struct with 8-bit channels.
asw::Vec2< float > position
A light. Positions are in world space when the light map has a camera, otherwise in screen space.
float pulse
Size of a steady pulse from 0 to 1.
asw::Color color
Colour of the light.
float flicker
Random flicker from 0 to 1. 0.2 suits a torch.
float cone
Width of a spot light's beam, in radians. 0 lights all round.
float intensity
Brightness from 0 to 1. Scales the colour.
float direction
Direction a spot light points, in radians. 0 is right, and angles turn clockwise on screen.
bool shadows
Whether occluders block this light.
asw::Vec2< float > position
Centre of the light.
float pulse_speed
Pulses per second.
float radius
Distance the light reaches, in pixels.
int seed
Gives lights their own flicker and pulse timing. Use a different seed for each light.
asw::Falloff falloff
How the light fades to its edge.
Types used throughout the ASW library.