LightEffect
Defined in: packages/three-flatland/src/lights/LightEffect.ts:159
Base class for lighting effects applied to Flatland sprites.
Mirrors the PassEffect pattern: class-based, schema-driven, with property
accessors. Uses TSL uniform() nodes for zero-cost runtime parameter updates.
LightEffect produces a ColorTransformFn that is automatically assigned to
all lit sprites. The transform runs in the material shader, reading light data
from shared DataTextures managed by LightStore.
Subclasses may also override lifecycle methods (init/update/resize/dispose) to manage GPU resources like Forward+ tiling or Radiance Cascades.
Example
Section titled “Example”class DefaultLightEffect extends LightEffect { static readonly lightName = 'defaultLight' static readonly lightSchema = { ambientIntensity: 0.2 } as const static readonly needsShadows = false declare ambientIntensity: number
static buildLightFn({ uniforms, lightStore }: LightEffectBuildContext): ColorTransformFn { // build shader using lightStore.readLightData() }}Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new LightEffect():
LightEffect
Defined in: packages/three-flatland/src/lights/LightEffect.ts:297
Returns
Section titled “Returns”LightEffect
Properties
Section titled “Properties”
readonlyname:string
Defined in: packages/three-flatland/src/lights/LightEffect.ts:259
Effect name (from static).
lightName
Section titled “lightName”
readonlystaticlightName:string
Defined in: packages/three-flatland/src/lights/LightEffect.ts:165
Unique light effect name. Must be overridden by subclass.
lightSchema
Section titled “lightSchema”
readonlystaticlightSchema:EffectSchema
Defined in: packages/three-flatland/src/lights/LightEffect.ts:167
Per-effect data schema with default values. Must be overridden by subclass.
needsShadows
Section titled “needsShadows”
readonlystaticneedsShadows:boolean=false
Defined in: packages/three-flatland/src/lights/LightEffect.ts:169
Whether this effect needs the shadow/SDF pipeline.
requires
Section titled “requires”
readonlystaticrequires: readonly keyofChannelNodeMap[] =[]
Defined in: packages/three-flatland/src/lights/LightEffect.ts:171
Per-fragment channels this effect requires (e.g., [‘normal’]).
Accessors
Section titled “Accessors”Get Signature
Section titled “Get Signature”get dirty():
boolean
Defined in: packages/three-flatland/src/lights/LightEffect.ts:434
Whether this effect has been marked dirty since last clearDirty().
Returns
Section titled “Returns”boolean
enabled
Section titled “enabled”Get Signature
Section titled “Get Signature”get enabled():
boolean
Defined in: packages/three-flatland/src/lights/LightEffect.ts:402
Whether this effect is enabled.
Returns
Section titled “Returns”boolean
Set Signature
Section titled “Set Signature”set enabled(
value):void
Defined in: packages/three-flatland/src/lights/LightEffect.ts:407
Toggle enabled state. Structural change — marks lighting dirty.
Parameters
Section titled “Parameters”boolean
Returns
Section titled “Returns”void
resolutionScale
Section titled “resolutionScale”Get Signature
Section titled “Get Signature”get resolutionScale():
number
Defined in: packages/three-flatland/src/lights/LightEffect.ts:423
Processing-resolution multiplier for resources owned by this effect.
The default 1 receives the full physical drawing-buffer size; 0.5
receives half-width/half-height dimensions while camera framing and the
renderer output stay unchanged. Values must be finite and greater than 0.
Returns
Section titled “Returns”number
Set Signature
Section titled “Set Signature”set resolutionScale(
value):void
Defined in: packages/three-flatland/src/lights/LightEffect.ts:427
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”void
Methods
Section titled “Methods”build()
Section titled “build()”build(
lightStore,worldSizeNode,worldOffsetNode,sdfTexture?):ColorTransformFn
Defined in: packages/three-flatland/src/lights/LightEffect.ts:516
Build the ColorTransformFn for standalone use (no Flatland, no ECS).
Returns the lighting function that can be assigned directly to a
sprite material’s colorTransform. For batched sprites, wrap with
wrapWithLightFlags() to gate per-instance.
Parameters
Section titled “Parameters”lightStore
Section titled “lightStore”LightStore
worldSizeNode
Section titled “worldSizeNode”UniformNode <"vec2", Vector2 >
worldOffsetNode
Section titled “worldOffsetNode”UniformNode <"vec2", Vector2 >
sdfTexture?
Section titled “sdfTexture?”Texture <unknown, TextureEventMap > | null
Returns
Section titled “Returns”Example
Section titled “Example”const lightStore = new LightStore()const lighting = new DefaultLightEffect()const lightFn = lighting.build(lightStore)
sprite.material.colorTransform = lightFnsprite.material.requiredChannels = new Set(DefaultLightEffect.requires)clearDirty()
Section titled “clearDirty()”clearDirty():
void
Defined in: packages/three-flatland/src/lights/LightEffect.ts:439
Clear the dirty flag. Called by lighting systems after processing.
Returns
Section titled “Returns”void
dispose()
Section titled “dispose()”dispose():
void
Defined in: packages/three-flatland/src/lights/LightEffect.ts:555
Dispose GPU resources owned by this effect. Override in subclasses that own ForwardPlusLighting or other GPU resources.
Returns
Section titled “Returns”void
init()
Section titled “init()”init(
_ctx):void
Defined in: packages/three-flatland/src/lights/LightEffect.ts:448
Initialize GPU resources. Called lazily before the first resize and update.
Parameters
Section titled “Parameters”Returns
Section titled “Returns”void
resize()
Section titled “resize()”resize(
_width,_height):void
Defined in: packages/three-flatland/src/lights/LightEffect.ts:459
Handle processing-surface resize. Flatland derives this from the physical render surface multiplied by resolutionScale. Once a valid size exists, this is called after init and before the next update. An initial update may run first while a newly mounted canvas still reports 0×0.
Parameters
Section titled “Parameters”_width
Section titled “_width”number
_height
Section titled “_height”number
Returns
Section titled “Returns”void
update()
Section titled “update()”update(
_ctx):void
Defined in: packages/three-flatland/src/lights/LightEffect.ts:451
Per-frame GPU passes (tiling, SDF, radiance cascades).
Parameters
Section titled “Parameters”Returns
Section titled “Returns”void
buildLightFn()
Section titled “buildLightFn()”
staticbuildLightFn(_context):ColorTransformFn
Defined in: packages/three-flatland/src/lights/LightEffect.ts:189
Build the lighting ColorTransformFn. Must be overridden by subclass. Called once when the effect is attached to Flatland. The returned function closes over uniform nodes for zero-cost parameter updates.