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
|
Full Usage:
LightContext2D(?litShader, ?litNormalMapShader, ?maxDirLights, ?maxPointLights, ?maxOccluders, ?softness, ?maxShadowDistance)
Parameters:
Shader
?litNormalMapShader : Shader
?maxDirLights : int
?maxPointLights : int
?maxOccluders : int
?softness : float32
?maxShadowDistance : float32
Returns: LightContext2D
|
|
Instance members
| Instance member |
Description
|
Full Usage:
this.Ambient
|
Current ambient light color. |
|
Directional lights accumulated this frame.
|
Full Usage:
this.EnsureLocationsCached
|
Ensures uniform locations are cached. Call before accessing Loc* members. |
Full Usage:
this.LocNormalMap
Returns: int
|
Uniform location for the normalMap sampler in the normal-map shader.
|
|
The normal-mapped lit-sprite shader. Use with sprites that have a normal map.
|
|
Occluder segments accumulated this frame.
|
|
Point lights accumulated this frame.
|
Full Usage:
this.Reset
|
Clears accumulated lights, occluders, and resets ambient to black. Call at the start of each frame's view. |
|
The standard lit-sprite shader (no normal map). Use with sprites that have no normal map.
|
Full Usage:
this.ShaderActive
|
Whether the lit shader is currently active via BeginShaderMode. Managed by commands. |
Full Usage:
this.ShadowsEnabled
|
Whether shadow raymarching is enabled for this context. Default true. |
Full Usage:
this.UniformsDirty
|
Whether light uniforms need to be re-uploaded to the GPU. |
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. |
Mibo