evaluateLighting method
Evaluates lighting parameters based on current sun elevation.
Implementation
AtmosphericLighting evaluateLighting() {
final sunDir = sunDirection;
final elevation = sunDir.y;
if (elevation > 0.0) {
// Sun above horizon: smooth daylight to golden hour / sunset
final t = elevation.clamp(0.0, 1.0);
final smoothT = math.sin(t * math.pi * 0.5);
final sunColor =
vm.Vector3(1.0, 0.95, 0.88) * smoothT +
vm.Vector3(1.0, 0.55, 0.20) * (1.0 - smoothT);
final intensity = shadowOnly ? 0.0 : (3.0 * smoothT);
return AtmosphericLighting(
sunColor: sunColor,
sunIntensity: intensity,
environmentIntensity: (0.3 + 0.5 * smoothT).clamp(0.0, 1.0),
shadowDarkness: (0.3 + 0.7 * smoothT).clamp(0.0, 1.0),
);
} else {
// Sun below horizon: smooth transition from dusk / twilight to starry night
final nightT = (-elevation / 0.4).clamp(0.0, 1.0);
final duskColor = vm.Vector3(1.0, 0.55, 0.20);
final nightSunColor = vm.Vector3(0.20, 0.30, 0.50);
final sunColor = duskColor * (1.0 - nightT) + nightSunColor * nightT;
return AtmosphericLighting(
sunColor: sunColor,
sunIntensity: 0.0,
environmentIntensity: (0.3 * (1.0 - nightT) + 0.08 * nightT).clamp(
0.0,
1.0,
),
shadowDarkness: 0.0,
);
}
}