Header menu logo Mibo

LightContext2D Type

User-owned mutable context that collects lighting state each frame and uploads it to the GPU when lit sprites render. Shadows use analytic Signed Distance Field (SDF) raymarching in the pixel shader.

Create one in init, store it in your model, call Reset() at the start of each frame's view, then accumulate lights via LightCommands.setAmbient, addDirectionalLight, addPointLight, addOccluder, and draw lit sprites via LightCommands.litSprite.

Occluder line segments are uploaded as a uniform array to the GPU each frame. Shadow quality is controlled by the softness and maxShadowDistance parameters. SDF sphere tracing in the pixel shader produces physically-plausible soft shadows with configurable penumbra — no shadow atlas or extra render passes required.

Internally manages two shader programs: one for standard lit sprites and one for normal-mapped lit sprites. The renderer switches between them via BeginShaderMode, which is the correct way to change shader state in raylib's batch system.

Constructors

Constructor Description

LightContext2D(?litShader, ?litNormalMapShader, ?maxDirLights, ?maxPointLights, ?maxOccluders, ?softness, ?maxShadowDistance)

Full Usage: LightContext2D(?litShader, ?litNormalMapShader, ?maxDirLights, ?maxPointLights, ?maxOccluders, ?softness, ?maxShadowDistance)

Parameters:
    ?litShader : Shader
    ?litNormalMapShader : Shader
    ?maxDirLights : int
    ?maxPointLights : int
    ?maxOccluders : int
    ?softness : float32
    ?maxShadowDistance : float32

Returns: LightContext2D
?litShader : Shader
?litNormalMapShader : Shader
?maxDirLights : int
?maxPointLights : int
?maxOccluders : int
?softness : float32
?maxShadowDistance : float32
Returns: LightContext2D

Instance members

Instance member Description

this.Ambient

Full Usage: this.Ambient

Current ambient light color.

this.DirLights

Full Usage: this.DirLights

Returns: ResizeArray<DirectionalLight2D>

Directional lights accumulated this frame.

Returns: ResizeArray<DirectionalLight2D>

this.EnsureLocationsCached

Full Usage: this.EnsureLocationsCached

Ensures uniform locations are cached. Call before accessing Loc* members.

this.LocNormalMap

Full Usage: this.LocNormalMap

Returns: int

Uniform location for the normalMap sampler in the normal-map shader.

Returns: int

this.NormalMapShader

Full Usage: this.NormalMapShader

Returns: Shader

The normal-mapped lit-sprite shader. Use with sprites that have a normal map.

Returns: Shader

this.Occluders

Full Usage: this.Occluders

Returns: ResizeArray<Occluder2D>

Occluder segments accumulated this frame.

Returns: ResizeArray<Occluder2D>

this.PointLights

Full Usage: this.PointLights

Returns: ResizeArray<PointLight2D>

Point lights accumulated this frame.

Returns: ResizeArray<PointLight2D>

this.Reset

Full Usage: this.Reset

Clears accumulated lights, occluders, and resets ambient to black. Call at the start of each frame's view.

this.Shader

Full Usage: this.Shader

Returns: Shader

The standard lit-sprite shader (no normal map). Use with sprites that have no normal map.

Returns: Shader

this.ShaderActive

Full Usage: this.ShaderActive

Whether the lit shader is currently active via BeginShaderMode. Managed by commands.

this.ShadowsEnabled

Full Usage: this.ShadowsEnabled

Whether shadow raymarching is enabled for this context. Default true.

this.UniformsDirty

Full Usage: this.UniformsDirty

Whether light uniforms need to be re-uploaded to the GPU.

this.UploadUniforms

Full Usage: this.UploadUniforms

Uploads all accumulated light data, occluder segments, and shadow parameters to the GPU for both shader variants. Call once per frame when UniformsDirty is true.

Type something to start searching.