Skip to content

@modoki/engine / rendering / syncFog

Function: syncFog()

syncFog(world, scene): void

Apply the first active Fog entity's settings to the scene. A hybrid mechanism:

  • linear/exponential drive the classic scene.fog object (THREE.Fog/FogExp2). Despite this engine rendering exclusively through WebGPURenderer/NodeMaterial, that classic object IS the right integration point: NodeMaterial.fog defaults to true, and three's own NodeManager.updateFog() transparently converts scene.fog into the equivalent TSL node graph each render, caching it by the Fog/FogExp2 object's OWN identity and refreshing color/near/far/density via reference() nodes (NodeUpdateType.OBJECT — re-read every frame). So mutating the SAME object's fields already gets "update without recompiling the shader" for free.
  • height (density varying with world Y — fog pools in valleys, independent of camera distance) has NO classic-object equivalent, so it drives scene.fogNode directly via exponentialHeightFogFactor(density, height) — see HeightFogState above for why that node's identity must stay stable.

NodeManager.getFogNode() prefers scene.fogNode over a derived-from-scene.fog node, so whichever path is inactive must be explicitly cleared or a stale one would win. First-entity-wins + clear-on-none mirrors syncEnvironment.

Parameters

world

World

scene

Scene

Returns

void

Built with Modoki.