bakeIfDue method

EnvironmentMap? bakeIfDue(
  1. DateTime now
)

Advances the bake and returns a fresh environment when one completes, or null to keep the current one. Called by the engine once per frame before the render graph is built; not part of the app-facing API.

The very first bake of a binding runs in one call so the scene is lit by the sky immediately. Every later bake is time-sliced through a SkyBakeJob: one GPU pass per frame, published only when the cycle completes, so a re-bake never spikes a frame and a partial result is never visible.

Implementation

EnvironmentMap? bakeIfDue(DateTime now) {
  if (!_everBaked) {
    _everBaked = true;
    _dirty = false;
    _lastBake = now;
    return EnvironmentMap.fromSky(
      source,
      faceResolution: faceResolution,
      equirectWidth: equirectWidth,
    );
  }
  if (!_job.inFlight) {
    if (!_isDue(now)) return null;
    _dirty = false;
    _lastBake = now;
    _job.start(faceResolution: faceResolution, equirectWidth: equirectWidth);
  }
  final done = _job.advance(source, _noEnvironment);
  if (done == null) return null;
  return EnvironmentMap.fromGpuTextures(
    prefilteredRadiance: done.atlas,
    diffuseShTexture: done.sh,
  );
}