Skip to content

LightSyncSystem ​

Applies LightComponent authoring values to the underlying THREE.js light objects each frame, supporting directional, ambient, point, spot, hemisphere, and area light types.

Overview ​

LightSyncSystem runs every frame and is responsible for:

  • Writing color, intensity, castShadow, and frustumCulled to every light object.
  • Writing distance and decay for THREE.PointLight and THREE.SpotLight.
  • Writing angle and penumbra for THREE.SpotLight.
  • Writing width and height for THREE.RectAreaLight.
  • Applying the optional values.shadow block (mapSize, bias, normalBias, radius, cameraSize, near, far) to shadow-casting lights. See Tune shadow quality.

Queried components ​

ComponentAccess
LightComponentRead (values sub-state)

Behavior notes ​

  • Signature-based change detection: per-entity signatures are computed from the serialized values object each frame. Light properties are only written when the signature changes, preventing redundant THREE.js mutations on every frame.
  • Value clamping: intensity is clamped to ≥ 0. distance is clamped to ≥ 0. angle is clamped to [0, π/2]. penumbra is clamped to [0, 1]. Non-finite values use safe defaults.
  • Shadow fields: only the fields present in values.shadow are written; a light without the block keeps three's defaults. Removing a field restores its default. A new mapSize disposes the allocated shadow map so three rebuilds it at the new size, and any camera change calls shadow.camera.updateProjectionMatrix(). mapSize is clamped to [16, 8192].
  • Stale entity cleanup: when an entity is destroyed the system removes its entry from the signature map to prevent unbounded memory growth.

API reference ​