Header menu logo Mibo.Raylib

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.

Constructors

Constructor Description

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

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

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

Returns: LightContext2D
?litShader : 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.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 lit-sprite shader (built-in or user-supplied).

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. The lit shader must already be active (BeginShaderMode called).

Type something to start searching.