Sky & atmosphere
The four examples the gallery lists under Sky & atmosphere. Each block is what the gallery’s code panel shows beside that example, copied from the example itself: the lines that do it rather than the whole file, so it isn’t compiled here the way the guides’ code is. The file it came from is linked under each one.
Day and night
Section titled “Day and night”A sun and a moon crossing the sky, with the camera metered for both.
// Where the body is, at this hour.final swing = sin((hour - 6) / 12 * pi); // up for half the dayfinal isDay = swing > 0;final altitude = (isDay ? swing : -swing) * radians(65);final azimuth = hour / 24 * 2 * pi + (isDay ? 0 : pi); // the moon opposes
// The sun falls to the moon's own strength at the horizon, so the swap is a// change of direction rather than a step in how much light there is.final lux = isDay ? 1.0 + 75000 * swing * swing : 1.0;final ambient = max(0.2, lux * 0.35); // a clear sky returns a third
OrblitScene( lights: [ OrblitLight( key: 310, kind: OrblitLightKind.directional, intensity: lux, direction: -toBody..normalize(), sunAngularRadius: 0.53, // the real sun's, and the real moon's haloSize: isDay ? 12 : 3, // glare, or none: what tells them apart ), ], sky: OrblitSky(colour: skyAt(swing), ambient: ambient), // Seventeen stops between noon and moonlight. Meter it, or one of the two // is a solid colour. camera: camera.copyWith( aperture: aperture, shutterSpeed: shutter, sensitivity: iso, ),)From day_and_night.dart. To open the gallery on it:
ORBLIT_EXAMPLE='day and night' flutter run -d macosGod rays
Section titled “God rays”A low sun behind a colonnade, and the shafts of light the air between the pillars catches.
// The scene's own directional light is the sun the shafts come from, so// they always point where the shadows do. Nothing else to wire up: with no// graph of its own, the scene gets the passes it needs.OrblitScene( lights: [sun], godRays: OrblitGodRays( strength: 0.8, // how bright; nought is off, and free decay: 0.97, // how far along its length a shaft fades density: 0.9, // how far towards the sun each pixel looks samples: 64, // smoothness against cost ), ...)From god_rays.dart. To open the gallery on it:
ORBLIT_EXAMPLE='god rays' flutter run -d macosWeather
Section titled “Weather”Haze, banks of cloud and falling weather, carried by one wind.
// Haze for distance, banks for shape. One setting, because weather with no// haze behind it reads as cut-outs hanging in clear air.fog: OrblitFog( colour: Vector3(0.65, 0.69, 0.73), density: 0.055, // per metre height: -1.5, // where the layer lies heightFalloff: 0.4, // how fast it thins going up structure: 0.75, // above zero, banks of cloud are drawn as well wind: Vector2(1.8, -1.8), // metres a second, across the ground featureSize: 1 / 22, // one over how big a cloud is, in metres thickness: 6, // how deep the bank is),
// Rain and snow are one curtain at different settings: what separates them is// how far a drop travels while the shutter is open.precipitation: OrblitPrecipitation( amount: 0.65, fall: 9, // metres a second; snow is under one wind: wind, dropsPerMetre: 6, stretch: 30, // a streak. 1.2 is a flake.),
// The renderer moves both on its own clock, so a still scene keeps raining// without the host sending another frame.From weather.dart. To open the gallery on it:
ORBLIT_EXAMPLE='weather' flutter run -d macosEnvironment volumes
Section titled “Environment volumes”A sunny courtyard and a dim, dusty hall, and the look blending between them as the camera walks through the door.
// The hall's own box, and what is different about being in it. Anything// left out — here the environment, the contrast, the fog's height — is left// exactly as the scene has it.OrblitEnvironmentVolume.box( key: 1, centre: Vector3(0, 2.5, -14), halfExtents: Vector3(4, 2.5, 10), // Full strength inside; fading to nothing four metres out of the door. blendDistance: 4, overrides: OrblitEnvironmentOverrides( fogDensity: 0.09, fogColour: linearOf(const Color(0xFF8A6A4C)), ambient: 2000, // lux, blended in log space skyColour: linearOf(const Color(0xFFC89A6A)), exposureCompensation: -0.5, // stops bloomStrength: 0.25, saturation: 0.85, temperature: 0.15, ),)
// A damp corner at the back, which wins where the two overlap.OrblitEnvironmentVolume.sphere( key: 2, centre: Vector3(0, 1.5, -20), radius: 3, blendDistance: 3, priority: 1, overrides: OrblitEnvironmentOverrides( fogDensity: 0.14, fogColour: linearOf(const Color(0xFF4A5C70)), ),)
// On the scene. They are resolved against the camera when it is sent, so// nothing else has to know they are there.OrblitScene(..., volumes: [hall, corner])From volumes.dart. To open the gallery on it:
ORBLIT_EXAMPLE='environment volumes' flutter run -d macos