bakeIrradianceField method

IrradianceFieldBakeStepper bakeIrradianceField({
  1. int faceResolution = 16,
  2. int probesPerStep = 8,
  3. int layerMask = 0xFFFFFFFF,
})

Bakes the irradiance field by rendering the scene from every probe in the active volume.

Runs probesPerStep probes per call to the returned stepper so a load screen can stay responsive.

Implementation

IrradianceFieldBakeStepper bakeIrradianceField({
  int faceResolution = 16,
  int probesPerStep = 8,
  int layerMask = 0xFFFFFFFF,
}) {
  if (!isReadyToRender) {
    throw StateError(
      'Scene.bakeIrradianceField requires the engine resources; await '
      'Scene.initializeStaticResources() first.',
    );
  }
  renderScene.rebuildIfDirty();
  final lightComponent = renderScene.primaryDirectionalLight;
  final spotShadowFrame = collectSpotShadows(renderScene.spotLights);
  final punctualLighting = _punctualLightBuffer.build(
    directionals: renderScene.directionalLights,
    primaryDirectional: lightComponent,
    points: renderScene.pointLights,
    spots: renderScene.spotLights,
    areas: renderScene.rectAreaLights,
    items: renderScene.items,
    bvh: renderScene.bvh,
    spotShadows: spotShadowFrame,
  );
  final chosen = renderScene.irradianceVolumeComponents.isNotEmpty
      ? renderScene.irradianceVolumeComponents.first
      : null;
  final center = chosen != null ? chosen.worldCenter : Vector3.zero();
  final extents = chosen != null
      ? chosen.extents * 2.0
      : globalIllumination.extents;
  final resolution = chosen != null
      ? chosen.resolution
      : globalIllumination.resolution;
  final layout = IrradianceFieldLayout(resolution);
  final origin = center - extents * 0.5;
  final spacing = Vector3(
    resolution.x > 1 ? extents.x / (resolution.x - 1) : extents.x,
    resolution.y > 1 ? extents.y / (resolution.y - 1) : extents.y,
    resolution.z > 1 ? extents.z / (resolution.z - 1) : extents.z,
  );
  return IrradianceFieldBakeStepper(
    layout: layout,
    origin: origin,
    spacing: spacing,
    faceResolution: faceResolution,
    probesPerStep: probesPerStep,
    layerMask: layerMask,
    renderScene: renderScene,
    environmentMap: environment ?? Material.getDefaultEnvironmentMap(),
    transientsBuffer: uniformTransients,
    lightComponent: lightComponent,
    punctualLighting: punctualLighting,
    spotShadowFrame: spotShadowFrame,
    renderView: _renderViewToTexture,
  );
}