GraphicsAPI reference
Class LightMap
Namespace: MicroEngine.Graphics
Assembly: MicroEngine.Graphics2D.dll
Guide: Graphics
Darkness with point lights for caves, dungeons and night scenes. Each frame the game clears the map, adds lights in world space and draws it over the finished scene:
- a coarse brightness grid ([CellSize](/docs/api/microengine.graphics.lightmap/#MicroEngine_Graphics_LightMap_CellSize) pixels, quantised to [Levels](/docs/api/microengine.graphics.lightmap/#MicroEngine_Graphics_LightMap_Levels) bands) is multiplied over the screen, toward [Shade](/docs/api/microengine.graphics.lightmap/#MicroEngine_Graphics_LightMap_Shade) where it is dark;
- lights with a glow colour add a soft radial halo on top.
Rows of equal cells merge into single rectangles, so a full screen costs a few hundred quads. With Darkness 1 and lights of brightness 0 it becomes a flat colour grade plus glows.
public sealed class LightMap : IDisposableInheritance
Implements
Constructors
LightMap(IGraphicsDevice?, PixelImage?)
public LightMap(IGraphicsDevice? device, PixelImage? glowImage = null)Parameters
device IGraphicsDevice?
Creates the halo texture; pass null to draw darkness only (e.g. headless tests).
glowImage PixelImage?
Optional square white halo to match a game’s style (e.g. banded pixel glows); defaults to CreateGlowImage. It is scaled to each light’s glow radius.
Properties
CellSize
Size of a brightness cell in pixels (4 by default); larger cells are cheaper and blockier.
public int CellSize { get; set; }Property Value
Darkness
Ambient darkness: 0 = no effect, 1 = fully Shade where unlit.
public float Darkness { get; set; }Property Value
GlowIntensity
Multiplier applied to every glow’s alpha (e.g. fade halos with the darkness).
public float GlowIntensity { get; set; }Property Value
Levels
Number of brightness bands (12 by default); fewer bands give a more stylised look.
public int Levels { get; set; }Property Value
LightCount
Number of lights added since the last Clear.
public int LightCount { get; }Property Value
Shade
The colour full darkness multiplies the scene toward.
public Color Shade { get; set; }Property Value
Methods
Add(Vector2, float, float, Color?, float?)
Adds a light. brightness lifts darkness inside radius with a smooth
falloff; glow (alpha respected) adds an additive halo of glowRadius
(default 90% of the radius). A light may only glow (brightness 0) or only brighten (no glow).
public void Add(Vector2 worldPosition, float radius, float brightness, Color? glow = null, float? glowRadius = null)Parameters
worldPosition Vector2
radius float
brightness float
glow Color?
glowRadius float?
BrightnessAt(Vector2)
Brightness 0..1 at a world point, before banding (useful for tests and stealth/AI rules).
public float BrightnessAt(Vector2 world)Parameters
world Vector2
Returns
Clear()
Removes every light; call it at the start of each frame before adding lights.
public void Clear()CreateGlowImage(int)
A white radial halo with a smooth (squared smoothstep) falloff.
public static PixelImage CreateGlowImage(int size)Parameters
size int
Returns
Dispose()
Releases the halo texture.
public void Dispose()Draw(IRenderer, Vector2, RectF)
Draws over screenArea; cameraTopLeft is the world point at screen (0,0).
public void Draw(IRenderer r, Vector2 cameraTopLeft, RectF screenArea)Parameters
cameraTopLeft Vector2
screenArea RectF
Draw(IRenderer, Camera2D)
Convenience overload using a camera’s rendered position (including shake).
public void Draw(IRenderer r, Camera2D camera)Parameters
camera Camera2D