Reference · The realistic Earth's pure parts
airFragfunction
The air as light scattered once, worked out for each pixel: a ray from the camera through the shell, sampled view times, each sample looking light times toward the Sun.
Rayleigh scattering (the air's own molecules: thicker the longer the path, and bluer) and Mie scattering (haze and dust: a bright halo round the Sun's direction), with the
scale heights and coefficients of the standard sea-level air (Rayleigh 8 km, Mie 1.2 km; the Mie coefficient is that of very clear air, 0.4 of the usual, so the haze stays blue). What the sums give, and nothing drawn: the blue haze thickening toward the limb on the day side,
the glow toward the Sun, the reddening along the day and night line (the Sun's light has crossed a long, low path) and the thin lit ring seen from the night side looking toward the Sun.
The surface under it is dimmed by what the air takes out of the light (the shader's alpha is what gets through) and what it adds is the colour.
Our own code, from the published single-scattering model (Nishita and others, 1993; O'Neil, GPU Gems 2, chapter 16), no code taken from any project.
The air can be drawn thicker than it is (thick, a uniform: 1 is the true 100 km, 3 the default of the elements): the shell and both scale heights grow by it and what each unit of length holds shrinks by it, so the same air gives the same colours over a wider glow.
The Sun is in the world's axes (sunDir, toward the Sun); ortho is 1 when the camera looks down the z axis from far away (the realistic Earth) and 0 for a camera at a place (the space view).
Import it
import { airFrag } from "@johnmorrisdotca/chikyu-earth/realistic";
Definition
function airFrag(samples: AirSamples): string
Parameters
| Name | Type | Description |
|---|---|---|
samples | AirSamples | How many samples to take ( |
Returns
string
The fragment program's source, for a ShaderMaterial.
Examples
import { airFrag, AIR_QUALITY } from "@johnmorrisdotca/chikyu-earth/realistic";
console.log(airFrag(AIR_QUALITY.light).includes("N_VIEW 6"));trueWhat it prints (run when this page was built)