Skip to content

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:

  1. 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;
  2. 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.

C#
public sealed class LightMap : IDisposable

Inheritance

object ← LightMap

Implements

IDisposable

Constructors

LightMap(IGraphicsDevice?, PixelImage?)

C#
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.

C#
public int CellSize { get; set; }

Property Value

int

Darkness

Ambient darkness: 0 = no effect, 1 = fully Shade where unlit.

C#
public float Darkness { get; set; }

Property Value

float

GlowIntensity

Multiplier applied to every glow’s alpha (e.g. fade halos with the darkness).

C#
public float GlowIntensity { get; set; }

Property Value

float

Levels

Number of brightness bands (12 by default); fewer bands give a more stylised look.

C#
public int Levels { get; set; }

Property Value

int

LightCount

Number of lights added since the last Clear.

C#
public int LightCount { get; }

Property Value

int

Shade

The colour full darkness multiplies the scene toward.

C#
public Color Shade { get; set; }

Property Value

Color

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).

C#
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).

C#
public float BrightnessAt(Vector2 world)

Parameters

world Vector2

Returns

float

Clear()

Removes every light; call it at the start of each frame before adding lights.

C#
public void Clear()

CreateGlowImage(int)

A white radial halo with a smooth (squared smoothstep) falloff.

C#
public static PixelImage CreateGlowImage(int size)

Parameters

size int

Returns

PixelImage

Dispose()

Releases the halo texture.

C#
public void Dispose()

Draw(IRenderer, Vector2, RectF)

Draws over screenArea; cameraTopLeft is the world point at screen (0,0).

C#
public void Draw(IRenderer r, Vector2 cameraTopLeft, RectF screenArea)

Parameters

r IRenderer

cameraTopLeft Vector2

screenArea RectF

Draw(IRenderer, Camera2D)

Convenience overload using a camera’s rendered position (including shake).

C#
public void Draw(IRenderer r, Camera2D camera)

Parameters

r IRenderer

camera Camera2D