@johnmorrisdotca/wakusei-planets 0.66.0 → 0.67.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,17 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.67.0] - 2026-11-18
6
+
7
+ - **`<wakusei-surface>`: the camera glides from the watched descent to the standing view, to the rover and between its two cameras, with no jump cut** (MODULES-1561). When `watch` is taken off, `drive="on"` starts or the watch's camera changes, the camera moves from where the watched descent (the window or the ground camera) had it to the new view in 1.1 seconds, easing out and in, with the eye keeping its height above the ground so that it does not pass under a hill, the azimuth turning the short way and the field of view blended. New attribute `glide` (`off` for the cut, or the milliseconds), new `camera` (the pose of the last draw) and `stats.gliding`; a reader who prefers reduced motion gets the cut, and a press or a key on the view ends the move. A move from a move (the watch ends, then the rover starts) goes on from where the first had got to. Switching between the window and the ground camera while watching (or moving where the ground camera stands with `watch-from`) is a move too. Tests: `test/glide.test.ts` (the curve, the blend, the heights, and when a move starts) and `e2e/surface-glide.demo.ts` (the pose of each draw is sampled on the way: no step is most of the way, it arrives, `glide=off` and reduced motion cut).
8
+
9
+ - **`bodyPhysics(id)`: mass, GM, surface gravity, the air at the surface and the surface temperature, each with its source and the day it was read** (MODULES-1553). New entry `@johnmorrisdotca/wakusei-planets/body-physics` for the Sun, the eight planets, Pluto and the Moon. Every figure is `{ value, unit, source: { name, url, pageUpdated, read } }` with the sheet's own wording in `quoted` where it is not a plain number, `bound` (`"below"` or `"about"`), `uncertainty`, `low` and `high`, `level` and `note`, and `bodyPhysics` gives `null` for a body that has no sheet (the dwarf planets and the other moons), and a field is `null` where the sheet has none (the Sun, Mercury, the Moon and Pluto have no air density; the Moon and Pluto give a range of temperature and no single figure). The gas giants' gravity, density and temperature are at the 1 bar level, which is also their pressure (100,000 Pa); Mercury's pressure is the sheet's upper limit. All from NASA's NSSDC planetary fact sheets, read 2026-11-18 (`NOTICE.md`). Guide [Physics of a body](docs/guides/body-physics.md), in English and Japanese. Tests: `test/body-physics.test.ts`.
10
+
11
+ - **`<wakusei-surface>`: a drag turns the view while the descent is watched** (MODULES-1546). The watched landing points its camera at each frame (at the stage from the ground, along the lunar module's heading from its window), and a drag wrote the new direction straight into the view, which the next frame of the running descent put back, so the view could not be turned. A drag now adds to a turn kept beside the camera, as the rover's view does, which every frame adds to where the camera points by itself; the pitch stops at 60 degrees either side, a paused descent is drawn again at once, and the turn is cleared when the camera is changed. Tests: `test/surface.test.ts` (the turn, its limit, and that it holds at every frame of the descent).
12
+
13
+ - **`<wakusei-surface>`: a made crater's floor no longer flickers black while the descent is watched** (MODULES-1547). Two causes, both in the quality of motion (the draws while the view changes). The Sun's march (`lit` in the ground's shader) leaves the made craters out of the march in that quality (`uNear.z` is 0) but set its start point down in the crater's floor, so the ray ran over ground without the crater and found it above its own start: the whole floor was black. The start now leaves the craters out wherever the march does. And the running descent was drawn at the quality of rest whenever a slow draw let the 160 ms since the last change run out, so one frame in a few had the crater's own shadow and the rest had the black floor: while the descent plays, every frame is now at the quality of motion. `test/api-snapshot.txt` changes only by a private member (`#movingNow`). Tests: `test/surface.test.ts`.
14
+
15
+
5
16
  ## [0.66.0] - 2026-11-18
6
17
 
7
18
  - **The irregular moons of `/moon-catalogue` follow JPL Horizons near the present** (MODULES-1091). With JPL's mean elements the irregular moons are 10 to 150 degrees from their real places within a year and a half, because a mean orbit cannot follow the Sun's pull. Each of the 393 irregular moons of the four giant planets now also has its osculating orbit on 2026-12-01 (`osculating`, `MoonOsculating`, `MOON_OSCULATING_EPOCH_JD`), and `catalogueMoonPosition` uses it within `MOON_OSCULATING_DAYS` (150) of that day and the mean orbit outside, so the space view's dots for them are where Horizons has them. Measured on 16 dates the orbit was not set from (15 to 210 days either side): within 150 days, over every moon at every date, the median is 0.06 degrees, 95 places in 100 are within 0.9 degrees and the worst, a few of Jupiter's at the edge of the window, is 7 degrees (Saturn's worst 1.1, Uranus's and Neptune's 0.1). The numbers are whole numbers (a to 100 km, e to 0.0001, angles to 0.01 degree: under 90 km of rounding) in `src/data/moon-osculating.ts`, made by `scripts/make-moon-osculating.py` (one Horizons request a moon, cached outside the repository, a refresh is a run with a new `--epoch`), and cost 7 kB gzipped: the `/moon-catalogue` chunk grows from 36.5 to 43.6 kB (its budget in the test is 45 kB and its size baseline is moved). `accuracy` and `grade` still describe the mean orbit on dates outside the window. A test (`test/moon-osculating.test.ts`) holds a sample of every group to Horizons' own places. The regular moons and the 29 drawn moons are unchanged.
package/NOTICE.md CHANGED
@@ -20,6 +20,7 @@ No picture is used by the line and shaded looks: they are drawn from numbers.
20
20
  - **Where the planets are in the sky (`/sky-bodies`)**, 2026-11-13: the positions are this package's own (the Sun and the Moon of `/suncalc`, VSOP87B for the planets, Pluto's table above). The planets' apparent magnitudes are the formulas of the Astronomical Almanac as given in A. Mallama and J. L. Hilton (2018), "Computing Apparent Planetary Magnitudes for The Astronomical Almanac", Astronomy and Computing 25, 10 (arXiv:1808.01973, read online 2026-11-13): the formulas only, typed as code (Mercury, Venus, Mars without its surface-albedo terms, Jupiter, Saturn with its rings, Uranus, Neptune after 2000); the Sun's apparent magnitude of -26.74 at one astronomical unit is the visual magnitude V(1,0) of NASA's Sun Fact Sheet (https://nssdc.gsfc.nasa.gov/planetary/factsheet/sunfact.html, read 2026-11-13), scaled by 5 log10 of the distance in astronomical units as in the JPL Horizons manual (https://ssd.jpl.nasa.gov/horizons/manual.html, read 2026-11-13); the Moon's magnitude law (-12.73 + 0.026 |phase angle| + 4e-9 phase angle to the fourth, plus 5 log10 of the distance over 384400 km) is the one the same Horizons manual gives for the Moon, after Krisciunas and Schaefer (1991), "A model of the brightness of moonlight", Publications of the Astronomical Society of the Pacific 103, 1033, cross-checked with the -12.74 of NASA's Moon Fact Sheet (https://nssdc.gsfc.nasa.gov/planetary/factsheet/moonfact.html, read 2026-11-13): the constants only, typed as code; and Pluto's H = -0.55 is from the JPL Small-Body Database (https://ssd-api.jpl.nasa.gov/sbdb.api, read 2026-11-13). The figures the tests compare with are numbers read online from JPL Horizons (https://ssd.jpl.nasa.gov/api/horizons.api, observer tables read 2026-11-13: R.A. and DEC (ICRF) and (a-appar), APmag, Illu%, Ang-diam, S-O-T, and Azi and Elev (a-app) for Tokyo, 139.69 E 35.69 N 40 m, and Ottawa, 75.70 W 45.42 N 70 m), on 2024-03-20 12:00, 2026-06-21 12:00 and 2030-12-01 00:00 UTC. Facts only: no text or file is copied.
21
21
  - **Stars (`/stars`)**: the Yale Bright Star Catalogue, D. Hoffleit and W. H. Warren Jr. (1991), "The Bright Star Catalogue, 5th Revised Edition (Preliminary Version)", Astronomical Data Center (NASA Goddard Space Flight Center) and the Centre de Données astronomiques de Strasbourg, catalogue V/50, as NASA's HEASARC serves it (table bsc5p, https://heasarc.gsfc.nasa.gov/W3Browse/star-catalog/bsc5p.html, file heasarc_bsc5p.tdat.gz, read 2026-11-08; a US government source), the 5,080 stars to visual magnitude 6.0, written out as numbers by `scripts/make-star-data.py` into `src/data/stars.ts`. The catalogue's own documentation calls it public domain and the Astronomical Data Center asks that it and the authors be acknowledged, which this line does; there is no formal licence text, so this footing is informal. The common names are our own list after the IAU Working Group on Star Names (https://www.iau.org/science/scientific_bodies/working_groups/280/); the star colour is Ballesteros's B-V to temperature relation (F. J. Ballesteros 2012, EPL 97, 34008) and a piecewise black-body colour fit. Deliberately NOT used: the Hipparcos, Tycho and Gaia catalogues (ESA, CC BY-NC 3.0 IGO, non-commercial), and HYG, AT-HYG and OpenNGC (CC BY-SA, which would put share-alike terms on this package's data).
22
22
  - **Mass and escape speed** (`JOURNEY_STOPS`): JPL "Planetary Satellite Physical Parameters" (https://ssd.jpl.nasa.gov/sats/phys_par/, read 2026-11-04) for the GM of the Earth, Mars through Pluto and the moons on that page; NASA's Sun, Mercury and Venus fact sheets (https://nssdc.gsfc.nasa.gov/planetary/factsheet/, read 2026-11-04) for those three GM values and the Sun's escape speed; JPL "Planetary Physical Parameters" (https://ssd.jpl.nasa.gov/planets/phys_par.html, read 2026-11-04) for the planets' escape speeds and for the masses of Ceres, Eris, Makemake and Haumea, turned into GM with the CODATA 2018 G that page names. A moon's escape speed is computed from its GM and the radius already in this package. Nereid, Orcus, Quaoar, Gonggong, Sedna, Vanth, Hiʻiaka, Namaka and Dysnomia are left blank: those pages do not print a mass.
23
+ - **Physics of a body (`bodyPhysics` in `@johnmorrisdotca/wakusei-planets/body-physics`, `src/body-physics.ts`)**: NASA Space Science Data Coordinated Archive (NSSDC), the planetary fact sheets of the Sun, Mercury, Venus, Earth, Moon, Mars, Jupiter, Saturn, Uranus, Neptune and Pluto (https://nssdc.gsfc.nasa.gov/planetary/factsheet/<body>fact.html; one page each, read 2026-11-18; the day each page says it was last updated is in the table, 2024-01-11 to 2025-05-19). The robots.txt of nssdc.gsfc.nasa.gov does not disallow /planetary/. The figures are facts typed as a table (mass, GM, surface gravity, and the surface air density, pressure and temperature, or the 1 bar level's for the gas giants), with the sheet's own wording kept where it is not a plain number; none of the pages' text is copied, and a figure a page does not give is left out, not estimated. GM here is the sheet's, to the digits it prints; `JOURNEY_STOPS` above carries JPL's GM to more digits for the same bodies.
23
24
 
24
25
  ## The dwarf planets
25
26
 
package/README.md CHANGED
@@ -19,7 +19,7 @@ Wakusei Planets runs in the browser of a phone, a tablet or a computer: nothing
19
19
 
20
20
  <p align="center"><img alt="The demo on a desk: Saturn in the painted look, turning in the big view, with the page's links to the portrait builder, the colouring sheets, the space view, the star page and the size line-up above it, and the choice of body and its moons below" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/main/docs/images/home-desk.webp" width="620"> <img alt="The same page on a phone: the same links in rows, and Saturn in the painted look below them" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/main/docs/images/home-phone.webp" width="200"></p>
21
21
 
22
- <p align="center"><img alt="Every body at one scale, the Earth among them: each small body has a magnified picture joined by a line, and the Sun shows only its edge" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.66.0/docs/images/lineup-desk.png" width="640"></p>
22
+ <p align="center"><img alt="Every body at one scale, the Earth among them: each small body has a magnified picture joined by a line, and the Sun shows only its edge" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.67.0/docs/images/lineup-desk.png" width="640"></p>
23
23
 
24
24
  ## Who it is for
25
25
 
@@ -412,7 +412,7 @@ The tiles of every body share one 48 MB budget, six loads at a time for a source
412
412
 
413
413
  ## The portrait builder
414
414
 
415
- <p align="center"><img alt="The Sun and the planets in an arc, painted, with their names, in the portrait builder" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.66.0/docs/images/portrait-family.png" width="640"></p>
415
+ <p align="center"><img alt="The Sun and the planets in an arc, painted, with their names, in the portrait builder" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.67.0/docs/images/portrait-family.png" width="640"></p>
416
416
 
417
417
  [The portrait builder](https://johnmorrisdotca.github.io/wakusei-planets/portrait.html) puts any bodies in one picture: drag them, size them, turn them, order them front to back, arrange them in a row, an arc, a grid or at true orbit distance (true or readable sizes, a planet's moons round it in orbit order), light them from one direction, and take the code, a PNG or an SVG. The scene is kept in the address, and every body is drawn in one WebGL scene, so the page holds one WebGL context. [The portrait builder](docs/guides/portrait-builder.md) is its guide.
418
418
 
@@ -568,7 +568,7 @@ BODIES.pluto.kind; // "dwarf-planet"
568
568
 
569
569
  If this package helps a paper, a talk or a class, please cite it as software. GitHub's "Cite this repository" button reads [CITATION.cff](CITATION.cff) and gives BibTeX and APA; in plain text:
570
570
 
571
- > Morris, J. (2026). *Wakusei Planets* (version 0.66.0) [Computer software]. https://github.com/johnmorrisdotca/wakusei-planets
571
+ > Morris, J. (2026). *Wakusei Planets* (version 0.67.0) [Computer software]. https://github.com/johnmorrisdotca/wakusei-planets
572
572
 
573
573
  Cite the version you used (`npm ls @johnmorrisdotca/wakusei-planets`), and cite the sources of the numbers you use as well: [NOTICE.md](NOTICE.md) names each one, with the paper or the page it was read from (the IAU working group's report for sizes and poles, VSOP87B, ELP2000-82B, L1.2 and TASS1.7 for positions, and NASA's JPL Horizons for the fits and the spacecraft).
574
574
 
@@ -0,0 +1,114 @@
1
+ /**
2
+ * The bodies that have a physics sheet: the Sun, the eight planets, Pluto and the Moon.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * import { PHYSICS_IDS } from "@johnmorrisdotca/wakusei-planets/body-physics";
7
+ *
8
+ * console.log(PHYSICS_IDS.join(", "));
9
+ * ```
10
+ */
11
+ export declare const PHYSICS_IDS: readonly ["sun", "mercury", "venus", "earth", "moon", "mars", "jupiter", "saturn", "uranus", "neptune", "pluto"];
12
+ /**
13
+ * The id of a body that has a physics sheet.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * import { PHYSICS_IDS, type PhysicsId } from "@johnmorrisdotca/wakusei-planets/body-physics";
18
+ *
19
+ * const id: PhysicsId = PHYSICS_IDS[3];
20
+ * console.log(id);
21
+ * ```
22
+ */
23
+ export type PhysicsId = (typeof PHYSICS_IDS)[number];
24
+ /**
25
+ * Where a figure was read: the page, the day the page says it was last updated, and the day it was read for this package.
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * import { bodyPhysics, type PhysicsSource } from "@johnmorrisdotca/wakusei-planets/body-physics";
30
+ *
31
+ * const source: PhysicsSource = bodyPhysics("mars").mass!.source;
32
+ * console.log(source.url, source.pageUpdated, source.read);
33
+ * ```
34
+ */
35
+ export interface PhysicsSource {
36
+ name: string;
37
+ url: string;
38
+ /** The day the page says it was last updated (`2025-05-19`). */
39
+ pageUpdated: string;
40
+ /** The day the page was read for this package. */
41
+ read: string;
42
+ }
43
+ /**
44
+ * One figure: its number in SI units (or the unit named), where it comes from, how the source writes it, and what it holds at.
45
+ *
46
+ * `quoted` is the source's own wording of the figure where it is not a plain number (`"~0.016 +/- 0.006 kg/m3"`, `"1014 mb"`, `">>1000 bars"`). `bound` is `"below"` for a figure the source gives as an upper limit and `"about"` for one it marks approximate. `uncertainty`
47
+ * is the +/- the source gives, in the same unit. `low` and `high` are the range it gives (a season, a day). `level` says where a figure holds when it is not the surface: `"1 bar"` for the gas giants, whose sheets give gravity, density and temperature at the 1 bar level, and
48
+ * `"top of photosphere"` for the Sun's pressure.
49
+ *
50
+ * @example
51
+ * ```ts
52
+ * import { bodyPhysics, type PhysicsReading } from "@johnmorrisdotca/wakusei-planets/body-physics";
53
+ *
54
+ * const density: PhysicsReading = bodyPhysics("mars").airDensity!;
55
+ * console.log(density.value, density.unit, density.uncertainty, density.quoted);
56
+ * ```
57
+ */
58
+ export interface PhysicsReading {
59
+ value: number;
60
+ unit: "kg" | "km3/s2" | "m/s2" | "kg/m3" | "Pa" | "K";
61
+ source: PhysicsSource;
62
+ quoted?: string;
63
+ bound?: "below" | "about";
64
+ uncertainty?: number;
65
+ low?: number;
66
+ high?: number;
67
+ level?: string;
68
+ note?: string;
69
+ }
70
+ /**
71
+ * The physics of a body. Each field is `null` where the source has no figure: the Sun, Mercury, the Moon and Pluto have no air density, and the Moon and Pluto's sheets give a range of temperature and no single figure (it is in `temperature.low` and `high`, with `value` `null`).
72
+ *
73
+ * @example
74
+ * ```ts
75
+ * import { bodyPhysics, type BodyPhysics } from "@johnmorrisdotca/wakusei-planets/body-physics";
76
+ *
77
+ * const earth: BodyPhysics = bodyPhysics("earth");
78
+ * console.log(earth.surfaceGravity?.value, earth.pressure?.value, earth.temperature?.value);
79
+ * ```
80
+ */
81
+ export interface BodyPhysics {
82
+ id: PhysicsId;
83
+ /** The mass in kilograms. */
84
+ mass: PhysicsReading | null;
85
+ /** The gravitational parameter GM in km3/s2. */
86
+ gm: PhysicsReading | null;
87
+ /** The surface gravity in m/s2: the mean at the surface, the Sun's at its equator, and the gas giants' at the 1 bar level. */
88
+ surfaceGravity: PhysicsReading | null;
89
+ /** The density of the air at the surface in kg/m3, or at the 1 bar level for the gas giants. */
90
+ airDensity: PhysicsReading | null;
91
+ /** The pressure at the surface in pascals, at the 1 bar level (100,000 Pa, the sheet's level) for the gas giants, or at the top of the Sun's photosphere. */
92
+ pressure: PhysicsReading | null;
93
+ /** The temperature in kelvin: the mean at the surface, the 1 bar level's for the gas giants, the Sun's effective temperature. `value` is `null` where the sheet gives only a range. */
94
+ temperature: (Omit<PhysicsReading, "value"> & {
95
+ value: number | null;
96
+ }) | null;
97
+ }
98
+ /**
99
+ * The physics of the Sun, a planet, Pluto or the Moon: its mass and GM, its surface gravity, the air at its surface and its surface temperature, each with the page and day it was read from, and `null` where the source has none (the Sun, Mercury, the Moon and Pluto have no air
100
+ * density).
101
+ *
102
+ * @param id - `"sun"`, `"mercury"` to `"neptune"`, `"pluto"` or `"moon"`; any other id (a dwarf planet, another planet's moon) has no sheet.
103
+ * @returns The physics (a new object each call), or `null` for a body that has no sheet, so a page can leave its physics out for it.
104
+ *
105
+ * @example
106
+ * ```ts
107
+ * import { bodyPhysics } from "@johnmorrisdotca/wakusei-planets/body-physics";
108
+ *
109
+ * const jupiter = bodyPhysics("jupiter");
110
+ * console.log(jupiter.surfaceGravity?.value, jupiter.surfaceGravity?.level, jupiter.temperature?.value, jupiter.temperature?.source.read);
111
+ * ```
112
+ */
113
+ export declare function bodyPhysics(id: PhysicsId): BodyPhysics;
114
+ export declare function bodyPhysics(id: string): BodyPhysics | null;
@@ -0,0 +1,162 @@
1
+ // What a physics model of a body needs, as data (MODULES-1553): mass and GM, surface gravity, the air at the surface, and the surface temperature, each figure with where it was read and the day it was read, and left out where the source has none. Every number is a fact
2
+ // read from NASA's planetary fact sheets (NSSDC, https://nssdc.gsfc.nasa.gov/planetary/factsheet/) on 2026-11-18, one page for each body, with the page's own "Last Updated" day beside it; no text of the pages is copied. Pure: no DOM, no clock reads, no three.js.
3
+ /**
4
+ * The bodies that have a physics sheet: the Sun, the eight planets, Pluto and the Moon.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * import { PHYSICS_IDS } from "@johnmorrisdotca/wakusei-planets/body-physics";
9
+ *
10
+ * console.log(PHYSICS_IDS.join(", "));
11
+ * ```
12
+ */
13
+ export const PHYSICS_IDS = ["sun", "mercury", "venus", "earth", "moon", "mars", "jupiter", "saturn", "uranus", "neptune", "pluto"];
14
+ const READ = "2026-11-18";
15
+ const PAGE = "https://nssdc.gsfc.nasa.gov/planetary/factsheet/";
16
+ const NAME = { sun: "Sun", mercury: "Mercury", venus: "Venus", earth: "Earth", moon: "Moon", mars: "Mars", jupiter: "Jupiter", saturn: "Saturn", uranus: "Uranus", neptune: "Neptune", pluto: "Pluto" };
17
+ // the day each page says it was last updated (its own "Last Updated" line)
18
+ const UPDATED = {
19
+ sun: "2024-05-09",
20
+ mercury: "2024-01-11",
21
+ venus: "2024-01-11",
22
+ earth: "2024-11-15",
23
+ moon: "2024-01-11",
24
+ mars: "2025-05-19",
25
+ jupiter: "2024-10-02",
26
+ saturn: "2025-03-18",
27
+ uranus: "2024-10-02",
28
+ neptune: "2024-10-03",
29
+ pluto: "2024-01-11",
30
+ };
31
+ const ROWS = {
32
+ sun: {
33
+ mass: 1_988_400,
34
+ gm: 132_712,
35
+ gravity: 274.0,
36
+ gravityNote: "at the equator",
37
+ pressure: { bar: 0.000868, quoted: "0.868 mb", level: "top of photosphere" },
38
+ temperature: { value: 5772, quoted: "5772 K", level: "effective", note: "the effective temperature; 4400 K at the top of the photosphere and 6600 K at the bottom" },
39
+ },
40
+ mercury: {
41
+ mass: 0.3301,
42
+ gm: 0.022032,
43
+ gravity: 3.7,
44
+ pressure: { bar: 5e-15, quoted: "<~5 x 10-15 bar", bound: "below" },
45
+ temperature: { value: 440, quoted: "440 K (167 C)", note: "the average; 590 to 725 K on the sunward side" },
46
+ },
47
+ venus: {
48
+ mass: 4.8673,
49
+ gm: 0.32486,
50
+ gravity: 8.87,
51
+ density: { value: 65, quoted: "~65. kg/m3", bound: "about" },
52
+ pressure: { bar: 92, quoted: "92 bars" },
53
+ temperature: { value: 737, quoted: "737 K (464 C)" },
54
+ },
55
+ earth: {
56
+ mass: 5.9722,
57
+ gm: 0.3986,
58
+ gravity: 9.82,
59
+ density: { value: 1.217, quoted: "1.217 kg/m3" },
60
+ pressure: { bar: 1.014, quoted: "1014 mb" },
61
+ temperature: { value: 288, quoted: "288 K (15 C)", low: 283, high: 293, note: "the average; the diurnal range is 283 to 293 K" },
62
+ },
63
+ moon: {
64
+ mass: 0.07346,
65
+ gm: 0.0049,
66
+ gravity: 1.62,
67
+ pressure: { bar: 3e-15, quoted: "3 x 10-15 bar", note: "at night" },
68
+ temperature: { value: null, quoted: "95 K to 390 K", low: 95, high: 390, note: "the diurnal range at the equator" },
69
+ },
70
+ mars: {
71
+ mass: 0.64169,
72
+ gm: 0.042828,
73
+ gravity: 3.73,
74
+ density: { value: 0.016, quoted: "~0.016 +/- 0.006 kg/m3", bound: "about", uncertainty: 0.006 },
75
+ pressure: { bar: 0.00636, quoted: "6.36 mb at mean radius (variable from 4.0 to 8.7 mb depending on season)", low: 0.004, high: 0.0087, note: "at the mean radius" },
76
+ temperature: { value: 214, quoted: "~214 K (-59 C)", bound: "about", low: 184, high: 242, note: "the average; the diurnal range 184 to 242 K is at the Viking 1 lander site" },
77
+ },
78
+ jupiter: {
79
+ mass: 1_898.13,
80
+ gm: 126.687,
81
+ gravity: 25.92,
82
+ gravityLevel: "1 bar",
83
+ density: { value: 0.16, quoted: "0.16 kg/m3", level: "1 bar" },
84
+ pressure: { bar: 1, quoted: "1 bar", level: "1 bar", note: "the 1 bar level, where the sheet gives the gravity, density and temperature; it gives no surface" },
85
+ temperature: { value: 165, quoted: "165 K (-108 C)", level: "1 bar" },
86
+ },
87
+ saturn: {
88
+ mass: 568.32,
89
+ gm: 37.931,
90
+ gravity: 11.19,
91
+ gravityLevel: "1 bar",
92
+ density: { value: 0.19, quoted: "0.19 kg/m3", level: "1 bar" },
93
+ pressure: { bar: 1, quoted: "1 bar", level: "1 bar", note: "the 1 bar level, where the sheet gives the gravity, density and temperature; it gives no surface" },
94
+ temperature: { value: 134, quoted: "134 K (-139 C)", level: "1 bar" },
95
+ },
96
+ uranus: {
97
+ mass: 86.811,
98
+ gm: 5.794,
99
+ gravity: 9.01,
100
+ gravityLevel: "1 bar",
101
+ density: { value: 0.42, quoted: "0.42 kg/m3", level: "1 bar" },
102
+ pressure: { bar: 1, quoted: "1 bar", level: "1 bar", note: "the 1 bar level, where the sheet gives the gravity, density and temperature; it gives no surface" },
103
+ temperature: { value: 76, quoted: "76 K (-197 C)", level: "1 bar" },
104
+ },
105
+ neptune: {
106
+ mass: 102.409,
107
+ gm: 6.8351,
108
+ gravity: 11.27,
109
+ gravityLevel: "1 bar",
110
+ density: { value: 0.45, quoted: "0.45 kg/m3", level: "1 bar" },
111
+ pressure: { bar: 1, quoted: "1 bar", level: "1 bar", note: "the 1 bar level, where the sheet gives the gravity, density and temperature; it gives no surface" },
112
+ temperature: { value: 72, quoted: "72 K (-201 C)", level: "1 bar" },
113
+ },
114
+ pluto: {
115
+ mass: 0.01303,
116
+ gm: 0.00087,
117
+ gravity: 0.62,
118
+ pressure: { bar: 1.3e-5, quoted: "~13 microbar", bound: "about" },
119
+ temperature: { value: null, quoted: "24 - 38 K (-247 - -233 C)", low: 24, high: 38 },
120
+ },
121
+ };
122
+ const BAR_PA = 100_000;
123
+ /** A product written without the float noise of a scale (`0.00636 * 1e5` is not 636 to the last bit). */
124
+ const scaled = (value, factor) => Number((value * factor).toPrecision(12));
125
+ export function bodyPhysics(id) {
126
+ if (!PHYSICS_IDS.includes(id))
127
+ return null;
128
+ const body = id;
129
+ const row = ROWS[body];
130
+ const source = () => ({ name: `NASA NSSDC Planetary Fact Sheet: ${NAME[body]}`, url: `${PAGE}${body}fact.html`, pageUpdated: UPDATED[body], read: READ });
131
+ const mass = { value: scaled(row.mass, 1e24), unit: "kg", source: source() };
132
+ const gm = { value: scaled(row.gm, 1e6), unit: "km3/s2", source: source() };
133
+ const gravity = { value: row.gravity, unit: "m/s2", source: source(), ...(row.gravityLevel === undefined ? {} : { level: row.gravityLevel }), ...(row.gravityNote === undefined ? {} : { note: row.gravityNote }) };
134
+ const d = row.density;
135
+ const p = row.pressure;
136
+ const t = row.temperature;
137
+ return {
138
+ id: body,
139
+ mass,
140
+ gm,
141
+ surfaceGravity: gravity,
142
+ airDensity: d === undefined
143
+ ? null
144
+ : { value: d.value, unit: "kg/m3", source: source(), quoted: d.quoted, ...(d.bound === undefined ? {} : { bound: d.bound }), ...(d.uncertainty === undefined ? {} : { uncertainty: d.uncertainty }), ...(d.level === undefined ? {} : { level: d.level }) },
145
+ pressure: p === undefined
146
+ ? null
147
+ : {
148
+ value: scaled(p.bar, BAR_PA),
149
+ unit: "Pa",
150
+ source: source(),
151
+ quoted: p.quoted,
152
+ ...(p.bound === undefined ? {} : { bound: p.bound }),
153
+ ...(p.low === undefined ? {} : { low: scaled(p.low, BAR_PA) }),
154
+ ...(p.high === undefined ? {} : { high: scaled(p.high, BAR_PA) }),
155
+ ...(p.level === undefined ? {} : { level: p.level }),
156
+ ...(p.note === undefined ? {} : { note: p.note }),
157
+ },
158
+ temperature: t === undefined
159
+ ? null
160
+ : { value: t.value, unit: "K", source: source(), quoted: t.quoted, ...(t.bound === undefined ? {} : { bound: t.bound }), ...(t.low === undefined ? {} : { low: t.low }), ...(t.high === undefined ? {} : { high: t.high }), ...(t.level === undefined ? {} : { level: t.level }), ...(t.note === undefined ? {} : { note: t.note }) },
161
+ };
162
+ }
@@ -77,6 +77,7 @@ export declare class WakuseiSurface extends HTMLElement {
77
77
  renderer: SharedRenderer<ThreeParts>["stats"] | undefined;
78
78
  mesh: SurfaceScene["mesh"] | undefined;
79
79
  quality: string;
80
+ gliding: boolean;
80
81
  scale: number;
81
82
  scaled: number;
82
83
  landing: {
@@ -91,6 +92,13 @@ export declare class WakuseiSurface extends HTMLElement {
91
92
  rocks: number;
92
93
  vehicleDrawn: boolean;
93
94
  };
95
+ /** Where the camera was in the last draw: the eye (metres east and north of the site, and its height) and the look; during a move it is the pose on the way, not where the view will end. `undefined` before the first draw. */
96
+ get camera(): {
97
+ east: number;
98
+ north: number;
99
+ up: number;
100
+ look: Look;
101
+ } | undefined;
94
102
  connectedCallback(): void;
95
103
  disconnectedCallback(): void;
96
104
  attributeChangedCallback(name: string): void;
@@ -4,7 +4,7 @@ import { TILES_BASE } from "../scene/textures.js";
4
4
  import { madeGround, rocksAround, setKeepOut, standingPlace } from "./detail.js";
5
5
  import { driveStep, driveView, ROVER, startDrive, toWorld } from "./drive.js";
6
6
  import { DustField } from "./dust.js";
7
- import { calloutsBy, clockText, LANDING, landingAt } from "./landing.js";
7
+ import { calloutsBy, clockText, LANDING, landingAt, turnedBy, watchedLook } from "./landing.js";
8
8
  import { drop, groundAt } from "./height.js";
9
9
  import { loadTerrain } from "./load.js";
10
10
  import { createSurfaceItem } from "./scene.js";
@@ -12,6 +12,7 @@ import { objectsOf, traverseOf } from "./objects.js";
12
12
  import { standSky } from "./sky.js";
13
13
  import { flatTerrain } from "./flat.js";
14
14
  import { siteById } from "./site.js";
15
+ import { blendPose, easeInOut, GLIDE_MS } from "./glide.js";
15
16
  import { clampLook, EYE_HEIGHT, stepOver, viewProjection, WALK_SPEED } from "./view.js";
16
17
  export { setThreeLoader };
17
18
  const TEMPLATE = `<style>
@@ -121,6 +122,10 @@ export class WakuseiSurface extends HTMLElement {
121
122
  #modelAbort;
122
123
  #driveCamera = "chase";
123
124
  #camOffset = { azimuth: 0, pitch: 0 };
125
+ /** The pose the last draw used, and whether it was the watched descent's (or a move from it still going): where a move to the standing view or the rover starts (MODULES-1561). */
126
+ #lastPose;
127
+ /** A smooth move of the camera in progress, from the pose it started at to wherever the view now puts it. */
128
+ #glide;
124
129
  #driveEyeUp = 0;
125
130
  #trail = [];
126
131
  #dust = new DustField(900, 17);
@@ -184,14 +189,23 @@ export class WakuseiSurface extends HTMLElement {
184
189
  /** Numbers for a test or a status line: the draws, the tiles, the renderer's own counts, the mesh, the quality of the last draw and the milliseconds of the last measured one. */
185
190
  get stats() {
186
191
  const scene = this.#view?.scene;
187
- return { state: this.#state, draws: this.#draws, tiles: this.#progress, renderer: this.#renderer?.stats, mesh: scene?.mesh, quality: this.#quality(), scale: this.#drawScale, scaled: this.#scaled, landing: this.landing, vehicle: this.#vehicle === undefined ? undefined : { ...this.#vehicle, spin: [...this.#vehicle.spin] }, drawMs: scene?.drawMs ?? this.#drawMs, rocks: scene?.rocks ?? 0, vehicleDrawn: scene?.vehicleDrawn ?? false };
192
+ return { state: this.#state, draws: this.#draws, tiles: this.#progress, renderer: this.#renderer?.stats, mesh: scene?.mesh, quality: this.#quality(), gliding: this.#glide !== undefined, scale: this.#drawScale, scaled: this.#scaled, landing: this.landing, vehicle: this.#vehicle === undefined ? undefined : { ...this.#vehicle, spin: [...this.#vehicle.spin] }, drawMs: scene?.drawMs ?? this.#drawMs, rocks: scene?.rocks ?? 0, vehicleDrawn: scene?.vehicleDrawn ?? false };
193
+ }
194
+ /** Where the camera was in the last draw: the eye (metres east and north of the site, and its height) and the look; during a move it is the pose on the way, not where the view will end. `undefined` before the first draw. */
195
+ get camera() {
196
+ const last = this.#lastPose?.pose;
197
+ return last === undefined ? undefined : { east: last.east, north: last.north, up: last.up, look: { ...last.look } };
198
+ }
199
+ /** Whether the draws are those of a view in motion: the view moved a moment ago, or the watched descent is running (its frames come every 33 ms, but a slow draw can leave the 160 ms of the last change behind: the frame after that was drawn at the quality of rest and the next at the quality of motion, and the ground flickered, MODULES-1547). */
200
+ #movingNow() {
201
+ return this.#moving || this.#landing?.playing === true;
188
202
  }
189
203
  /** The quality of the next draw: the `quality` attribute, or in `auto` the quality of motion while the view moves and the machine's own quality of rest otherwise. */
190
204
  #quality() {
191
205
  const own = this.getAttribute("quality");
192
206
  if (own === "full" || own === "medium" || own === "fast")
193
207
  return own;
194
- return this.#moving ? "fast" : this.#restQuality;
208
+ return this.#movingNow() ? "fast" : this.#restQuality;
195
209
  }
196
210
  connectedCallback() {
197
211
  this.#root = this.shadowRoot ?? this.attachShadow({ mode: "open" });
@@ -501,7 +515,8 @@ export class WakuseiSurface extends HTMLElement {
501
515
  // `auto`: a draw at rest is timed now and then, and a machine that takes too long at rest steps down (a card does a draw at full quality in a few milliseconds; a phone may not)
502
516
  const auto = this.getAttribute("quality") === null || this.getAttribute("quality") === "auto";
503
517
  const was = scene.drawMs;
504
- if (auto && !this.#moving && was !== undefined && this.#measured > 0) {
518
+ const moving = this.#movingNow();
519
+ if (auto && !moving && was !== undefined && this.#measured > 0) {
505
520
  if (was > 120 && this.#restQuality === "full")
506
521
  this.#restQuality = "medium";
507
522
  else if (was > 250 && this.#restQuality === "medium")
@@ -519,19 +534,46 @@ export class WakuseiSurface extends HTMLElement {
519
534
  }
520
535
  }
521
536
  const forced = scaleAttr === null || scaleAttr === "auto" ? undefined : Number(scaleAttr);
522
- const timeMoving = auto && this.#moving && this.#movingTimes.length < 4 && forced === undefined;
537
+ const timeMoving = auto && moving && this.#movingTimes.length < 4 && forced === undefined;
523
538
  if (timeMoving)
524
539
  this.#movingPending = true;
525
- this.#drawScale = forced !== undefined && Number.isFinite(forced) ? Math.min(1, Math.max(0.25, forced)) : this.#moving ? this.#moveScale : 1;
526
- const measure = (auto && !this.#moving && this.#measured < 4) || timeMoving;
527
- if (measure && !this.#moving)
540
+ this.#drawScale = forced !== undefined && Number.isFinite(forced) ? Math.min(1, Math.max(0.25, forced)) : moving ? this.#moveScale : 1;
541
+ const measure = (auto && !moving && this.#measured < 4) || timeMoving;
542
+ if (measure && !moving)
528
543
  this.#measured += 1;
529
544
  if (this.#drawScale < 1)
530
545
  this.#scaled += 1;
531
- scene.apply({ eye: { east: this.#at.east, north: this.#at.north, up: this.#eyeUp() }, look: this.#look, sky: this.#sky, shadows: this.getAttribute("shadows") !== "off", detail: !this.#noDetail(), exposure: num(this.getAttribute("exposure"), this.#site()?.body === "mars" ? 1.5 : 1.6), quality: this.#quality(), scale: this.#drawScale, objects: this.#objects.length > 0, ...(this.#vehicle === undefined ? {} : { vehicle: this.#vehicle, ...(this.#model === undefined ? {} : { model: this.#model }), trail: this.#trail, dust: this.#dust.position }), ...(this.#landing === undefined ? {} : { lander: this.#landerState(), dust: this.#dust.position }), measure: measure || this.getAttribute("measure") !== null });
546
+ // the camera: where the view puts it, or on the way to there from where the watched descent had it (a move, not a cut)
547
+ let pose = { east: this.#at.east, north: this.#at.north, up: this.#eyeUp(), look: this.#look };
548
+ if (this.#glide !== undefined) {
549
+ const k = (performance.now() - this.#glide.at) / this.#glide.ms;
550
+ if (k >= 1)
551
+ this.#glide = undefined;
552
+ else
553
+ pose = blendPose(this.#glide.from, pose, easeInOut(k), (east, north) => this.#groundAt(east, north));
554
+ }
555
+ this.#lastPose = { pose, fromWatch: this.#landing !== undefined || this.#glide !== undefined };
556
+ scene.apply({ eye: { east: pose.east, north: pose.north, up: pose.up }, look: pose.look, sky: this.#sky, shadows: this.getAttribute("shadows") !== "off", detail: !this.#noDetail(), exposure: num(this.getAttribute("exposure"), this.#site()?.body === "mars" ? 1.5 : 1.6), quality: this.#quality(), scale: this.#drawScale, objects: this.#objects.length > 0, ...(this.#vehicle === undefined ? {} : { vehicle: this.#vehicle, ...(this.#model === undefined ? {} : { model: this.#model }), trail: this.#trail, dust: this.#dust.position }), ...(this.#landing === undefined ? {} : { lander: this.#landerState(), dust: this.#dust.position }), measure: measure || this.getAttribute("measure") !== null });
532
557
  this.#view.invalidate();
533
558
  this.#draws += 1;
534
559
  this.#placeLabels();
560
+ // a move goes on a frame after a frame, at the quality of motion, until it arrives
561
+ if (this.#glide !== undefined)
562
+ this.#changed();
563
+ }
564
+ /**
565
+ * Start a smooth move of the camera from where the last draw had it, when that was the watched descent's (or a move from it that has not arrived): to the standing view when the watch ends, to the rover when it starts to be driven, and to the other camera when the watch's camera (or where the ground camera stands) changes.
566
+ * The `glide` attribute is `off` for a cut, or the time in milliseconds (1100 by default); a reader who prefers reduced motion gets the cut.
567
+ */
568
+ #beginGlide() {
569
+ const last = this.#lastPose;
570
+ const setting = this.getAttribute("glide");
571
+ if (last === undefined || !last.fromWatch || setting === "off")
572
+ return;
573
+ if (typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches)
574
+ return;
575
+ const asked = Number(setting);
576
+ this.#glide = { from: last.pose, at: performance.now(), ms: setting !== null && Number.isFinite(asked) && asked > 0 ? asked : GLIDE_MS };
535
577
  }
536
578
  // --- driving the rover (`drive="on"`) ---------------------------------------------------------------------------------------------------------------
537
579
  /** Which view of the rover: `chase` (from behind and above, the default) or `seat` (the commander's). The key C turns from one to the other. */
@@ -594,6 +636,7 @@ export class WakuseiSurface extends HTMLElement {
594
636
  this.choose(undefined);
595
637
  this.#syncModel();
596
638
  this.#syncDriveCamera();
639
+ this.#beginGlide();
597
640
  this.#changed();
598
641
  }
599
642
  /** The vehicle's measures: a loaded model's, or the lunar rover's. */
@@ -868,6 +911,7 @@ export class WakuseiSurface extends HTMLElement {
868
911
  this.#readAttributes();
869
912
  const td = this.#touchdown();
870
913
  this.#at = { east: td.east, north: td.north };
914
+ this.#beginGlide();
871
915
  this.#changed();
872
916
  return;
873
917
  }
@@ -880,9 +924,13 @@ export class WakuseiSurface extends HTMLElement {
880
924
  if (this.#landing.camera !== camera)
881
925
  this.#look = clampLook({ ...this.#look, fov: camera === "ground" ? 27 : 74 });
882
926
  const changed = this.#landing.camera !== camera;
927
+ // a change of camera, or of where the ground camera stands, is a move and not a cut (MODULES-1561)
928
+ const moved = changed || this.#landing.from.distance !== from.distance || this.#landing.from.bearing !== from.bearing;
883
929
  this.#landing.camera = camera;
884
930
  this.#landing.from = from;
885
931
  this.#camOffset = { azimuth: 0, pitch: 0 };
932
+ if (moved)
933
+ this.#beginGlide();
886
934
  this.#landingFrame(0, true);
887
935
  if (changed)
888
936
  this.#landingAnnounce();
@@ -940,7 +988,7 @@ export class WakuseiSurface extends HTMLElement {
940
988
  if (l.camera === "lander") {
941
989
  this.#at = { east: lx, north: ly };
942
990
  this.#landingEyeUp = lz + pose.altitude + 4;
943
- this.#look = clampLook({ azimuth: (((pose.heading + this.#camOffset.azimuth) % 360) + 360) % 360, pitch: pose.pitch + this.#camOffset.pitch, fov: this.#look.fov });
991
+ this.#look = clampLook({ ...watchedLook({ azimuth: pose.heading, pitch: pose.pitch }, this.#camOffset), fov: this.#look.fov });
944
992
  }
945
993
  else {
946
994
  const b = (l.from.bearing * Math.PI) / 180;
@@ -950,7 +998,7 @@ export class WakuseiSurface extends HTMLElement {
950
998
  const horizontal = Math.hypot(lx - ox, ly - oy) || 1;
951
999
  const azimuth = ((Math.atan2(lx - ox, ly - oy) * 180) / Math.PI + 360) % 360;
952
1000
  const pitch = (Math.atan2(lz + pose.altitude + 3.4 - this.#landingEyeUp, horizontal) * 180) / Math.PI;
953
- this.#look = clampLook({ azimuth: azimuth + this.#camOffset.azimuth, pitch: pitch + this.#camOffset.pitch, fov: this.#look.fov });
1001
+ this.#look = clampLook({ ...watchedLook({ azimuth, pitch }, this.#camOffset), fov: this.#look.fov });
954
1002
  }
955
1003
  // the marker: while the stage is smaller than about 6 pixels in the ground camera a ring and its height mark where it is, fading out as it grows
956
1004
  const ring = this.#root.getElementById("marker");
@@ -1180,6 +1228,7 @@ export class WakuseiSurface extends HTMLElement {
1180
1228
  };
1181
1229
  // --- hands ---------------------------------------------------------------------------------------------------------------------------------------
1182
1230
  #onPointerDown = (event) => {
1231
+ this.#glide = undefined;
1183
1232
  this.#pointers.set(event.pointerId, { x: event.clientX, y: event.clientY });
1184
1233
  this.setPointerCapture(event.pointerId);
1185
1234
  this.setAttribute("data-dragging", "");
@@ -1199,10 +1248,15 @@ export class WakuseiSurface extends HTMLElement {
1199
1248
  }
1200
1249
  const box = this.getBoundingClientRect();
1201
1250
  const perPixel = this.#look.fov / Math.max(1, box.height);
1202
- if (this.#vehicle !== undefined) {
1203
- this.#camOffset = { azimuth: this.#camOffset.azimuth - (event.clientX - was.x) * perPixel, pitch: Math.max(-60, Math.min(60, this.#camOffset.pitch + (event.clientY - was.y) * perPixel)) };
1204
- this.#syncDriveCamera();
1205
- this.#changed();
1251
+ if (this.#vehicle !== undefined || this.#landing !== undefined) {
1252
+ // the rover's camera and the watched descent's point themselves at every frame: a drag adds to a turn kept beside them (MODULES-1546: it was written into the look, which the next frame of the descent put back)
1253
+ this.#camOffset = turnedBy(this.#camOffset, event.clientX - was.x, event.clientY - was.y, perPixel);
1254
+ if (this.#vehicle !== undefined) {
1255
+ this.#syncDriveCamera();
1256
+ this.#changed();
1257
+ }
1258
+ else
1259
+ this.#landingFrame(0, false);
1206
1260
  return;
1207
1261
  }
1208
1262
  this.#look = clampLook({ ...this.#look, azimuth: this.#look.azimuth - (event.clientX - was.x) * perPixel, pitch: this.#look.pitch + (event.clientY - was.y) * perPixel });
@@ -1229,6 +1283,7 @@ export class WakuseiSurface extends HTMLElement {
1229
1283
  this.#zoom(Math.exp(event.deltaY * 0.0015));
1230
1284
  };
1231
1285
  #onKeyDown = (event) => {
1286
+ this.#glide = undefined;
1232
1287
  const key = event.key.length === 1 ? event.key.toLowerCase() : event.key;
1233
1288
  if (key === "c" && this.#vehicle !== undefined) {
1234
1289
  this.driveCamera = this.#driveCamera === "chase" ? "seat" : "chase";
@@ -0,0 +1,27 @@
1
+ import type { Look } from "./view.ts";
2
+ /** How long the move takes by default, in milliseconds. */
3
+ export declare const GLIDE_MS = 1100;
4
+ /** Where the camera is and which way it looks: metres east and north of the site, the eye's height in metres (absolute, as the standing view's eye is), and the look. */
5
+ export interface Pose {
6
+ east: number;
7
+ north: number;
8
+ up: number;
9
+ look: Look;
10
+ }
11
+ /**
12
+ * The slow-fast-slow curve of the move: 0 at 0, 1 at 1, and flat at both ends so that it starts and stops without a jolt.
13
+ *
14
+ * @param t - How far through the move, 0 to 1 (outside is held).
15
+ * @returns The share of the way gone, 0 to 1.
16
+ */
17
+ export declare function easeInOut(t: number): number;
18
+ /**
19
+ * The pose a share `k` of the way from one pose to another: the eye on the straight line between them with its height above the ground blended (so it never goes under a hill between the two places), the azimuth the short way round, and the pitch and the field of view blended. At 0 it is `from` and at 1 it is `to`, exactly.
20
+ *
21
+ * @param from - Where the move starts.
22
+ * @param to - Where it ends.
23
+ * @param k - The share of the way, 0 to 1 (already eased).
24
+ * @param groundAt - The height of the ground at a place, in the same metres as `up`.
25
+ * @returns The blended pose.
26
+ */
27
+ export declare function blendPose(from: Pose, to: Pose, k: number, groundAt: (east: number, north: number) => number): Pose;
@@ -0,0 +1,43 @@
1
+ /** How long the move takes by default, in milliseconds. */
2
+ export const GLIDE_MS = 1100;
3
+ /**
4
+ * The slow-fast-slow curve of the move: 0 at 0, 1 at 1, and flat at both ends so that it starts and stops without a jolt.
5
+ *
6
+ * @param t - How far through the move, 0 to 1 (outside is held).
7
+ * @returns The share of the way gone, 0 to 1.
8
+ */
9
+ export function easeInOut(t) {
10
+ const x = Math.max(0, Math.min(1, t));
11
+ return x * x * x * (x * (x * 6 - 15) + 10);
12
+ }
13
+ const turnBetween = (a, b) => ((((b - a) % 360) + 540) % 360) - 180;
14
+ /**
15
+ * The pose a share `k` of the way from one pose to another: the eye on the straight line between them with its height above the ground blended (so it never goes under a hill between the two places), the azimuth the short way round, and the pitch and the field of view blended. At 0 it is `from` and at 1 it is `to`, exactly.
16
+ *
17
+ * @param from - Where the move starts.
18
+ * @param to - Where it ends.
19
+ * @param k - The share of the way, 0 to 1 (already eased).
20
+ * @param groundAt - The height of the ground at a place, in the same metres as `up`.
21
+ * @returns The blended pose.
22
+ */
23
+ export function blendPose(from, to, k, groundAt) {
24
+ if (!(k > 0))
25
+ return { ...from, look: { ...from.look } };
26
+ if (!(k < 1))
27
+ return { ...to, look: { ...to.look } };
28
+ const east = from.east + (to.east - from.east) * k;
29
+ const north = from.north + (to.north - from.north) * k;
30
+ const aboveFrom = from.up - groundAt(from.east, from.north);
31
+ const aboveTo = to.up - groundAt(to.east, to.north);
32
+ const up = groundAt(east, north) + aboveFrom + (aboveTo - aboveFrom) * k;
33
+ return {
34
+ east,
35
+ north,
36
+ up,
37
+ look: {
38
+ azimuth: (((from.look.azimuth + turnBetween(from.look.azimuth, to.look.azimuth) * k) % 360) + 360) % 360,
39
+ pitch: from.look.pitch + (to.look.pitch - from.look.pitch) * k,
40
+ fov: from.look.fov + (to.look.fov - from.look.fov) * k,
41
+ },
42
+ };
43
+ }
@@ -5,12 +5,12 @@ export declare const DETAIL = "\nuniform float uPixel; // the angle one pixel ta
5
5
  /** The ground's vertices: a ring index and an angle across the view, laid out as the viewer's own polar grid, then raised to the measured heights. */
6
6
  export declare const GROUND_VERTEX = "\nprecision highp float;\nprecision highp sampler2D;\n// position (declared by three.js) holds x: 0 to 1 out along the rays (ring spacing grows with the distance), y: -1 to 1 across the view\nuniform mat4 uVP;\nuniform vec2 uEyeEN; // the eyes' place in the site's plane: east, north\nuniform float uYaw; // radians, clockwise from north\nuniform float uSpan; // half the angle drawn across the view, radians\nuniform float uRMin;\nuniform float uRMax;\n\nuniform sampler2D uH0;\nuniform sampler2D uH1;\nuniform sampler2D uH2;\nuniform sampler2D uH3;\nuniform sampler2D uA0; // the ground picture on the first three levels, 0 to 1 with the middle at 0.5\nuniform sampler2D uA1;\nuniform sampler2D uA2;\nuniform float uPicture; // 1 where the picture is there\nuniform vec4 uL0; // half width, metres a sample, samples across, the distance out to which this level is used\nuniform vec4 uL1;\nuniform vec4 uL2;\nuniform vec4 uL3;\nuniform float uHmin;\nuniform float uHrange;\nuniform float uGround;\nuniform float uRadius;\n\nuniform vec2 uFarHeight; // the range the coarse level is encoded over: its minimum and its span\nfloat dec(vec4 t, vec2 hr) { return hr.x + (t.r * 255.0 * 256.0 + t.g * 255.0) / 65535.0 * hr.y; }\n\nfloat lin(sampler2D s, vec2 p, vec4 l, vec2 hr) {\n vec2 f = vec2((p.x + l.x) / l.y - 0.5, (l.x - p.y) / l.y - 0.5);\n vec2 i = floor(f);\n vec2 t = f - i;\n float st = 1.0 / l.z;\n vec2 uv = (i + 0.5) * st;\n float a = dec(texture2D(s, uv), hr);\n float b = dec(texture2D(s, uv + vec2(st, 0.0)), hr);\n float c = dec(texture2D(s, uv + vec2(0.0, st)), hr);\n float d = dec(texture2D(s, uv + vec2(st, st)), hr);\n return mix(mix(a, b, t.x), mix(c, d, t.x), t.y);\n}\n\nfloat nearest(sampler2D s, vec2 p, vec4 l, vec2 hr) {\n vec2 uv = vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z));\n return dec(texture2D(s, uv), hr);\n}\n\nbool holds(vec2 p, vec4 l, float dist) { return dist < l.w && abs(p.x) < l.x - 2.0 * l.y && abs(p.y) < l.x - 2.0 * l.y; }\n\n// the ground's height over the site's, the sphere's fall taken off; `fine` reads four samples, otherwise one\nfloat terrainY(vec2 p, float dist, bool fine) {\n float h;\n if (holds(p, uL0, dist)) h = fine ? lin(uH0, p, uL0, vec2(uHmin, uHrange)) : nearest(uH0, p, uL0, vec2(uHmin, uHrange));\n else if (holds(p, uL1, dist)) h = fine ? lin(uH1, p, uL1, vec2(uHmin, uHrange)) : nearest(uH1, p, uL1, vec2(uHmin, uHrange));\n else if (holds(p, uL2, dist)) h = fine ? lin(uH2, p, uL2, vec2(uHmin, uHrange)) : nearest(uH2, p, uL2, vec2(uHmin, uHrange));\n else h = fine ? lin(uH3, p, uL3, uFarHeight) : nearest(uH3, p, uL3, uFarHeight);\n return h - uGround - dot(p, p) / (2.0 * uRadius);\n}\n\n// the ground's own brightness at a point, from the picture of the level that serves it, 1 where it is the middle\nfloat albedoAt(vec2 p, float dist) {\n if (uPicture < 0.5) return 1.0;\n vec4 l;\n if (holds(p, uL0, dist)) { l = uL0; return 2.0 * texture2D(uA0, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n if (holds(p, uL1, dist)) { l = uL1; return 2.0 * texture2D(uA1, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n if (holds(p, uL2, dist)) { l = uL2; return 2.0 * texture2D(uA2, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n return 1.0;\n}\n\n// the measured ground's shadows, baked (scripts/make-moon-terrain.py): for a point, the elevation angle in degrees of the horizon toward the Sun, read from the finest of the three horizon maps that holds the point\nuniform sampler2D uZ0;\nuniform sampler2D uZ1;\nuniform sampler2D uZ2;\nuniform float uHzOn; // 1 where the maps are there\nuniform vec3 uHzSun; // the two directions (of 18) the Sun's azimuth lies between, and the share of the second\nuniform vec2 uHzRange; // the degrees the codes 0 and 255 stand for\n\nfloat hzSector(sampler2D s, vec2 cell, float k) {\n float slab = floor(k / 3.0);\n float ch = k - slab * 3.0;\n vec3 v = texture2D(s, vec2((cell.x + slab) / 6.0, cell.y)).rgb;\n return ch < 0.5 ? v.r : (ch < 1.5 ? v.g : v.b);\n}\n\nfloat hzFrom(sampler2D s, vec2 p, float reach) {\n vec2 cell = clamp(vec2((p.x + reach) / (2.0 * reach), (reach - p.y) / (2.0 * reach)), vec2(0.5 / 512.0), vec2(1.0 - 0.5 / 512.0));\n float code = mix(hzSector(s, cell, uHzSun.x), hzSector(s, cell, uHzSun.y), uHzSun.z);\n return uHzRange.x + code * (uHzRange.y - uHzRange.x);\n}\n\nfloat horizonAt(vec2 p) {\n if (abs(p.x) < uL0.x && abs(p.y) < uL0.x) return hzFrom(uZ0, p, uL0.x);\n if (abs(p.x) < uL1.x && abs(p.y) < uL1.x) return hzFrom(uZ1, p, uL1.x);\n if (abs(p.x) < uL2.x && abs(p.y) < uL2.x) return hzFrom(uZ2, p, uL2.x);\n return -90.0;\n}\n\n// the spacing of the level that serves a point, for the step of a slope\nfloat spacing(vec2 p, float dist) {\n if (holds(p, uL0, dist)) return uL0.y;\n if (holds(p, uL1, dist)) return uL1.y;\n if (holds(p, uL2, dist)) return uL2.y;\n return uL3.y;\n}\n\n\nuniform float uPixel; // the angle one pixel takes, radians\nuniform float uDetail; // 1 for the made detail, 0 for none\n\nuvec2 pcg2d(uvec2 v) {\n v = v * 1664525u + 1013904223u;\n v.x += v.y * 1664525u;\n v.y += v.x * 1664525u;\n v = v ^ (v >> 16u);\n v.x += v.y * 1664525u;\n v.y += v.x * 1664525u;\n v = v ^ (v >> 16u);\n return v;\n}\nfloat u24(uint h) { return float(h >> 8u) * (1.0 / 16777216.0); }\n\nuniform vec4 uKeep[6]; // the objects the made ground keeps away from: east, north, the distance inside which nothing is made, the distance outside which it all is\nuniform float uKeepCount;\nfloat keepMask(vec2 p) {\n float keep = 1.0;\n for (int i = 0; i < 6; i += 1) {\n if (float(i) >= uKeepCount) break;\n vec4 k = uKeep[i];\n float t = clamp((distance(p, k.xy) - k.z) / (k.w - k.z), 0.0, 1.0);\n keep = min(keep, t * t * (3.0 - 2.0 * t));\n }\n return keep;\n}\n\n// the made ground at a point: x the height in metres, yz the slope east and north, from every crater of every octave whose nominal diameter is over `fromD`\nvec3 madeGround(vec2 p, float fromD) {\n vec3 sum = vec3(0.0);\n for (int octave = 5; octave >= 0; octave -= 1) {\n float nominal = 0.5 * exp2(float(octave));\n float fade = clamp(nominal / fromD - 1.0, 0.0, 1.0);\n if (fade <= 0.0) break;\n float cell = 3.0 * nominal;\n ivec2 base = ivec2(floor(p / cell));\n vec2 fr = p / cell - vec2(base);\n float occ = (octave >= 3 ? 0.5 : 1.0) * 0.36 * exp2(-0.5 * float(octave));\n for (int j = -1; j <= 1; j += 1) {\n for (int i = -1; i <= 1; i += 1) {\n // a crater is kept to the middle of its cell, so a neighbour's reaches this cell only within a fifth of the edge\n if ((i == -1 && fr.x > 0.2) || (i == 1 && fr.x < 0.8) || (j == -1 && fr.y > 0.2) || (j == 1 && fr.y < 0.8)) continue;\n ivec2 c = base + ivec2(i, j);\n uvec2 ab = pcg2d(uvec2(uint(c.x), uint(c.y + octave * 7919)));\n if (u24(ab.x) >= occ) continue;\n uvec2 cd = pcg2d(uvec2(uint(c.x + 104729), uint(c.y + octave * 7919 + 15485863)));\n float diameter = nominal * (1.0 + (octave == 5 ? 0.25 : 1.0) * u24(cd.y));\n float r4 = float(ab.x & 255u) / 255.0;\n float age = 1.0 - r4 * r4 * r4 * r4;\n float radius = 0.5 * diameter;\n float vary = 0.6 + 0.4 * (float(cd.x & 255u) / 255.0);\n float depth = diameter * (0.2 - 0.17 * age) * vary;\n float rim = 0.045 * diameter * pow(1.0 - age, 1.5);\n float rimWidth = 0.22 + 0.5 * age;\n vec2 centre = vec2(float(c.x) + 0.25 + 0.5 * u24(ab.y), float(c.y) + 0.25 + 0.5 * u24(cd.x)) * cell;\n vec2 d = p - centre;\n float r = length(d);\n float x = r / radius;\n float h = 0.0;\n float dh = 0.0;\n if (x < 1.0) { float bowl = 1.0 - x * x; float pw = 1.0 + age; h = -depth * pow(bowl, pw); dh = 2.0 * depth * pw * x * pow(bowl, age); }\n float e = (x - 1.0) / rimWidth;\n float ex = exp(-e * e);\n h += rim * ex;\n dh += -2.0 * rim * e * ex / rimWidth;\n if (x > 1.0) { float t = 1.0 / x; h += 0.25 * rim * t * t * t; dh += -0.75 * rim * t * t * t * t; }\n float k = r > 1e-6 ? dh / (radius * r) : 0.0;\n sum += fade * vec3(h, k * d.x, k * d.y);\n }\n }\n }\n return sum * keepMask(p);\n}\n\nfloat vnoise(vec2 p) {\n vec2 i = floor(p);\n vec2 f = p - i;\n vec2 w = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);\n uvec2 c = uvec2(ivec2(i));\n float a = u24(pcg2d(c).x);\n float b = u24(pcg2d(c + uvec2(1u, 0u)).x);\n float cc = u24(pcg2d(c + uvec2(0u, 1u)).x);\n float d = u24(pcg2d(c + uvec2(1u, 1u)).x);\n return mix(mix(a, b, w.x), mix(cc, d, w.x), w.y);\n}\n\n// a fine roughness of the dust: two scales, as a slope (east, north), faded out where a pixel covers more than a few of its grains\nvec2 roughness(vec2 p, float footprint) {\n vec2 g = vec2(0.0);\n for (int k = 0; k < 2; k += 1) {\n float s = k == 0 ? 0.07 : 0.3;\n float amp = k == 0 ? 0.3 : 0.28;\n float fade = smoothstep(footprint * 2.0, footprint * 7.0, s);\n if (fade <= 0.0) continue;\n float d = s * 0.25;\n vec2 q = (k == 0 ? vec2(p.x * 0.629 + p.y * 0.777, p.y * 0.629 - p.x * 0.777) : vec2(p.x * 0.857 - p.y * 0.515, p.x * 0.515 + p.y * 0.857)) / s;\n float dx = vnoise(q + vec2(0.25, 0.0)) - vnoise(q - vec2(0.25, 0.0));\n float dy = vnoise(q + vec2(0.0, 0.25)) - vnoise(q - vec2(0.0, 0.25));\n g += fade * amp * vec2(dx, dy) / (0.5 * s) * 0.012;\n }\n return g;\n}\n\nvarying vec3 vP;\nvoid main() {\n float r = uRMin * pow(uRMax / uRMin, position.x);\n float a = uYaw + position.y * uSpan;\n vec2 p = uEyeEN + r * vec2(sin(a), cos(a));\n float y = terrainY(p, r, true);\n // the made craters, those the mesh can hold here: bigger than a few of its steps\n if (uDetail > 0.5 && r < 3000.0) y += madeGround(p, max(2.5 * r * uPixel, 0.06 * r)).x;\n vP = vec3(p.x, y, p.y);\n gl_Position = uVP * vec4(p.x, y, -p.y, 1.0);\n}\n";
7
7
  /** What the ground, the rocks and their shadows all need to be lit: the Sun, the eyes, the heights and the made detail, the ground's height with the craters on it, and a point's light (a hard shadow by a march toward the Sun). */
8
- export declare const LIGHT = "\nuniform vec3 uSun;\nuniform vec3 uEye;\nuniform vec2 uEyeEN;\nuniform float uExposure;\nuniform float uAlbedo;\nuniform float uMaxY; // the highest ground over the site's, for the end of a shadow's march\nuniform float uEarthshine; // the light of the sunlit ground round the shade, a small share of a lit slope's (on Mars the sky's light, a good deal more)\nuniform vec3 uTint; // the ground's colour over its grey: white on the Moon\nuniform float uShadows; // 1 for the ground to shadow itself (the default), 0 for none (a try-out)\nuniform float uSunDegrees; // the Sun's elevation in degrees\nuniform vec3 uNear; // the near march: steps, the distance it reaches in metres, the distance out to which the made craters are in it (the quality of the draw)\n\nuniform sampler2D uH0;\nuniform sampler2D uH1;\nuniform sampler2D uH2;\nuniform sampler2D uH3;\nuniform sampler2D uA0; // the ground picture on the first three levels, 0 to 1 with the middle at 0.5\nuniform sampler2D uA1;\nuniform sampler2D uA2;\nuniform float uPicture; // 1 where the picture is there\nuniform vec4 uL0; // half width, metres a sample, samples across, the distance out to which this level is used\nuniform vec4 uL1;\nuniform vec4 uL2;\nuniform vec4 uL3;\nuniform float uHmin;\nuniform float uHrange;\nuniform float uGround;\nuniform float uRadius;\n\nuniform vec2 uFarHeight; // the range the coarse level is encoded over: its minimum and its span\nfloat dec(vec4 t, vec2 hr) { return hr.x + (t.r * 255.0 * 256.0 + t.g * 255.0) / 65535.0 * hr.y; }\n\nfloat lin(sampler2D s, vec2 p, vec4 l, vec2 hr) {\n vec2 f = vec2((p.x + l.x) / l.y - 0.5, (l.x - p.y) / l.y - 0.5);\n vec2 i = floor(f);\n vec2 t = f - i;\n float st = 1.0 / l.z;\n vec2 uv = (i + 0.5) * st;\n float a = dec(texture2D(s, uv), hr);\n float b = dec(texture2D(s, uv + vec2(st, 0.0)), hr);\n float c = dec(texture2D(s, uv + vec2(0.0, st)), hr);\n float d = dec(texture2D(s, uv + vec2(st, st)), hr);\n return mix(mix(a, b, t.x), mix(c, d, t.x), t.y);\n}\n\nfloat nearest(sampler2D s, vec2 p, vec4 l, vec2 hr) {\n vec2 uv = vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z));\n return dec(texture2D(s, uv), hr);\n}\n\nbool holds(vec2 p, vec4 l, float dist) { return dist < l.w && abs(p.x) < l.x - 2.0 * l.y && abs(p.y) < l.x - 2.0 * l.y; }\n\n// the ground's height over the site's, the sphere's fall taken off; `fine` reads four samples, otherwise one\nfloat terrainY(vec2 p, float dist, bool fine) {\n float h;\n if (holds(p, uL0, dist)) h = fine ? lin(uH0, p, uL0, vec2(uHmin, uHrange)) : nearest(uH0, p, uL0, vec2(uHmin, uHrange));\n else if (holds(p, uL1, dist)) h = fine ? lin(uH1, p, uL1, vec2(uHmin, uHrange)) : nearest(uH1, p, uL1, vec2(uHmin, uHrange));\n else if (holds(p, uL2, dist)) h = fine ? lin(uH2, p, uL2, vec2(uHmin, uHrange)) : nearest(uH2, p, uL2, vec2(uHmin, uHrange));\n else h = fine ? lin(uH3, p, uL3, uFarHeight) : nearest(uH3, p, uL3, uFarHeight);\n return h - uGround - dot(p, p) / (2.0 * uRadius);\n}\n\n// the ground's own brightness at a point, from the picture of the level that serves it, 1 where it is the middle\nfloat albedoAt(vec2 p, float dist) {\n if (uPicture < 0.5) return 1.0;\n vec4 l;\n if (holds(p, uL0, dist)) { l = uL0; return 2.0 * texture2D(uA0, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n if (holds(p, uL1, dist)) { l = uL1; return 2.0 * texture2D(uA1, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n if (holds(p, uL2, dist)) { l = uL2; return 2.0 * texture2D(uA2, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n return 1.0;\n}\n\n// the measured ground's shadows, baked (scripts/make-moon-terrain.py): for a point, the elevation angle in degrees of the horizon toward the Sun, read from the finest of the three horizon maps that holds the point\nuniform sampler2D uZ0;\nuniform sampler2D uZ1;\nuniform sampler2D uZ2;\nuniform float uHzOn; // 1 where the maps are there\nuniform vec3 uHzSun; // the two directions (of 18) the Sun's azimuth lies between, and the share of the second\nuniform vec2 uHzRange; // the degrees the codes 0 and 255 stand for\n\nfloat hzSector(sampler2D s, vec2 cell, float k) {\n float slab = floor(k / 3.0);\n float ch = k - slab * 3.0;\n vec3 v = texture2D(s, vec2((cell.x + slab) / 6.0, cell.y)).rgb;\n return ch < 0.5 ? v.r : (ch < 1.5 ? v.g : v.b);\n}\n\nfloat hzFrom(sampler2D s, vec2 p, float reach) {\n vec2 cell = clamp(vec2((p.x + reach) / (2.0 * reach), (reach - p.y) / (2.0 * reach)), vec2(0.5 / 512.0), vec2(1.0 - 0.5 / 512.0));\n float code = mix(hzSector(s, cell, uHzSun.x), hzSector(s, cell, uHzSun.y), uHzSun.z);\n return uHzRange.x + code * (uHzRange.y - uHzRange.x);\n}\n\nfloat horizonAt(vec2 p) {\n if (abs(p.x) < uL0.x && abs(p.y) < uL0.x) return hzFrom(uZ0, p, uL0.x);\n if (abs(p.x) < uL1.x && abs(p.y) < uL1.x) return hzFrom(uZ1, p, uL1.x);\n if (abs(p.x) < uL2.x && abs(p.y) < uL2.x) return hzFrom(uZ2, p, uL2.x);\n return -90.0;\n}\n\n// the spacing of the level that serves a point, for the step of a slope\nfloat spacing(vec2 p, float dist) {\n if (holds(p, uL0, dist)) return uL0.y;\n if (holds(p, uL1, dist)) return uL1.y;\n if (holds(p, uL2, dist)) return uL2.y;\n return uL3.y;\n}\n\n\nuniform float uPixel; // the angle one pixel takes, radians\nuniform float uDetail; // 1 for the made detail, 0 for none\n\nuvec2 pcg2d(uvec2 v) {\n v = v * 1664525u + 1013904223u;\n v.x += v.y * 1664525u;\n v.y += v.x * 1664525u;\n v = v ^ (v >> 16u);\n v.x += v.y * 1664525u;\n v.y += v.x * 1664525u;\n v = v ^ (v >> 16u);\n return v;\n}\nfloat u24(uint h) { return float(h >> 8u) * (1.0 / 16777216.0); }\n\nuniform vec4 uKeep[6]; // the objects the made ground keeps away from: east, north, the distance inside which nothing is made, the distance outside which it all is\nuniform float uKeepCount;\nfloat keepMask(vec2 p) {\n float keep = 1.0;\n for (int i = 0; i < 6; i += 1) {\n if (float(i) >= uKeepCount) break;\n vec4 k = uKeep[i];\n float t = clamp((distance(p, k.xy) - k.z) / (k.w - k.z), 0.0, 1.0);\n keep = min(keep, t * t * (3.0 - 2.0 * t));\n }\n return keep;\n}\n\n// the made ground at a point: x the height in metres, yz the slope east and north, from every crater of every octave whose nominal diameter is over `fromD`\nvec3 madeGround(vec2 p, float fromD) {\n vec3 sum = vec3(0.0);\n for (int octave = 5; octave >= 0; octave -= 1) {\n float nominal = 0.5 * exp2(float(octave));\n float fade = clamp(nominal / fromD - 1.0, 0.0, 1.0);\n if (fade <= 0.0) break;\n float cell = 3.0 * nominal;\n ivec2 base = ivec2(floor(p / cell));\n vec2 fr = p / cell - vec2(base);\n float occ = (octave >= 3 ? 0.5 : 1.0) * 0.36 * exp2(-0.5 * float(octave));\n for (int j = -1; j <= 1; j += 1) {\n for (int i = -1; i <= 1; i += 1) {\n // a crater is kept to the middle of its cell, so a neighbour's reaches this cell only within a fifth of the edge\n if ((i == -1 && fr.x > 0.2) || (i == 1 && fr.x < 0.8) || (j == -1 && fr.y > 0.2) || (j == 1 && fr.y < 0.8)) continue;\n ivec2 c = base + ivec2(i, j);\n uvec2 ab = pcg2d(uvec2(uint(c.x), uint(c.y + octave * 7919)));\n if (u24(ab.x) >= occ) continue;\n uvec2 cd = pcg2d(uvec2(uint(c.x + 104729), uint(c.y + octave * 7919 + 15485863)));\n float diameter = nominal * (1.0 + (octave == 5 ? 0.25 : 1.0) * u24(cd.y));\n float r4 = float(ab.x & 255u) / 255.0;\n float age = 1.0 - r4 * r4 * r4 * r4;\n float radius = 0.5 * diameter;\n float vary = 0.6 + 0.4 * (float(cd.x & 255u) / 255.0);\n float depth = diameter * (0.2 - 0.17 * age) * vary;\n float rim = 0.045 * diameter * pow(1.0 - age, 1.5);\n float rimWidth = 0.22 + 0.5 * age;\n vec2 centre = vec2(float(c.x) + 0.25 + 0.5 * u24(ab.y), float(c.y) + 0.25 + 0.5 * u24(cd.x)) * cell;\n vec2 d = p - centre;\n float r = length(d);\n float x = r / radius;\n float h = 0.0;\n float dh = 0.0;\n if (x < 1.0) { float bowl = 1.0 - x * x; float pw = 1.0 + age; h = -depth * pow(bowl, pw); dh = 2.0 * depth * pw * x * pow(bowl, age); }\n float e = (x - 1.0) / rimWidth;\n float ex = exp(-e * e);\n h += rim * ex;\n dh += -2.0 * rim * e * ex / rimWidth;\n if (x > 1.0) { float t = 1.0 / x; h += 0.25 * rim * t * t * t; dh += -0.75 * rim * t * t * t * t; }\n float k = r > 1e-6 ? dh / (radius * r) : 0.0;\n sum += fade * vec3(h, k * d.x, k * d.y);\n }\n }\n }\n return sum * keepMask(p);\n}\n\nfloat vnoise(vec2 p) {\n vec2 i = floor(p);\n vec2 f = p - i;\n vec2 w = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);\n uvec2 c = uvec2(ivec2(i));\n float a = u24(pcg2d(c).x);\n float b = u24(pcg2d(c + uvec2(1u, 0u)).x);\n float cc = u24(pcg2d(c + uvec2(0u, 1u)).x);\n float d = u24(pcg2d(c + uvec2(1u, 1u)).x);\n return mix(mix(a, b, w.x), mix(cc, d, w.x), w.y);\n}\n\n// a fine roughness of the dust: two scales, as a slope (east, north), faded out where a pixel covers more than a few of its grains\nvec2 roughness(vec2 p, float footprint) {\n vec2 g = vec2(0.0);\n for (int k = 0; k < 2; k += 1) {\n float s = k == 0 ? 0.07 : 0.3;\n float amp = k == 0 ? 0.3 : 0.28;\n float fade = smoothstep(footprint * 2.0, footprint * 7.0, s);\n if (fade <= 0.0) continue;\n float d = s * 0.25;\n vec2 q = (k == 0 ? vec2(p.x * 0.629 + p.y * 0.777, p.y * 0.629 - p.x * 0.777) : vec2(p.x * 0.857 - p.y * 0.515, p.x * 0.515 + p.y * 0.857)) / s;\n float dx = vnoise(q + vec2(0.25, 0.0)) - vnoise(q - vec2(0.25, 0.0));\n float dy = vnoise(q + vec2(0.0, 0.25)) - vnoise(q - vec2(0.0, 0.25));\n g += fade * amp * vec2(dx, dy) / (0.5 * s) * 0.012;\n }\n return g;\n}\n\n\n// the ground's height at a point: the measured heights and, near the eyes, the made craters (kept to the ones a pixel here can show)\nfloat groundY(vec2 p, float dist, bool fine, float fromD) {\n float y = terrainY(p, dist, fine);\n if (uDetail > 0.5 && fromD < 24.0) y += madeGround(p, fromD).x;\n return y;\n}\n\n// 1 where the Sun reaches a point, 0 where the ground is in its way. The measured ground's shadow is read from the baked horizon; the march toward the Sun over the heights (and the made craters) is the near\n// field's only, a few tens of metres with a fixed number of steps, as sharp as the Sun's edge. Where there is no baked horizon the march goes all the way, as it did before the maps.\nfloat lit(vec3 P, float dist0) {\n vec2 dir = normalize(uSun.xz);\n float slope = uSun.y / max(length(uSun.xz), 1e-4);\n if (uHzOn > 0.5 && horizonAt(P.xz) - 0.3 > uSunDegrees) return 0.0;\n // the ground at the point from the heights themselves, not the mesh's slope between its corners, which can be a long way off on a far mountain\n P.y = groundY(P.xz, dist0, true, 2.5 * dist0 * uPixel);\n float t = 0.5 * spacing(P.xz, dist0) + 0.25;\n if (uDetail > 0.5) t = min(t, 0.2 + 0.02 * dist0);\n // a pixel's own start along the ray: the edge of a rim's shadow is a line of steps, and a line of steps is jagged; with a start of its own each pixel it becomes a fine grain instead\n float jitter = fract(sin(dot(P.xz, vec2(12.9898, 78.233))) * 43758.5453);\n float range = uHzOn > 0.5 ? uNear.y : 80000.0;\n for (int i = 0; i < 260; i += 1) {\n if (float(i) >= uNear.x) break;\n vec2 q = P.xz + dir * t;\n float y = P.y + slope * t;\n float dist = max(t, distance(q, uEyeEN));\n float res = spacing(q, dist);\n float h = groundY(q, dist, t < 600.0, t < uNear.z ? max(0.2 * t, 2.5 * dist * uPixel) : 99.0);\n float bias = (t < 40.0 ? 0.01 : 0.3 * res) + 0.002 * t;\n if (h > y + bias) return 0.0;\n if (y > uMaxY || t > range) break;\n float step = t < 30.0 ? t * 0.045 + 0.04 : t * 0.06 + 0.5;\n t += step * (0.65 + 0.7 * jitter);\n }\n return 1.0;\n}\n";
8
+ export declare const LIGHT = "\nuniform vec3 uSun;\nuniform vec3 uEye;\nuniform vec2 uEyeEN;\nuniform float uExposure;\nuniform float uAlbedo;\nuniform float uMaxY; // the highest ground over the site's, for the end of a shadow's march\nuniform float uEarthshine; // the light of the sunlit ground round the shade, a small share of a lit slope's (on Mars the sky's light, a good deal more)\nuniform vec3 uTint; // the ground's colour over its grey: white on the Moon\nuniform float uShadows; // 1 for the ground to shadow itself (the default), 0 for none (a try-out)\nuniform float uSunDegrees; // the Sun's elevation in degrees\nuniform vec3 uNear; // the near march: steps, the distance it reaches in metres, the distance out to which the made craters are in it (the quality of the draw)\n\nuniform sampler2D uH0;\nuniform sampler2D uH1;\nuniform sampler2D uH2;\nuniform sampler2D uH3;\nuniform sampler2D uA0; // the ground picture on the first three levels, 0 to 1 with the middle at 0.5\nuniform sampler2D uA1;\nuniform sampler2D uA2;\nuniform float uPicture; // 1 where the picture is there\nuniform vec4 uL0; // half width, metres a sample, samples across, the distance out to which this level is used\nuniform vec4 uL1;\nuniform vec4 uL2;\nuniform vec4 uL3;\nuniform float uHmin;\nuniform float uHrange;\nuniform float uGround;\nuniform float uRadius;\n\nuniform vec2 uFarHeight; // the range the coarse level is encoded over: its minimum and its span\nfloat dec(vec4 t, vec2 hr) { return hr.x + (t.r * 255.0 * 256.0 + t.g * 255.0) / 65535.0 * hr.y; }\n\nfloat lin(sampler2D s, vec2 p, vec4 l, vec2 hr) {\n vec2 f = vec2((p.x + l.x) / l.y - 0.5, (l.x - p.y) / l.y - 0.5);\n vec2 i = floor(f);\n vec2 t = f - i;\n float st = 1.0 / l.z;\n vec2 uv = (i + 0.5) * st;\n float a = dec(texture2D(s, uv), hr);\n float b = dec(texture2D(s, uv + vec2(st, 0.0)), hr);\n float c = dec(texture2D(s, uv + vec2(0.0, st)), hr);\n float d = dec(texture2D(s, uv + vec2(st, st)), hr);\n return mix(mix(a, b, t.x), mix(c, d, t.x), t.y);\n}\n\nfloat nearest(sampler2D s, vec2 p, vec4 l, vec2 hr) {\n vec2 uv = vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z));\n return dec(texture2D(s, uv), hr);\n}\n\nbool holds(vec2 p, vec4 l, float dist) { return dist < l.w && abs(p.x) < l.x - 2.0 * l.y && abs(p.y) < l.x - 2.0 * l.y; }\n\n// the ground's height over the site's, the sphere's fall taken off; `fine` reads four samples, otherwise one\nfloat terrainY(vec2 p, float dist, bool fine) {\n float h;\n if (holds(p, uL0, dist)) h = fine ? lin(uH0, p, uL0, vec2(uHmin, uHrange)) : nearest(uH0, p, uL0, vec2(uHmin, uHrange));\n else if (holds(p, uL1, dist)) h = fine ? lin(uH1, p, uL1, vec2(uHmin, uHrange)) : nearest(uH1, p, uL1, vec2(uHmin, uHrange));\n else if (holds(p, uL2, dist)) h = fine ? lin(uH2, p, uL2, vec2(uHmin, uHrange)) : nearest(uH2, p, uL2, vec2(uHmin, uHrange));\n else h = fine ? lin(uH3, p, uL3, uFarHeight) : nearest(uH3, p, uL3, uFarHeight);\n return h - uGround - dot(p, p) / (2.0 * uRadius);\n}\n\n// the ground's own brightness at a point, from the picture of the level that serves it, 1 where it is the middle\nfloat albedoAt(vec2 p, float dist) {\n if (uPicture < 0.5) return 1.0;\n vec4 l;\n if (holds(p, uL0, dist)) { l = uL0; return 2.0 * texture2D(uA0, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n if (holds(p, uL1, dist)) { l = uL1; return 2.0 * texture2D(uA1, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n if (holds(p, uL2, dist)) { l = uL2; return 2.0 * texture2D(uA2, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n return 1.0;\n}\n\n// the measured ground's shadows, baked (scripts/make-moon-terrain.py): for a point, the elevation angle in degrees of the horizon toward the Sun, read from the finest of the three horizon maps that holds the point\nuniform sampler2D uZ0;\nuniform sampler2D uZ1;\nuniform sampler2D uZ2;\nuniform float uHzOn; // 1 where the maps are there\nuniform vec3 uHzSun; // the two directions (of 18) the Sun's azimuth lies between, and the share of the second\nuniform vec2 uHzRange; // the degrees the codes 0 and 255 stand for\n\nfloat hzSector(sampler2D s, vec2 cell, float k) {\n float slab = floor(k / 3.0);\n float ch = k - slab * 3.0;\n vec3 v = texture2D(s, vec2((cell.x + slab) / 6.0, cell.y)).rgb;\n return ch < 0.5 ? v.r : (ch < 1.5 ? v.g : v.b);\n}\n\nfloat hzFrom(sampler2D s, vec2 p, float reach) {\n vec2 cell = clamp(vec2((p.x + reach) / (2.0 * reach), (reach - p.y) / (2.0 * reach)), vec2(0.5 / 512.0), vec2(1.0 - 0.5 / 512.0));\n float code = mix(hzSector(s, cell, uHzSun.x), hzSector(s, cell, uHzSun.y), uHzSun.z);\n return uHzRange.x + code * (uHzRange.y - uHzRange.x);\n}\n\nfloat horizonAt(vec2 p) {\n if (abs(p.x) < uL0.x && abs(p.y) < uL0.x) return hzFrom(uZ0, p, uL0.x);\n if (abs(p.x) < uL1.x && abs(p.y) < uL1.x) return hzFrom(uZ1, p, uL1.x);\n if (abs(p.x) < uL2.x && abs(p.y) < uL2.x) return hzFrom(uZ2, p, uL2.x);\n return -90.0;\n}\n\n// the spacing of the level that serves a point, for the step of a slope\nfloat spacing(vec2 p, float dist) {\n if (holds(p, uL0, dist)) return uL0.y;\n if (holds(p, uL1, dist)) return uL1.y;\n if (holds(p, uL2, dist)) return uL2.y;\n return uL3.y;\n}\n\n\nuniform float uPixel; // the angle one pixel takes, radians\nuniform float uDetail; // 1 for the made detail, 0 for none\n\nuvec2 pcg2d(uvec2 v) {\n v = v * 1664525u + 1013904223u;\n v.x += v.y * 1664525u;\n v.y += v.x * 1664525u;\n v = v ^ (v >> 16u);\n v.x += v.y * 1664525u;\n v.y += v.x * 1664525u;\n v = v ^ (v >> 16u);\n return v;\n}\nfloat u24(uint h) { return float(h >> 8u) * (1.0 / 16777216.0); }\n\nuniform vec4 uKeep[6]; // the objects the made ground keeps away from: east, north, the distance inside which nothing is made, the distance outside which it all is\nuniform float uKeepCount;\nfloat keepMask(vec2 p) {\n float keep = 1.0;\n for (int i = 0; i < 6; i += 1) {\n if (float(i) >= uKeepCount) break;\n vec4 k = uKeep[i];\n float t = clamp((distance(p, k.xy) - k.z) / (k.w - k.z), 0.0, 1.0);\n keep = min(keep, t * t * (3.0 - 2.0 * t));\n }\n return keep;\n}\n\n// the made ground at a point: x the height in metres, yz the slope east and north, from every crater of every octave whose nominal diameter is over `fromD`\nvec3 madeGround(vec2 p, float fromD) {\n vec3 sum = vec3(0.0);\n for (int octave = 5; octave >= 0; octave -= 1) {\n float nominal = 0.5 * exp2(float(octave));\n float fade = clamp(nominal / fromD - 1.0, 0.0, 1.0);\n if (fade <= 0.0) break;\n float cell = 3.0 * nominal;\n ivec2 base = ivec2(floor(p / cell));\n vec2 fr = p / cell - vec2(base);\n float occ = (octave >= 3 ? 0.5 : 1.0) * 0.36 * exp2(-0.5 * float(octave));\n for (int j = -1; j <= 1; j += 1) {\n for (int i = -1; i <= 1; i += 1) {\n // a crater is kept to the middle of its cell, so a neighbour's reaches this cell only within a fifth of the edge\n if ((i == -1 && fr.x > 0.2) || (i == 1 && fr.x < 0.8) || (j == -1 && fr.y > 0.2) || (j == 1 && fr.y < 0.8)) continue;\n ivec2 c = base + ivec2(i, j);\n uvec2 ab = pcg2d(uvec2(uint(c.x), uint(c.y + octave * 7919)));\n if (u24(ab.x) >= occ) continue;\n uvec2 cd = pcg2d(uvec2(uint(c.x + 104729), uint(c.y + octave * 7919 + 15485863)));\n float diameter = nominal * (1.0 + (octave == 5 ? 0.25 : 1.0) * u24(cd.y));\n float r4 = float(ab.x & 255u) / 255.0;\n float age = 1.0 - r4 * r4 * r4 * r4;\n float radius = 0.5 * diameter;\n float vary = 0.6 + 0.4 * (float(cd.x & 255u) / 255.0);\n float depth = diameter * (0.2 - 0.17 * age) * vary;\n float rim = 0.045 * diameter * pow(1.0 - age, 1.5);\n float rimWidth = 0.22 + 0.5 * age;\n vec2 centre = vec2(float(c.x) + 0.25 + 0.5 * u24(ab.y), float(c.y) + 0.25 + 0.5 * u24(cd.x)) * cell;\n vec2 d = p - centre;\n float r = length(d);\n float x = r / radius;\n float h = 0.0;\n float dh = 0.0;\n if (x < 1.0) { float bowl = 1.0 - x * x; float pw = 1.0 + age; h = -depth * pow(bowl, pw); dh = 2.0 * depth * pw * x * pow(bowl, age); }\n float e = (x - 1.0) / rimWidth;\n float ex = exp(-e * e);\n h += rim * ex;\n dh += -2.0 * rim * e * ex / rimWidth;\n if (x > 1.0) { float t = 1.0 / x; h += 0.25 * rim * t * t * t; dh += -0.75 * rim * t * t * t * t; }\n float k = r > 1e-6 ? dh / (radius * r) : 0.0;\n sum += fade * vec3(h, k * d.x, k * d.y);\n }\n }\n }\n return sum * keepMask(p);\n}\n\nfloat vnoise(vec2 p) {\n vec2 i = floor(p);\n vec2 f = p - i;\n vec2 w = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);\n uvec2 c = uvec2(ivec2(i));\n float a = u24(pcg2d(c).x);\n float b = u24(pcg2d(c + uvec2(1u, 0u)).x);\n float cc = u24(pcg2d(c + uvec2(0u, 1u)).x);\n float d = u24(pcg2d(c + uvec2(1u, 1u)).x);\n return mix(mix(a, b, w.x), mix(cc, d, w.x), w.y);\n}\n\n// a fine roughness of the dust: two scales, as a slope (east, north), faded out where a pixel covers more than a few of its grains\nvec2 roughness(vec2 p, float footprint) {\n vec2 g = vec2(0.0);\n for (int k = 0; k < 2; k += 1) {\n float s = k == 0 ? 0.07 : 0.3;\n float amp = k == 0 ? 0.3 : 0.28;\n float fade = smoothstep(footprint * 2.0, footprint * 7.0, s);\n if (fade <= 0.0) continue;\n float d = s * 0.25;\n vec2 q = (k == 0 ? vec2(p.x * 0.629 + p.y * 0.777, p.y * 0.629 - p.x * 0.777) : vec2(p.x * 0.857 - p.y * 0.515, p.x * 0.515 + p.y * 0.857)) / s;\n float dx = vnoise(q + vec2(0.25, 0.0)) - vnoise(q - vec2(0.25, 0.0));\n float dy = vnoise(q + vec2(0.0, 0.25)) - vnoise(q - vec2(0.0, 0.25));\n g += fade * amp * vec2(dx, dy) / (0.5 * s) * 0.012;\n }\n return g;\n}\n\n\n// the ground's height at a point: the measured heights and, near the eyes, the made craters (kept to the ones a pixel here can show)\nfloat groundY(vec2 p, float dist, bool fine, float fromD) {\n float y = terrainY(p, dist, fine);\n if (uDetail > 0.5 && fromD < 24.0) y += madeGround(p, fromD).x;\n return y;\n}\n\n// 1 where the Sun reaches a point, 0 where the ground is in its way. The measured ground's shadow is read from the baked horizon; the march toward the Sun over the heights (and the made craters) is the near\n// field's only, a few tens of metres with a fixed number of steps, as sharp as the Sun's edge. Where there is no baked horizon the march goes all the way, as it did before the maps.\nfloat lit(vec3 P, float dist0) {\n vec2 dir = normalize(uSun.xz);\n float slope = uSun.y / max(length(uSun.xz), 1e-4);\n if (uHzOn > 0.5 && horizonAt(P.xz) - 0.3 > uSunDegrees) return 0.0;\n // the ground at the point from the heights themselves, not the mesh's slope between its corners, which can be a long way off on a far mountain\n // the made craters are in the ground at the point only where they are in the march too (uNear.z is 0 in the quality of motion, which leaves them out of the march): a point set down in a made crater's floor and a ray over the ground without the crater put the whole floor under the ground's height, black\n P.y = groundY(P.xz, dist0, true, uNear.z > 0.0 ? 2.5 * dist0 * uPixel : 99.0);\n float t = 0.5 * spacing(P.xz, dist0) + 0.25;\n if (uDetail > 0.5) t = min(t, 0.2 + 0.02 * dist0);\n // a pixel's own start along the ray: the edge of a rim's shadow is a line of steps, and a line of steps is jagged; with a start of its own each pixel it becomes a fine grain instead\n float jitter = fract(sin(dot(P.xz, vec2(12.9898, 78.233))) * 43758.5453);\n float range = uHzOn > 0.5 ? uNear.y : 80000.0;\n for (int i = 0; i < 260; i += 1) {\n if (float(i) >= uNear.x) break;\n vec2 q = P.xz + dir * t;\n float y = P.y + slope * t;\n float dist = max(t, distance(q, uEyeEN));\n float res = spacing(q, dist);\n float h = groundY(q, dist, t < 600.0, t < uNear.z ? max(0.2 * t, 2.5 * dist * uPixel) : 99.0);\n float bias = (t < 40.0 ? 0.01 : 0.3 * res) + 0.002 * t;\n if (h > y + bias) return 0.0;\n if (y > uMaxY || t > range) break;\n float step = t < 30.0 ? t * 0.045 + 0.04 : t * 0.06 + 0.5;\n t += step * (0.65 + 0.7 * jitter);\n }\n return 1.0;\n}\n";
9
9
  /** The ground's light. */
10
- export declare const GROUND_FRAGMENT = "\nprecision highp float;\nprecision highp sampler2D;\n\nuniform vec3 uSun;\nuniform vec3 uEye;\nuniform vec2 uEyeEN;\nuniform float uExposure;\nuniform float uAlbedo;\nuniform float uMaxY; // the highest ground over the site's, for the end of a shadow's march\nuniform float uEarthshine; // the light of the sunlit ground round the shade, a small share of a lit slope's (on Mars the sky's light, a good deal more)\nuniform vec3 uTint; // the ground's colour over its grey: white on the Moon\nuniform float uShadows; // 1 for the ground to shadow itself (the default), 0 for none (a try-out)\nuniform float uSunDegrees; // the Sun's elevation in degrees\nuniform vec3 uNear; // the near march: steps, the distance it reaches in metres, the distance out to which the made craters are in it (the quality of the draw)\n\nuniform sampler2D uH0;\nuniform sampler2D uH1;\nuniform sampler2D uH2;\nuniform sampler2D uH3;\nuniform sampler2D uA0; // the ground picture on the first three levels, 0 to 1 with the middle at 0.5\nuniform sampler2D uA1;\nuniform sampler2D uA2;\nuniform float uPicture; // 1 where the picture is there\nuniform vec4 uL0; // half width, metres a sample, samples across, the distance out to which this level is used\nuniform vec4 uL1;\nuniform vec4 uL2;\nuniform vec4 uL3;\nuniform float uHmin;\nuniform float uHrange;\nuniform float uGround;\nuniform float uRadius;\n\nuniform vec2 uFarHeight; // the range the coarse level is encoded over: its minimum and its span\nfloat dec(vec4 t, vec2 hr) { return hr.x + (t.r * 255.0 * 256.0 + t.g * 255.0) / 65535.0 * hr.y; }\n\nfloat lin(sampler2D s, vec2 p, vec4 l, vec2 hr) {\n vec2 f = vec2((p.x + l.x) / l.y - 0.5, (l.x - p.y) / l.y - 0.5);\n vec2 i = floor(f);\n vec2 t = f - i;\n float st = 1.0 / l.z;\n vec2 uv = (i + 0.5) * st;\n float a = dec(texture2D(s, uv), hr);\n float b = dec(texture2D(s, uv + vec2(st, 0.0)), hr);\n float c = dec(texture2D(s, uv + vec2(0.0, st)), hr);\n float d = dec(texture2D(s, uv + vec2(st, st)), hr);\n return mix(mix(a, b, t.x), mix(c, d, t.x), t.y);\n}\n\nfloat nearest(sampler2D s, vec2 p, vec4 l, vec2 hr) {\n vec2 uv = vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z));\n return dec(texture2D(s, uv), hr);\n}\n\nbool holds(vec2 p, vec4 l, float dist) { return dist < l.w && abs(p.x) < l.x - 2.0 * l.y && abs(p.y) < l.x - 2.0 * l.y; }\n\n// the ground's height over the site's, the sphere's fall taken off; `fine` reads four samples, otherwise one\nfloat terrainY(vec2 p, float dist, bool fine) {\n float h;\n if (holds(p, uL0, dist)) h = fine ? lin(uH0, p, uL0, vec2(uHmin, uHrange)) : nearest(uH0, p, uL0, vec2(uHmin, uHrange));\n else if (holds(p, uL1, dist)) h = fine ? lin(uH1, p, uL1, vec2(uHmin, uHrange)) : nearest(uH1, p, uL1, vec2(uHmin, uHrange));\n else if (holds(p, uL2, dist)) h = fine ? lin(uH2, p, uL2, vec2(uHmin, uHrange)) : nearest(uH2, p, uL2, vec2(uHmin, uHrange));\n else h = fine ? lin(uH3, p, uL3, uFarHeight) : nearest(uH3, p, uL3, uFarHeight);\n return h - uGround - dot(p, p) / (2.0 * uRadius);\n}\n\n// the ground's own brightness at a point, from the picture of the level that serves it, 1 where it is the middle\nfloat albedoAt(vec2 p, float dist) {\n if (uPicture < 0.5) return 1.0;\n vec4 l;\n if (holds(p, uL0, dist)) { l = uL0; return 2.0 * texture2D(uA0, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n if (holds(p, uL1, dist)) { l = uL1; return 2.0 * texture2D(uA1, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n if (holds(p, uL2, dist)) { l = uL2; return 2.0 * texture2D(uA2, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n return 1.0;\n}\n\n// the measured ground's shadows, baked (scripts/make-moon-terrain.py): for a point, the elevation angle in degrees of the horizon toward the Sun, read from the finest of the three horizon maps that holds the point\nuniform sampler2D uZ0;\nuniform sampler2D uZ1;\nuniform sampler2D uZ2;\nuniform float uHzOn; // 1 where the maps are there\nuniform vec3 uHzSun; // the two directions (of 18) the Sun's azimuth lies between, and the share of the second\nuniform vec2 uHzRange; // the degrees the codes 0 and 255 stand for\n\nfloat hzSector(sampler2D s, vec2 cell, float k) {\n float slab = floor(k / 3.0);\n float ch = k - slab * 3.0;\n vec3 v = texture2D(s, vec2((cell.x + slab) / 6.0, cell.y)).rgb;\n return ch < 0.5 ? v.r : (ch < 1.5 ? v.g : v.b);\n}\n\nfloat hzFrom(sampler2D s, vec2 p, float reach) {\n vec2 cell = clamp(vec2((p.x + reach) / (2.0 * reach), (reach - p.y) / (2.0 * reach)), vec2(0.5 / 512.0), vec2(1.0 - 0.5 / 512.0));\n float code = mix(hzSector(s, cell, uHzSun.x), hzSector(s, cell, uHzSun.y), uHzSun.z);\n return uHzRange.x + code * (uHzRange.y - uHzRange.x);\n}\n\nfloat horizonAt(vec2 p) {\n if (abs(p.x) < uL0.x && abs(p.y) < uL0.x) return hzFrom(uZ0, p, uL0.x);\n if (abs(p.x) < uL1.x && abs(p.y) < uL1.x) return hzFrom(uZ1, p, uL1.x);\n if (abs(p.x) < uL2.x && abs(p.y) < uL2.x) return hzFrom(uZ2, p, uL2.x);\n return -90.0;\n}\n\n// the spacing of the level that serves a point, for the step of a slope\nfloat spacing(vec2 p, float dist) {\n if (holds(p, uL0, dist)) return uL0.y;\n if (holds(p, uL1, dist)) return uL1.y;\n if (holds(p, uL2, dist)) return uL2.y;\n return uL3.y;\n}\n\n\nuniform float uPixel; // the angle one pixel takes, radians\nuniform float uDetail; // 1 for the made detail, 0 for none\n\nuvec2 pcg2d(uvec2 v) {\n v = v * 1664525u + 1013904223u;\n v.x += v.y * 1664525u;\n v.y += v.x * 1664525u;\n v = v ^ (v >> 16u);\n v.x += v.y * 1664525u;\n v.y += v.x * 1664525u;\n v = v ^ (v >> 16u);\n return v;\n}\nfloat u24(uint h) { return float(h >> 8u) * (1.0 / 16777216.0); }\n\nuniform vec4 uKeep[6]; // the objects the made ground keeps away from: east, north, the distance inside which nothing is made, the distance outside which it all is\nuniform float uKeepCount;\nfloat keepMask(vec2 p) {\n float keep = 1.0;\n for (int i = 0; i < 6; i += 1) {\n if (float(i) >= uKeepCount) break;\n vec4 k = uKeep[i];\n float t = clamp((distance(p, k.xy) - k.z) / (k.w - k.z), 0.0, 1.0);\n keep = min(keep, t * t * (3.0 - 2.0 * t));\n }\n return keep;\n}\n\n// the made ground at a point: x the height in metres, yz the slope east and north, from every crater of every octave whose nominal diameter is over `fromD`\nvec3 madeGround(vec2 p, float fromD) {\n vec3 sum = vec3(0.0);\n for (int octave = 5; octave >= 0; octave -= 1) {\n float nominal = 0.5 * exp2(float(octave));\n float fade = clamp(nominal / fromD - 1.0, 0.0, 1.0);\n if (fade <= 0.0) break;\n float cell = 3.0 * nominal;\n ivec2 base = ivec2(floor(p / cell));\n vec2 fr = p / cell - vec2(base);\n float occ = (octave >= 3 ? 0.5 : 1.0) * 0.36 * exp2(-0.5 * float(octave));\n for (int j = -1; j <= 1; j += 1) {\n for (int i = -1; i <= 1; i += 1) {\n // a crater is kept to the middle of its cell, so a neighbour's reaches this cell only within a fifth of the edge\n if ((i == -1 && fr.x > 0.2) || (i == 1 && fr.x < 0.8) || (j == -1 && fr.y > 0.2) || (j == 1 && fr.y < 0.8)) continue;\n ivec2 c = base + ivec2(i, j);\n uvec2 ab = pcg2d(uvec2(uint(c.x), uint(c.y + octave * 7919)));\n if (u24(ab.x) >= occ) continue;\n uvec2 cd = pcg2d(uvec2(uint(c.x + 104729), uint(c.y + octave * 7919 + 15485863)));\n float diameter = nominal * (1.0 + (octave == 5 ? 0.25 : 1.0) * u24(cd.y));\n float r4 = float(ab.x & 255u) / 255.0;\n float age = 1.0 - r4 * r4 * r4 * r4;\n float radius = 0.5 * diameter;\n float vary = 0.6 + 0.4 * (float(cd.x & 255u) / 255.0);\n float depth = diameter * (0.2 - 0.17 * age) * vary;\n float rim = 0.045 * diameter * pow(1.0 - age, 1.5);\n float rimWidth = 0.22 + 0.5 * age;\n vec2 centre = vec2(float(c.x) + 0.25 + 0.5 * u24(ab.y), float(c.y) + 0.25 + 0.5 * u24(cd.x)) * cell;\n vec2 d = p - centre;\n float r = length(d);\n float x = r / radius;\n float h = 0.0;\n float dh = 0.0;\n if (x < 1.0) { float bowl = 1.0 - x * x; float pw = 1.0 + age; h = -depth * pow(bowl, pw); dh = 2.0 * depth * pw * x * pow(bowl, age); }\n float e = (x - 1.0) / rimWidth;\n float ex = exp(-e * e);\n h += rim * ex;\n dh += -2.0 * rim * e * ex / rimWidth;\n if (x > 1.0) { float t = 1.0 / x; h += 0.25 * rim * t * t * t; dh += -0.75 * rim * t * t * t * t; }\n float k = r > 1e-6 ? dh / (radius * r) : 0.0;\n sum += fade * vec3(h, k * d.x, k * d.y);\n }\n }\n }\n return sum * keepMask(p);\n}\n\nfloat vnoise(vec2 p) {\n vec2 i = floor(p);\n vec2 f = p - i;\n vec2 w = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);\n uvec2 c = uvec2(ivec2(i));\n float a = u24(pcg2d(c).x);\n float b = u24(pcg2d(c + uvec2(1u, 0u)).x);\n float cc = u24(pcg2d(c + uvec2(0u, 1u)).x);\n float d = u24(pcg2d(c + uvec2(1u, 1u)).x);\n return mix(mix(a, b, w.x), mix(cc, d, w.x), w.y);\n}\n\n// a fine roughness of the dust: two scales, as a slope (east, north), faded out where a pixel covers more than a few of its grains\nvec2 roughness(vec2 p, float footprint) {\n vec2 g = vec2(0.0);\n for (int k = 0; k < 2; k += 1) {\n float s = k == 0 ? 0.07 : 0.3;\n float amp = k == 0 ? 0.3 : 0.28;\n float fade = smoothstep(footprint * 2.0, footprint * 7.0, s);\n if (fade <= 0.0) continue;\n float d = s * 0.25;\n vec2 q = (k == 0 ? vec2(p.x * 0.629 + p.y * 0.777, p.y * 0.629 - p.x * 0.777) : vec2(p.x * 0.857 - p.y * 0.515, p.x * 0.515 + p.y * 0.857)) / s;\n float dx = vnoise(q + vec2(0.25, 0.0)) - vnoise(q - vec2(0.25, 0.0));\n float dy = vnoise(q + vec2(0.0, 0.25)) - vnoise(q - vec2(0.0, 0.25));\n g += fade * amp * vec2(dx, dy) / (0.5 * s) * 0.012;\n }\n return g;\n}\n\n\n// the ground's height at a point: the measured heights and, near the eyes, the made craters (kept to the ones a pixel here can show)\nfloat groundY(vec2 p, float dist, bool fine, float fromD) {\n float y = terrainY(p, dist, fine);\n if (uDetail > 0.5 && fromD < 24.0) y += madeGround(p, fromD).x;\n return y;\n}\n\n// 1 where the Sun reaches a point, 0 where the ground is in its way. The measured ground's shadow is read from the baked horizon; the march toward the Sun over the heights (and the made craters) is the near\n// field's only, a few tens of metres with a fixed number of steps, as sharp as the Sun's edge. Where there is no baked horizon the march goes all the way, as it did before the maps.\nfloat lit(vec3 P, float dist0) {\n vec2 dir = normalize(uSun.xz);\n float slope = uSun.y / max(length(uSun.xz), 1e-4);\n if (uHzOn > 0.5 && horizonAt(P.xz) - 0.3 > uSunDegrees) return 0.0;\n // the ground at the point from the heights themselves, not the mesh's slope between its corners, which can be a long way off on a far mountain\n P.y = groundY(P.xz, dist0, true, 2.5 * dist0 * uPixel);\n float t = 0.5 * spacing(P.xz, dist0) + 0.25;\n if (uDetail > 0.5) t = min(t, 0.2 + 0.02 * dist0);\n // a pixel's own start along the ray: the edge of a rim's shadow is a line of steps, and a line of steps is jagged; with a start of its own each pixel it becomes a fine grain instead\n float jitter = fract(sin(dot(P.xz, vec2(12.9898, 78.233))) * 43758.5453);\n float range = uHzOn > 0.5 ? uNear.y : 80000.0;\n for (int i = 0; i < 260; i += 1) {\n if (float(i) >= uNear.x) break;\n vec2 q = P.xz + dir * t;\n float y = P.y + slope * t;\n float dist = max(t, distance(q, uEyeEN));\n float res = spacing(q, dist);\n float h = groundY(q, dist, t < 600.0, t < uNear.z ? max(0.2 * t, 2.5 * dist * uPixel) : 99.0);\n float bias = (t < 40.0 ? 0.01 : 0.3 * res) + 0.002 * t;\n if (h > y + bias) return 0.0;\n if (y > uMaxY || t > range) break;\n float step = t < 30.0 ? t * 0.045 + 0.04 : t * 0.06 + 0.5;\n t += step * (0.65 + 0.7 * jitter);\n }\n return 1.0;\n}\n\nvarying vec3 vP;\n\nvoid main() {\n float dist = distance(vP.xz, uEyeEN);\n float fromD = 2.5 * dist * uPixel;\n float e = max(spacing(vP.xz, dist), dist * 0.001);\n float hE = terrainY(vP.xz + vec2(e, 0.0), dist, true);\n float hW = terrainY(vP.xz - vec2(e, 0.0), dist, true);\n float hN = terrainY(vP.xz + vec2(0.0, e), dist, true);\n float hS = terrainY(vP.xz - vec2(0.0, e), dist, true);\n vec2 slope = vec2((hE - hW) / (2.0 * e), (hN - hS) / (2.0 * e));\n if (uDetail > 0.5) {\n if (fromD < 24.0) slope += madeGround(vP.xz, fromD).yz;\n slope += roughness(vP.xz, dist * uPixel);\n }\n vec3 n = normalize(vec3(-slope.x, 1.0, -slope.y));\n float mu0 = dot(n, uSun);\n float mu = max(dot(n, normalize(uEye - vP)), 0.03);\n float shine = 0.0;\n if (mu0 > 0.0 && uSun.y > -0.01) shine = (uShadows > 0.5 ? lit(vP, dist) : 1.0) * 2.0 * mu0 / (mu0 + mu);\n float light = uAlbedo * albedoAt(vP.xz, dist) * (shine + uEarthshine * max(n.y, 0.0)) * uExposure;\n gl_FragColor = vec4(pow(clamp(vec3(light) * uTint, 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);\n}\n";
10
+ export declare const GROUND_FRAGMENT = "\nprecision highp float;\nprecision highp sampler2D;\n\nuniform vec3 uSun;\nuniform vec3 uEye;\nuniform vec2 uEyeEN;\nuniform float uExposure;\nuniform float uAlbedo;\nuniform float uMaxY; // the highest ground over the site's, for the end of a shadow's march\nuniform float uEarthshine; // the light of the sunlit ground round the shade, a small share of a lit slope's (on Mars the sky's light, a good deal more)\nuniform vec3 uTint; // the ground's colour over its grey: white on the Moon\nuniform float uShadows; // 1 for the ground to shadow itself (the default), 0 for none (a try-out)\nuniform float uSunDegrees; // the Sun's elevation in degrees\nuniform vec3 uNear; // the near march: steps, the distance it reaches in metres, the distance out to which the made craters are in it (the quality of the draw)\n\nuniform sampler2D uH0;\nuniform sampler2D uH1;\nuniform sampler2D uH2;\nuniform sampler2D uH3;\nuniform sampler2D uA0; // the ground picture on the first three levels, 0 to 1 with the middle at 0.5\nuniform sampler2D uA1;\nuniform sampler2D uA2;\nuniform float uPicture; // 1 where the picture is there\nuniform vec4 uL0; // half width, metres a sample, samples across, the distance out to which this level is used\nuniform vec4 uL1;\nuniform vec4 uL2;\nuniform vec4 uL3;\nuniform float uHmin;\nuniform float uHrange;\nuniform float uGround;\nuniform float uRadius;\n\nuniform vec2 uFarHeight; // the range the coarse level is encoded over: its minimum and its span\nfloat dec(vec4 t, vec2 hr) { return hr.x + (t.r * 255.0 * 256.0 + t.g * 255.0) / 65535.0 * hr.y; }\n\nfloat lin(sampler2D s, vec2 p, vec4 l, vec2 hr) {\n vec2 f = vec2((p.x + l.x) / l.y - 0.5, (l.x - p.y) / l.y - 0.5);\n vec2 i = floor(f);\n vec2 t = f - i;\n float st = 1.0 / l.z;\n vec2 uv = (i + 0.5) * st;\n float a = dec(texture2D(s, uv), hr);\n float b = dec(texture2D(s, uv + vec2(st, 0.0)), hr);\n float c = dec(texture2D(s, uv + vec2(0.0, st)), hr);\n float d = dec(texture2D(s, uv + vec2(st, st)), hr);\n return mix(mix(a, b, t.x), mix(c, d, t.x), t.y);\n}\n\nfloat nearest(sampler2D s, vec2 p, vec4 l, vec2 hr) {\n vec2 uv = vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z));\n return dec(texture2D(s, uv), hr);\n}\n\nbool holds(vec2 p, vec4 l, float dist) { return dist < l.w && abs(p.x) < l.x - 2.0 * l.y && abs(p.y) < l.x - 2.0 * l.y; }\n\n// the ground's height over the site's, the sphere's fall taken off; `fine` reads four samples, otherwise one\nfloat terrainY(vec2 p, float dist, bool fine) {\n float h;\n if (holds(p, uL0, dist)) h = fine ? lin(uH0, p, uL0, vec2(uHmin, uHrange)) : nearest(uH0, p, uL0, vec2(uHmin, uHrange));\n else if (holds(p, uL1, dist)) h = fine ? lin(uH1, p, uL1, vec2(uHmin, uHrange)) : nearest(uH1, p, uL1, vec2(uHmin, uHrange));\n else if (holds(p, uL2, dist)) h = fine ? lin(uH2, p, uL2, vec2(uHmin, uHrange)) : nearest(uH2, p, uL2, vec2(uHmin, uHrange));\n else h = fine ? lin(uH3, p, uL3, uFarHeight) : nearest(uH3, p, uL3, uFarHeight);\n return h - uGround - dot(p, p) / (2.0 * uRadius);\n}\n\n// the ground's own brightness at a point, from the picture of the level that serves it, 1 where it is the middle\nfloat albedoAt(vec2 p, float dist) {\n if (uPicture < 0.5) return 1.0;\n vec4 l;\n if (holds(p, uL0, dist)) { l = uL0; return 2.0 * texture2D(uA0, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n if (holds(p, uL1, dist)) { l = uL1; return 2.0 * texture2D(uA1, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n if (holds(p, uL2, dist)) { l = uL2; return 2.0 * texture2D(uA2, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n return 1.0;\n}\n\n// the measured ground's shadows, baked (scripts/make-moon-terrain.py): for a point, the elevation angle in degrees of the horizon toward the Sun, read from the finest of the three horizon maps that holds the point\nuniform sampler2D uZ0;\nuniform sampler2D uZ1;\nuniform sampler2D uZ2;\nuniform float uHzOn; // 1 where the maps are there\nuniform vec3 uHzSun; // the two directions (of 18) the Sun's azimuth lies between, and the share of the second\nuniform vec2 uHzRange; // the degrees the codes 0 and 255 stand for\n\nfloat hzSector(sampler2D s, vec2 cell, float k) {\n float slab = floor(k / 3.0);\n float ch = k - slab * 3.0;\n vec3 v = texture2D(s, vec2((cell.x + slab) / 6.0, cell.y)).rgb;\n return ch < 0.5 ? v.r : (ch < 1.5 ? v.g : v.b);\n}\n\nfloat hzFrom(sampler2D s, vec2 p, float reach) {\n vec2 cell = clamp(vec2((p.x + reach) / (2.0 * reach), (reach - p.y) / (2.0 * reach)), vec2(0.5 / 512.0), vec2(1.0 - 0.5 / 512.0));\n float code = mix(hzSector(s, cell, uHzSun.x), hzSector(s, cell, uHzSun.y), uHzSun.z);\n return uHzRange.x + code * (uHzRange.y - uHzRange.x);\n}\n\nfloat horizonAt(vec2 p) {\n if (abs(p.x) < uL0.x && abs(p.y) < uL0.x) return hzFrom(uZ0, p, uL0.x);\n if (abs(p.x) < uL1.x && abs(p.y) < uL1.x) return hzFrom(uZ1, p, uL1.x);\n if (abs(p.x) < uL2.x && abs(p.y) < uL2.x) return hzFrom(uZ2, p, uL2.x);\n return -90.0;\n}\n\n// the spacing of the level that serves a point, for the step of a slope\nfloat spacing(vec2 p, float dist) {\n if (holds(p, uL0, dist)) return uL0.y;\n if (holds(p, uL1, dist)) return uL1.y;\n if (holds(p, uL2, dist)) return uL2.y;\n return uL3.y;\n}\n\n\nuniform float uPixel; // the angle one pixel takes, radians\nuniform float uDetail; // 1 for the made detail, 0 for none\n\nuvec2 pcg2d(uvec2 v) {\n v = v * 1664525u + 1013904223u;\n v.x += v.y * 1664525u;\n v.y += v.x * 1664525u;\n v = v ^ (v >> 16u);\n v.x += v.y * 1664525u;\n v.y += v.x * 1664525u;\n v = v ^ (v >> 16u);\n return v;\n}\nfloat u24(uint h) { return float(h >> 8u) * (1.0 / 16777216.0); }\n\nuniform vec4 uKeep[6]; // the objects the made ground keeps away from: east, north, the distance inside which nothing is made, the distance outside which it all is\nuniform float uKeepCount;\nfloat keepMask(vec2 p) {\n float keep = 1.0;\n for (int i = 0; i < 6; i += 1) {\n if (float(i) >= uKeepCount) break;\n vec4 k = uKeep[i];\n float t = clamp((distance(p, k.xy) - k.z) / (k.w - k.z), 0.0, 1.0);\n keep = min(keep, t * t * (3.0 - 2.0 * t));\n }\n return keep;\n}\n\n// the made ground at a point: x the height in metres, yz the slope east and north, from every crater of every octave whose nominal diameter is over `fromD`\nvec3 madeGround(vec2 p, float fromD) {\n vec3 sum = vec3(0.0);\n for (int octave = 5; octave >= 0; octave -= 1) {\n float nominal = 0.5 * exp2(float(octave));\n float fade = clamp(nominal / fromD - 1.0, 0.0, 1.0);\n if (fade <= 0.0) break;\n float cell = 3.0 * nominal;\n ivec2 base = ivec2(floor(p / cell));\n vec2 fr = p / cell - vec2(base);\n float occ = (octave >= 3 ? 0.5 : 1.0) * 0.36 * exp2(-0.5 * float(octave));\n for (int j = -1; j <= 1; j += 1) {\n for (int i = -1; i <= 1; i += 1) {\n // a crater is kept to the middle of its cell, so a neighbour's reaches this cell only within a fifth of the edge\n if ((i == -1 && fr.x > 0.2) || (i == 1 && fr.x < 0.8) || (j == -1 && fr.y > 0.2) || (j == 1 && fr.y < 0.8)) continue;\n ivec2 c = base + ivec2(i, j);\n uvec2 ab = pcg2d(uvec2(uint(c.x), uint(c.y + octave * 7919)));\n if (u24(ab.x) >= occ) continue;\n uvec2 cd = pcg2d(uvec2(uint(c.x + 104729), uint(c.y + octave * 7919 + 15485863)));\n float diameter = nominal * (1.0 + (octave == 5 ? 0.25 : 1.0) * u24(cd.y));\n float r4 = float(ab.x & 255u) / 255.0;\n float age = 1.0 - r4 * r4 * r4 * r4;\n float radius = 0.5 * diameter;\n float vary = 0.6 + 0.4 * (float(cd.x & 255u) / 255.0);\n float depth = diameter * (0.2 - 0.17 * age) * vary;\n float rim = 0.045 * diameter * pow(1.0 - age, 1.5);\n float rimWidth = 0.22 + 0.5 * age;\n vec2 centre = vec2(float(c.x) + 0.25 + 0.5 * u24(ab.y), float(c.y) + 0.25 + 0.5 * u24(cd.x)) * cell;\n vec2 d = p - centre;\n float r = length(d);\n float x = r / radius;\n float h = 0.0;\n float dh = 0.0;\n if (x < 1.0) { float bowl = 1.0 - x * x; float pw = 1.0 + age; h = -depth * pow(bowl, pw); dh = 2.0 * depth * pw * x * pow(bowl, age); }\n float e = (x - 1.0) / rimWidth;\n float ex = exp(-e * e);\n h += rim * ex;\n dh += -2.0 * rim * e * ex / rimWidth;\n if (x > 1.0) { float t = 1.0 / x; h += 0.25 * rim * t * t * t; dh += -0.75 * rim * t * t * t * t; }\n float k = r > 1e-6 ? dh / (radius * r) : 0.0;\n sum += fade * vec3(h, k * d.x, k * d.y);\n }\n }\n }\n return sum * keepMask(p);\n}\n\nfloat vnoise(vec2 p) {\n vec2 i = floor(p);\n vec2 f = p - i;\n vec2 w = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);\n uvec2 c = uvec2(ivec2(i));\n float a = u24(pcg2d(c).x);\n float b = u24(pcg2d(c + uvec2(1u, 0u)).x);\n float cc = u24(pcg2d(c + uvec2(0u, 1u)).x);\n float d = u24(pcg2d(c + uvec2(1u, 1u)).x);\n return mix(mix(a, b, w.x), mix(cc, d, w.x), w.y);\n}\n\n// a fine roughness of the dust: two scales, as a slope (east, north), faded out where a pixel covers more than a few of its grains\nvec2 roughness(vec2 p, float footprint) {\n vec2 g = vec2(0.0);\n for (int k = 0; k < 2; k += 1) {\n float s = k == 0 ? 0.07 : 0.3;\n float amp = k == 0 ? 0.3 : 0.28;\n float fade = smoothstep(footprint * 2.0, footprint * 7.0, s);\n if (fade <= 0.0) continue;\n float d = s * 0.25;\n vec2 q = (k == 0 ? vec2(p.x * 0.629 + p.y * 0.777, p.y * 0.629 - p.x * 0.777) : vec2(p.x * 0.857 - p.y * 0.515, p.x * 0.515 + p.y * 0.857)) / s;\n float dx = vnoise(q + vec2(0.25, 0.0)) - vnoise(q - vec2(0.25, 0.0));\n float dy = vnoise(q + vec2(0.0, 0.25)) - vnoise(q - vec2(0.0, 0.25));\n g += fade * amp * vec2(dx, dy) / (0.5 * s) * 0.012;\n }\n return g;\n}\n\n\n// the ground's height at a point: the measured heights and, near the eyes, the made craters (kept to the ones a pixel here can show)\nfloat groundY(vec2 p, float dist, bool fine, float fromD) {\n float y = terrainY(p, dist, fine);\n if (uDetail > 0.5 && fromD < 24.0) y += madeGround(p, fromD).x;\n return y;\n}\n\n// 1 where the Sun reaches a point, 0 where the ground is in its way. The measured ground's shadow is read from the baked horizon; the march toward the Sun over the heights (and the made craters) is the near\n// field's only, a few tens of metres with a fixed number of steps, as sharp as the Sun's edge. Where there is no baked horizon the march goes all the way, as it did before the maps.\nfloat lit(vec3 P, float dist0) {\n vec2 dir = normalize(uSun.xz);\n float slope = uSun.y / max(length(uSun.xz), 1e-4);\n if (uHzOn > 0.5 && horizonAt(P.xz) - 0.3 > uSunDegrees) return 0.0;\n // the ground at the point from the heights themselves, not the mesh's slope between its corners, which can be a long way off on a far mountain\n // the made craters are in the ground at the point only where they are in the march too (uNear.z is 0 in the quality of motion, which leaves them out of the march): a point set down in a made crater's floor and a ray over the ground without the crater put the whole floor under the ground's height, black\n P.y = groundY(P.xz, dist0, true, uNear.z > 0.0 ? 2.5 * dist0 * uPixel : 99.0);\n float t = 0.5 * spacing(P.xz, dist0) + 0.25;\n if (uDetail > 0.5) t = min(t, 0.2 + 0.02 * dist0);\n // a pixel's own start along the ray: the edge of a rim's shadow is a line of steps, and a line of steps is jagged; with a start of its own each pixel it becomes a fine grain instead\n float jitter = fract(sin(dot(P.xz, vec2(12.9898, 78.233))) * 43758.5453);\n float range = uHzOn > 0.5 ? uNear.y : 80000.0;\n for (int i = 0; i < 260; i += 1) {\n if (float(i) >= uNear.x) break;\n vec2 q = P.xz + dir * t;\n float y = P.y + slope * t;\n float dist = max(t, distance(q, uEyeEN));\n float res = spacing(q, dist);\n float h = groundY(q, dist, t < 600.0, t < uNear.z ? max(0.2 * t, 2.5 * dist * uPixel) : 99.0);\n float bias = (t < 40.0 ? 0.01 : 0.3 * res) + 0.002 * t;\n if (h > y + bias) return 0.0;\n if (y > uMaxY || t > range) break;\n float step = t < 30.0 ? t * 0.045 + 0.04 : t * 0.06 + 0.5;\n t += step * (0.65 + 0.7 * jitter);\n }\n return 1.0;\n}\n\nvarying vec3 vP;\n\nvoid main() {\n float dist = distance(vP.xz, uEyeEN);\n float fromD = 2.5 * dist * uPixel;\n float e = max(spacing(vP.xz, dist), dist * 0.001);\n float hE = terrainY(vP.xz + vec2(e, 0.0), dist, true);\n float hW = terrainY(vP.xz - vec2(e, 0.0), dist, true);\n float hN = terrainY(vP.xz + vec2(0.0, e), dist, true);\n float hS = terrainY(vP.xz - vec2(0.0, e), dist, true);\n vec2 slope = vec2((hE - hW) / (2.0 * e), (hN - hS) / (2.0 * e));\n if (uDetail > 0.5) {\n if (fromD < 24.0) slope += madeGround(vP.xz, fromD).yz;\n slope += roughness(vP.xz, dist * uPixel);\n }\n vec3 n = normalize(vec3(-slope.x, 1.0, -slope.y));\n float mu0 = dot(n, uSun);\n float mu = max(dot(n, normalize(uEye - vP)), 0.03);\n float shine = 0.0;\n if (mu0 > 0.0 && uSun.y > -0.01) shine = (uShadows > 0.5 ? lit(vP, dist) : 1.0) * 2.0 * mu0 / (mu0 + mu);\n float light = uAlbedo * albedoAt(vP.xz, dist) * (shine + uEarthshine * max(n.y, 0.0)) * uExposure;\n gl_FragColor = vec4(pow(clamp(vec3(light) * uTint, 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);\n}\n";
11
11
  /** The rocks: pieces of ground standing on it. Their corners come from the page already in the site's plane (east, up, north). */
12
12
  export declare const ROCK_VERTEX = "\nprecision highp float;\n// position, normal and uv are declared by three.js\nattribute float tone;\nuniform mat4 uVP;\nvarying vec3 vP;\nvarying vec3 vN;\nvarying float vTone;\nvoid main() {\n vP = position;\n vN = normal;\n vTone = tone;\n gl_Position = uVP * vec4(position.x, position.y, -position.z, 1.0);\n}\n";
13
- export declare const ROCK_FRAGMENT = "\nprecision highp float;\nprecision highp sampler2D;\n\nuniform vec3 uSun;\nuniform vec3 uEye;\nuniform vec2 uEyeEN;\nuniform float uExposure;\nuniform float uAlbedo;\nuniform float uMaxY; // the highest ground over the site's, for the end of a shadow's march\nuniform float uEarthshine; // the light of the sunlit ground round the shade, a small share of a lit slope's (on Mars the sky's light, a good deal more)\nuniform vec3 uTint; // the ground's colour over its grey: white on the Moon\nuniform float uShadows; // 1 for the ground to shadow itself (the default), 0 for none (a try-out)\nuniform float uSunDegrees; // the Sun's elevation in degrees\nuniform vec3 uNear; // the near march: steps, the distance it reaches in metres, the distance out to which the made craters are in it (the quality of the draw)\n\nuniform sampler2D uH0;\nuniform sampler2D uH1;\nuniform sampler2D uH2;\nuniform sampler2D uH3;\nuniform sampler2D uA0; // the ground picture on the first three levels, 0 to 1 with the middle at 0.5\nuniform sampler2D uA1;\nuniform sampler2D uA2;\nuniform float uPicture; // 1 where the picture is there\nuniform vec4 uL0; // half width, metres a sample, samples across, the distance out to which this level is used\nuniform vec4 uL1;\nuniform vec4 uL2;\nuniform vec4 uL3;\nuniform float uHmin;\nuniform float uHrange;\nuniform float uGround;\nuniform float uRadius;\n\nuniform vec2 uFarHeight; // the range the coarse level is encoded over: its minimum and its span\nfloat dec(vec4 t, vec2 hr) { return hr.x + (t.r * 255.0 * 256.0 + t.g * 255.0) / 65535.0 * hr.y; }\n\nfloat lin(sampler2D s, vec2 p, vec4 l, vec2 hr) {\n vec2 f = vec2((p.x + l.x) / l.y - 0.5, (l.x - p.y) / l.y - 0.5);\n vec2 i = floor(f);\n vec2 t = f - i;\n float st = 1.0 / l.z;\n vec2 uv = (i + 0.5) * st;\n float a = dec(texture2D(s, uv), hr);\n float b = dec(texture2D(s, uv + vec2(st, 0.0)), hr);\n float c = dec(texture2D(s, uv + vec2(0.0, st)), hr);\n float d = dec(texture2D(s, uv + vec2(st, st)), hr);\n return mix(mix(a, b, t.x), mix(c, d, t.x), t.y);\n}\n\nfloat nearest(sampler2D s, vec2 p, vec4 l, vec2 hr) {\n vec2 uv = vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z));\n return dec(texture2D(s, uv), hr);\n}\n\nbool holds(vec2 p, vec4 l, float dist) { return dist < l.w && abs(p.x) < l.x - 2.0 * l.y && abs(p.y) < l.x - 2.0 * l.y; }\n\n// the ground's height over the site's, the sphere's fall taken off; `fine` reads four samples, otherwise one\nfloat terrainY(vec2 p, float dist, bool fine) {\n float h;\n if (holds(p, uL0, dist)) h = fine ? lin(uH0, p, uL0, vec2(uHmin, uHrange)) : nearest(uH0, p, uL0, vec2(uHmin, uHrange));\n else if (holds(p, uL1, dist)) h = fine ? lin(uH1, p, uL1, vec2(uHmin, uHrange)) : nearest(uH1, p, uL1, vec2(uHmin, uHrange));\n else if (holds(p, uL2, dist)) h = fine ? lin(uH2, p, uL2, vec2(uHmin, uHrange)) : nearest(uH2, p, uL2, vec2(uHmin, uHrange));\n else h = fine ? lin(uH3, p, uL3, uFarHeight) : nearest(uH3, p, uL3, uFarHeight);\n return h - uGround - dot(p, p) / (2.0 * uRadius);\n}\n\n// the ground's own brightness at a point, from the picture of the level that serves it, 1 where it is the middle\nfloat albedoAt(vec2 p, float dist) {\n if (uPicture < 0.5) return 1.0;\n vec4 l;\n if (holds(p, uL0, dist)) { l = uL0; return 2.0 * texture2D(uA0, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n if (holds(p, uL1, dist)) { l = uL1; return 2.0 * texture2D(uA1, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n if (holds(p, uL2, dist)) { l = uL2; return 2.0 * texture2D(uA2, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n return 1.0;\n}\n\n// the measured ground's shadows, baked (scripts/make-moon-terrain.py): for a point, the elevation angle in degrees of the horizon toward the Sun, read from the finest of the three horizon maps that holds the point\nuniform sampler2D uZ0;\nuniform sampler2D uZ1;\nuniform sampler2D uZ2;\nuniform float uHzOn; // 1 where the maps are there\nuniform vec3 uHzSun; // the two directions (of 18) the Sun's azimuth lies between, and the share of the second\nuniform vec2 uHzRange; // the degrees the codes 0 and 255 stand for\n\nfloat hzSector(sampler2D s, vec2 cell, float k) {\n float slab = floor(k / 3.0);\n float ch = k - slab * 3.0;\n vec3 v = texture2D(s, vec2((cell.x + slab) / 6.0, cell.y)).rgb;\n return ch < 0.5 ? v.r : (ch < 1.5 ? v.g : v.b);\n}\n\nfloat hzFrom(sampler2D s, vec2 p, float reach) {\n vec2 cell = clamp(vec2((p.x + reach) / (2.0 * reach), (reach - p.y) / (2.0 * reach)), vec2(0.5 / 512.0), vec2(1.0 - 0.5 / 512.0));\n float code = mix(hzSector(s, cell, uHzSun.x), hzSector(s, cell, uHzSun.y), uHzSun.z);\n return uHzRange.x + code * (uHzRange.y - uHzRange.x);\n}\n\nfloat horizonAt(vec2 p) {\n if (abs(p.x) < uL0.x && abs(p.y) < uL0.x) return hzFrom(uZ0, p, uL0.x);\n if (abs(p.x) < uL1.x && abs(p.y) < uL1.x) return hzFrom(uZ1, p, uL1.x);\n if (abs(p.x) < uL2.x && abs(p.y) < uL2.x) return hzFrom(uZ2, p, uL2.x);\n return -90.0;\n}\n\n// the spacing of the level that serves a point, for the step of a slope\nfloat spacing(vec2 p, float dist) {\n if (holds(p, uL0, dist)) return uL0.y;\n if (holds(p, uL1, dist)) return uL1.y;\n if (holds(p, uL2, dist)) return uL2.y;\n return uL3.y;\n}\n\n\nuniform float uPixel; // the angle one pixel takes, radians\nuniform float uDetail; // 1 for the made detail, 0 for none\n\nuvec2 pcg2d(uvec2 v) {\n v = v * 1664525u + 1013904223u;\n v.x += v.y * 1664525u;\n v.y += v.x * 1664525u;\n v = v ^ (v >> 16u);\n v.x += v.y * 1664525u;\n v.y += v.x * 1664525u;\n v = v ^ (v >> 16u);\n return v;\n}\nfloat u24(uint h) { return float(h >> 8u) * (1.0 / 16777216.0); }\n\nuniform vec4 uKeep[6]; // the objects the made ground keeps away from: east, north, the distance inside which nothing is made, the distance outside which it all is\nuniform float uKeepCount;\nfloat keepMask(vec2 p) {\n float keep = 1.0;\n for (int i = 0; i < 6; i += 1) {\n if (float(i) >= uKeepCount) break;\n vec4 k = uKeep[i];\n float t = clamp((distance(p, k.xy) - k.z) / (k.w - k.z), 0.0, 1.0);\n keep = min(keep, t * t * (3.0 - 2.0 * t));\n }\n return keep;\n}\n\n// the made ground at a point: x the height in metres, yz the slope east and north, from every crater of every octave whose nominal diameter is over `fromD`\nvec3 madeGround(vec2 p, float fromD) {\n vec3 sum = vec3(0.0);\n for (int octave = 5; octave >= 0; octave -= 1) {\n float nominal = 0.5 * exp2(float(octave));\n float fade = clamp(nominal / fromD - 1.0, 0.0, 1.0);\n if (fade <= 0.0) break;\n float cell = 3.0 * nominal;\n ivec2 base = ivec2(floor(p / cell));\n vec2 fr = p / cell - vec2(base);\n float occ = (octave >= 3 ? 0.5 : 1.0) * 0.36 * exp2(-0.5 * float(octave));\n for (int j = -1; j <= 1; j += 1) {\n for (int i = -1; i <= 1; i += 1) {\n // a crater is kept to the middle of its cell, so a neighbour's reaches this cell only within a fifth of the edge\n if ((i == -1 && fr.x > 0.2) || (i == 1 && fr.x < 0.8) || (j == -1 && fr.y > 0.2) || (j == 1 && fr.y < 0.8)) continue;\n ivec2 c = base + ivec2(i, j);\n uvec2 ab = pcg2d(uvec2(uint(c.x), uint(c.y + octave * 7919)));\n if (u24(ab.x) >= occ) continue;\n uvec2 cd = pcg2d(uvec2(uint(c.x + 104729), uint(c.y + octave * 7919 + 15485863)));\n float diameter = nominal * (1.0 + (octave == 5 ? 0.25 : 1.0) * u24(cd.y));\n float r4 = float(ab.x & 255u) / 255.0;\n float age = 1.0 - r4 * r4 * r4 * r4;\n float radius = 0.5 * diameter;\n float vary = 0.6 + 0.4 * (float(cd.x & 255u) / 255.0);\n float depth = diameter * (0.2 - 0.17 * age) * vary;\n float rim = 0.045 * diameter * pow(1.0 - age, 1.5);\n float rimWidth = 0.22 + 0.5 * age;\n vec2 centre = vec2(float(c.x) + 0.25 + 0.5 * u24(ab.y), float(c.y) + 0.25 + 0.5 * u24(cd.x)) * cell;\n vec2 d = p - centre;\n float r = length(d);\n float x = r / radius;\n float h = 0.0;\n float dh = 0.0;\n if (x < 1.0) { float bowl = 1.0 - x * x; float pw = 1.0 + age; h = -depth * pow(bowl, pw); dh = 2.0 * depth * pw * x * pow(bowl, age); }\n float e = (x - 1.0) / rimWidth;\n float ex = exp(-e * e);\n h += rim * ex;\n dh += -2.0 * rim * e * ex / rimWidth;\n if (x > 1.0) { float t = 1.0 / x; h += 0.25 * rim * t * t * t; dh += -0.75 * rim * t * t * t * t; }\n float k = r > 1e-6 ? dh / (radius * r) : 0.0;\n sum += fade * vec3(h, k * d.x, k * d.y);\n }\n }\n }\n return sum * keepMask(p);\n}\n\nfloat vnoise(vec2 p) {\n vec2 i = floor(p);\n vec2 f = p - i;\n vec2 w = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);\n uvec2 c = uvec2(ivec2(i));\n float a = u24(pcg2d(c).x);\n float b = u24(pcg2d(c + uvec2(1u, 0u)).x);\n float cc = u24(pcg2d(c + uvec2(0u, 1u)).x);\n float d = u24(pcg2d(c + uvec2(1u, 1u)).x);\n return mix(mix(a, b, w.x), mix(cc, d, w.x), w.y);\n}\n\n// a fine roughness of the dust: two scales, as a slope (east, north), faded out where a pixel covers more than a few of its grains\nvec2 roughness(vec2 p, float footprint) {\n vec2 g = vec2(0.0);\n for (int k = 0; k < 2; k += 1) {\n float s = k == 0 ? 0.07 : 0.3;\n float amp = k == 0 ? 0.3 : 0.28;\n float fade = smoothstep(footprint * 2.0, footprint * 7.0, s);\n if (fade <= 0.0) continue;\n float d = s * 0.25;\n vec2 q = (k == 0 ? vec2(p.x * 0.629 + p.y * 0.777, p.y * 0.629 - p.x * 0.777) : vec2(p.x * 0.857 - p.y * 0.515, p.x * 0.515 + p.y * 0.857)) / s;\n float dx = vnoise(q + vec2(0.25, 0.0)) - vnoise(q - vec2(0.25, 0.0));\n float dy = vnoise(q + vec2(0.0, 0.25)) - vnoise(q - vec2(0.0, 0.25));\n g += fade * amp * vec2(dx, dy) / (0.5 * s) * 0.012;\n }\n return g;\n}\n\n\n// the ground's height at a point: the measured heights and, near the eyes, the made craters (kept to the ones a pixel here can show)\nfloat groundY(vec2 p, float dist, bool fine, float fromD) {\n float y = terrainY(p, dist, fine);\n if (uDetail > 0.5 && fromD < 24.0) y += madeGround(p, fromD).x;\n return y;\n}\n\n// 1 where the Sun reaches a point, 0 where the ground is in its way. The measured ground's shadow is read from the baked horizon; the march toward the Sun over the heights (and the made craters) is the near\n// field's only, a few tens of metres with a fixed number of steps, as sharp as the Sun's edge. Where there is no baked horizon the march goes all the way, as it did before the maps.\nfloat lit(vec3 P, float dist0) {\n vec2 dir = normalize(uSun.xz);\n float slope = uSun.y / max(length(uSun.xz), 1e-4);\n if (uHzOn > 0.5 && horizonAt(P.xz) - 0.3 > uSunDegrees) return 0.0;\n // the ground at the point from the heights themselves, not the mesh's slope between its corners, which can be a long way off on a far mountain\n P.y = groundY(P.xz, dist0, true, 2.5 * dist0 * uPixel);\n float t = 0.5 * spacing(P.xz, dist0) + 0.25;\n if (uDetail > 0.5) t = min(t, 0.2 + 0.02 * dist0);\n // a pixel's own start along the ray: the edge of a rim's shadow is a line of steps, and a line of steps is jagged; with a start of its own each pixel it becomes a fine grain instead\n float jitter = fract(sin(dot(P.xz, vec2(12.9898, 78.233))) * 43758.5453);\n float range = uHzOn > 0.5 ? uNear.y : 80000.0;\n for (int i = 0; i < 260; i += 1) {\n if (float(i) >= uNear.x) break;\n vec2 q = P.xz + dir * t;\n float y = P.y + slope * t;\n float dist = max(t, distance(q, uEyeEN));\n float res = spacing(q, dist);\n float h = groundY(q, dist, t < 600.0, t < uNear.z ? max(0.2 * t, 2.5 * dist * uPixel) : 99.0);\n float bias = (t < 40.0 ? 0.01 : 0.3 * res) + 0.002 * t;\n if (h > y + bias) return 0.0;\n if (y > uMaxY || t > range) break;\n float step = t < 30.0 ? t * 0.045 + 0.04 : t * 0.06 + 0.5;\n t += step * (0.65 + 0.7 * jitter);\n }\n return 1.0;\n}\n\nvarying vec3 vP;\nvarying vec3 vN;\nvarying float vTone;\nvoid main() {\n vec3 n = normalize(vN);\n float mu0 = dot(n, uSun);\n float mu = max(dot(n, normalize(uEye - vP)), 0.03);\n float dist = distance(vP.xz, uEyeEN);\n float shine = 0.0;\n if (mu0 > 0.0 && uSun.y > -0.01) shine = (uShadows > 0.5 ? lit(vP + n * 0.02, dist) : 1.0) * 2.0 * mu0 / (mu0 + mu);\n float light = uAlbedo * 1.1 * vTone * (shine + 0.12 * (n.y * 0.5 + 0.5)) * uExposure; // the shade of a stone is lit by the ground round it\n gl_FragColor = vec4(vec3(pow(clamp(light, 0.0, 1.0), 1.0 / 2.2)), 1.0);\n}\n";
13
+ export declare const ROCK_FRAGMENT = "\nprecision highp float;\nprecision highp sampler2D;\n\nuniform vec3 uSun;\nuniform vec3 uEye;\nuniform vec2 uEyeEN;\nuniform float uExposure;\nuniform float uAlbedo;\nuniform float uMaxY; // the highest ground over the site's, for the end of a shadow's march\nuniform float uEarthshine; // the light of the sunlit ground round the shade, a small share of a lit slope's (on Mars the sky's light, a good deal more)\nuniform vec3 uTint; // the ground's colour over its grey: white on the Moon\nuniform float uShadows; // 1 for the ground to shadow itself (the default), 0 for none (a try-out)\nuniform float uSunDegrees; // the Sun's elevation in degrees\nuniform vec3 uNear; // the near march: steps, the distance it reaches in metres, the distance out to which the made craters are in it (the quality of the draw)\n\nuniform sampler2D uH0;\nuniform sampler2D uH1;\nuniform sampler2D uH2;\nuniform sampler2D uH3;\nuniform sampler2D uA0; // the ground picture on the first three levels, 0 to 1 with the middle at 0.5\nuniform sampler2D uA1;\nuniform sampler2D uA2;\nuniform float uPicture; // 1 where the picture is there\nuniform vec4 uL0; // half width, metres a sample, samples across, the distance out to which this level is used\nuniform vec4 uL1;\nuniform vec4 uL2;\nuniform vec4 uL3;\nuniform float uHmin;\nuniform float uHrange;\nuniform float uGround;\nuniform float uRadius;\n\nuniform vec2 uFarHeight; // the range the coarse level is encoded over: its minimum and its span\nfloat dec(vec4 t, vec2 hr) { return hr.x + (t.r * 255.0 * 256.0 + t.g * 255.0) / 65535.0 * hr.y; }\n\nfloat lin(sampler2D s, vec2 p, vec4 l, vec2 hr) {\n vec2 f = vec2((p.x + l.x) / l.y - 0.5, (l.x - p.y) / l.y - 0.5);\n vec2 i = floor(f);\n vec2 t = f - i;\n float st = 1.0 / l.z;\n vec2 uv = (i + 0.5) * st;\n float a = dec(texture2D(s, uv), hr);\n float b = dec(texture2D(s, uv + vec2(st, 0.0)), hr);\n float c = dec(texture2D(s, uv + vec2(0.0, st)), hr);\n float d = dec(texture2D(s, uv + vec2(st, st)), hr);\n return mix(mix(a, b, t.x), mix(c, d, t.x), t.y);\n}\n\nfloat nearest(sampler2D s, vec2 p, vec4 l, vec2 hr) {\n vec2 uv = vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z));\n return dec(texture2D(s, uv), hr);\n}\n\nbool holds(vec2 p, vec4 l, float dist) { return dist < l.w && abs(p.x) < l.x - 2.0 * l.y && abs(p.y) < l.x - 2.0 * l.y; }\n\n// the ground's height over the site's, the sphere's fall taken off; `fine` reads four samples, otherwise one\nfloat terrainY(vec2 p, float dist, bool fine) {\n float h;\n if (holds(p, uL0, dist)) h = fine ? lin(uH0, p, uL0, vec2(uHmin, uHrange)) : nearest(uH0, p, uL0, vec2(uHmin, uHrange));\n else if (holds(p, uL1, dist)) h = fine ? lin(uH1, p, uL1, vec2(uHmin, uHrange)) : nearest(uH1, p, uL1, vec2(uHmin, uHrange));\n else if (holds(p, uL2, dist)) h = fine ? lin(uH2, p, uL2, vec2(uHmin, uHrange)) : nearest(uH2, p, uL2, vec2(uHmin, uHrange));\n else h = fine ? lin(uH3, p, uL3, uFarHeight) : nearest(uH3, p, uL3, uFarHeight);\n return h - uGround - dot(p, p) / (2.0 * uRadius);\n}\n\n// the ground's own brightness at a point, from the picture of the level that serves it, 1 where it is the middle\nfloat albedoAt(vec2 p, float dist) {\n if (uPicture < 0.5) return 1.0;\n vec4 l;\n if (holds(p, uL0, dist)) { l = uL0; return 2.0 * texture2D(uA0, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n if (holds(p, uL1, dist)) { l = uL1; return 2.0 * texture2D(uA1, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n if (holds(p, uL2, dist)) { l = uL2; return 2.0 * texture2D(uA2, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n return 1.0;\n}\n\n// the measured ground's shadows, baked (scripts/make-moon-terrain.py): for a point, the elevation angle in degrees of the horizon toward the Sun, read from the finest of the three horizon maps that holds the point\nuniform sampler2D uZ0;\nuniform sampler2D uZ1;\nuniform sampler2D uZ2;\nuniform float uHzOn; // 1 where the maps are there\nuniform vec3 uHzSun; // the two directions (of 18) the Sun's azimuth lies between, and the share of the second\nuniform vec2 uHzRange; // the degrees the codes 0 and 255 stand for\n\nfloat hzSector(sampler2D s, vec2 cell, float k) {\n float slab = floor(k / 3.0);\n float ch = k - slab * 3.0;\n vec3 v = texture2D(s, vec2((cell.x + slab) / 6.0, cell.y)).rgb;\n return ch < 0.5 ? v.r : (ch < 1.5 ? v.g : v.b);\n}\n\nfloat hzFrom(sampler2D s, vec2 p, float reach) {\n vec2 cell = clamp(vec2((p.x + reach) / (2.0 * reach), (reach - p.y) / (2.0 * reach)), vec2(0.5 / 512.0), vec2(1.0 - 0.5 / 512.0));\n float code = mix(hzSector(s, cell, uHzSun.x), hzSector(s, cell, uHzSun.y), uHzSun.z);\n return uHzRange.x + code * (uHzRange.y - uHzRange.x);\n}\n\nfloat horizonAt(vec2 p) {\n if (abs(p.x) < uL0.x && abs(p.y) < uL0.x) return hzFrom(uZ0, p, uL0.x);\n if (abs(p.x) < uL1.x && abs(p.y) < uL1.x) return hzFrom(uZ1, p, uL1.x);\n if (abs(p.x) < uL2.x && abs(p.y) < uL2.x) return hzFrom(uZ2, p, uL2.x);\n return -90.0;\n}\n\n// the spacing of the level that serves a point, for the step of a slope\nfloat spacing(vec2 p, float dist) {\n if (holds(p, uL0, dist)) return uL0.y;\n if (holds(p, uL1, dist)) return uL1.y;\n if (holds(p, uL2, dist)) return uL2.y;\n return uL3.y;\n}\n\n\nuniform float uPixel; // the angle one pixel takes, radians\nuniform float uDetail; // 1 for the made detail, 0 for none\n\nuvec2 pcg2d(uvec2 v) {\n v = v * 1664525u + 1013904223u;\n v.x += v.y * 1664525u;\n v.y += v.x * 1664525u;\n v = v ^ (v >> 16u);\n v.x += v.y * 1664525u;\n v.y += v.x * 1664525u;\n v = v ^ (v >> 16u);\n return v;\n}\nfloat u24(uint h) { return float(h >> 8u) * (1.0 / 16777216.0); }\n\nuniform vec4 uKeep[6]; // the objects the made ground keeps away from: east, north, the distance inside which nothing is made, the distance outside which it all is\nuniform float uKeepCount;\nfloat keepMask(vec2 p) {\n float keep = 1.0;\n for (int i = 0; i < 6; i += 1) {\n if (float(i) >= uKeepCount) break;\n vec4 k = uKeep[i];\n float t = clamp((distance(p, k.xy) - k.z) / (k.w - k.z), 0.0, 1.0);\n keep = min(keep, t * t * (3.0 - 2.0 * t));\n }\n return keep;\n}\n\n// the made ground at a point: x the height in metres, yz the slope east and north, from every crater of every octave whose nominal diameter is over `fromD`\nvec3 madeGround(vec2 p, float fromD) {\n vec3 sum = vec3(0.0);\n for (int octave = 5; octave >= 0; octave -= 1) {\n float nominal = 0.5 * exp2(float(octave));\n float fade = clamp(nominal / fromD - 1.0, 0.0, 1.0);\n if (fade <= 0.0) break;\n float cell = 3.0 * nominal;\n ivec2 base = ivec2(floor(p / cell));\n vec2 fr = p / cell - vec2(base);\n float occ = (octave >= 3 ? 0.5 : 1.0) * 0.36 * exp2(-0.5 * float(octave));\n for (int j = -1; j <= 1; j += 1) {\n for (int i = -1; i <= 1; i += 1) {\n // a crater is kept to the middle of its cell, so a neighbour's reaches this cell only within a fifth of the edge\n if ((i == -1 && fr.x > 0.2) || (i == 1 && fr.x < 0.8) || (j == -1 && fr.y > 0.2) || (j == 1 && fr.y < 0.8)) continue;\n ivec2 c = base + ivec2(i, j);\n uvec2 ab = pcg2d(uvec2(uint(c.x), uint(c.y + octave * 7919)));\n if (u24(ab.x) >= occ) continue;\n uvec2 cd = pcg2d(uvec2(uint(c.x + 104729), uint(c.y + octave * 7919 + 15485863)));\n float diameter = nominal * (1.0 + (octave == 5 ? 0.25 : 1.0) * u24(cd.y));\n float r4 = float(ab.x & 255u) / 255.0;\n float age = 1.0 - r4 * r4 * r4 * r4;\n float radius = 0.5 * diameter;\n float vary = 0.6 + 0.4 * (float(cd.x & 255u) / 255.0);\n float depth = diameter * (0.2 - 0.17 * age) * vary;\n float rim = 0.045 * diameter * pow(1.0 - age, 1.5);\n float rimWidth = 0.22 + 0.5 * age;\n vec2 centre = vec2(float(c.x) + 0.25 + 0.5 * u24(ab.y), float(c.y) + 0.25 + 0.5 * u24(cd.x)) * cell;\n vec2 d = p - centre;\n float r = length(d);\n float x = r / radius;\n float h = 0.0;\n float dh = 0.0;\n if (x < 1.0) { float bowl = 1.0 - x * x; float pw = 1.0 + age; h = -depth * pow(bowl, pw); dh = 2.0 * depth * pw * x * pow(bowl, age); }\n float e = (x - 1.0) / rimWidth;\n float ex = exp(-e * e);\n h += rim * ex;\n dh += -2.0 * rim * e * ex / rimWidth;\n if (x > 1.0) { float t = 1.0 / x; h += 0.25 * rim * t * t * t; dh += -0.75 * rim * t * t * t * t; }\n float k = r > 1e-6 ? dh / (radius * r) : 0.0;\n sum += fade * vec3(h, k * d.x, k * d.y);\n }\n }\n }\n return sum * keepMask(p);\n}\n\nfloat vnoise(vec2 p) {\n vec2 i = floor(p);\n vec2 f = p - i;\n vec2 w = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);\n uvec2 c = uvec2(ivec2(i));\n float a = u24(pcg2d(c).x);\n float b = u24(pcg2d(c + uvec2(1u, 0u)).x);\n float cc = u24(pcg2d(c + uvec2(0u, 1u)).x);\n float d = u24(pcg2d(c + uvec2(1u, 1u)).x);\n return mix(mix(a, b, w.x), mix(cc, d, w.x), w.y);\n}\n\n// a fine roughness of the dust: two scales, as a slope (east, north), faded out where a pixel covers more than a few of its grains\nvec2 roughness(vec2 p, float footprint) {\n vec2 g = vec2(0.0);\n for (int k = 0; k < 2; k += 1) {\n float s = k == 0 ? 0.07 : 0.3;\n float amp = k == 0 ? 0.3 : 0.28;\n float fade = smoothstep(footprint * 2.0, footprint * 7.0, s);\n if (fade <= 0.0) continue;\n float d = s * 0.25;\n vec2 q = (k == 0 ? vec2(p.x * 0.629 + p.y * 0.777, p.y * 0.629 - p.x * 0.777) : vec2(p.x * 0.857 - p.y * 0.515, p.x * 0.515 + p.y * 0.857)) / s;\n float dx = vnoise(q + vec2(0.25, 0.0)) - vnoise(q - vec2(0.25, 0.0));\n float dy = vnoise(q + vec2(0.0, 0.25)) - vnoise(q - vec2(0.0, 0.25));\n g += fade * amp * vec2(dx, dy) / (0.5 * s) * 0.012;\n }\n return g;\n}\n\n\n// the ground's height at a point: the measured heights and, near the eyes, the made craters (kept to the ones a pixel here can show)\nfloat groundY(vec2 p, float dist, bool fine, float fromD) {\n float y = terrainY(p, dist, fine);\n if (uDetail > 0.5 && fromD < 24.0) y += madeGround(p, fromD).x;\n return y;\n}\n\n// 1 where the Sun reaches a point, 0 where the ground is in its way. The measured ground's shadow is read from the baked horizon; the march toward the Sun over the heights (and the made craters) is the near\n// field's only, a few tens of metres with a fixed number of steps, as sharp as the Sun's edge. Where there is no baked horizon the march goes all the way, as it did before the maps.\nfloat lit(vec3 P, float dist0) {\n vec2 dir = normalize(uSun.xz);\n float slope = uSun.y / max(length(uSun.xz), 1e-4);\n if (uHzOn > 0.5 && horizonAt(P.xz) - 0.3 > uSunDegrees) return 0.0;\n // the ground at the point from the heights themselves, not the mesh's slope between its corners, which can be a long way off on a far mountain\n // the made craters are in the ground at the point only where they are in the march too (uNear.z is 0 in the quality of motion, which leaves them out of the march): a point set down in a made crater's floor and a ray over the ground without the crater put the whole floor under the ground's height, black\n P.y = groundY(P.xz, dist0, true, uNear.z > 0.0 ? 2.5 * dist0 * uPixel : 99.0);\n float t = 0.5 * spacing(P.xz, dist0) + 0.25;\n if (uDetail > 0.5) t = min(t, 0.2 + 0.02 * dist0);\n // a pixel's own start along the ray: the edge of a rim's shadow is a line of steps, and a line of steps is jagged; with a start of its own each pixel it becomes a fine grain instead\n float jitter = fract(sin(dot(P.xz, vec2(12.9898, 78.233))) * 43758.5453);\n float range = uHzOn > 0.5 ? uNear.y : 80000.0;\n for (int i = 0; i < 260; i += 1) {\n if (float(i) >= uNear.x) break;\n vec2 q = P.xz + dir * t;\n float y = P.y + slope * t;\n float dist = max(t, distance(q, uEyeEN));\n float res = spacing(q, dist);\n float h = groundY(q, dist, t < 600.0, t < uNear.z ? max(0.2 * t, 2.5 * dist * uPixel) : 99.0);\n float bias = (t < 40.0 ? 0.01 : 0.3 * res) + 0.002 * t;\n if (h > y + bias) return 0.0;\n if (y > uMaxY || t > range) break;\n float step = t < 30.0 ? t * 0.045 + 0.04 : t * 0.06 + 0.5;\n t += step * (0.65 + 0.7 * jitter);\n }\n return 1.0;\n}\n\nvarying vec3 vP;\nvarying vec3 vN;\nvarying float vTone;\nvoid main() {\n vec3 n = normalize(vN);\n float mu0 = dot(n, uSun);\n float mu = max(dot(n, normalize(uEye - vP)), 0.03);\n float dist = distance(vP.xz, uEyeEN);\n float shine = 0.0;\n if (mu0 > 0.0 && uSun.y > -0.01) shine = (uShadows > 0.5 ? lit(vP + n * 0.02, dist) : 1.0) * 2.0 * mu0 / (mu0 + mu);\n float light = uAlbedo * 1.1 * vTone * (shine + 0.12 * (n.y * 0.5 + 0.5)) * uExposure; // the shade of a stone is lit by the ground round it\n gl_FragColor = vec4(vec3(pow(clamp(light, 0.0, 1.0), 1.0 / 2.2)), 1.0);\n}\n";
14
14
  /** A rock's shadow on the ground: a quad laid along the way the Sun's light goes, a soft dark shape, drawn over the ground. */
15
15
  export declare const SHADOW_VERTEX = "\nprecision highp float;\nuniform mat4 uVP;\nvarying vec2 vUv;\nvoid main() {\n vUv = uv;\n gl_Position = uVP * vec4(position.x, position.y, -position.z, 1.0);\n}\n";
16
16
  export declare const SHADOW_FRAGMENT = "\nprecision highp float;\nvarying vec2 vUv;\nvoid main() {\n float u = vUv.x;\n float across = smoothstep(1.0, 0.5, abs(vUv.y));\n float along = smoothstep(0.0, 0.06, u) * (1.0 - smoothstep(0.78, 1.0, u));\n float a = across * along * 0.85;\n if (a < 0.01) discard;\n gl_FragColor = vec4(0.0, 0.0, 0.0, a);\n}\n";
@@ -262,7 +262,8 @@ float lit(vec3 P, float dist0) {
262
262
  float slope = uSun.y / max(length(uSun.xz), 1e-4);
263
263
  if (uHzOn > 0.5 && horizonAt(P.xz) - 0.3 > uSunDegrees) return 0.0;
264
264
  // the ground at the point from the heights themselves, not the mesh's slope between its corners, which can be a long way off on a far mountain
265
- P.y = groundY(P.xz, dist0, true, 2.5 * dist0 * uPixel);
265
+ // the made craters are in the ground at the point only where they are in the march too (uNear.z is 0 in the quality of motion, which leaves them out of the march): a point set down in a made crater's floor and a ray over the ground without the crater put the whole floor under the ground's height, black
266
+ P.y = groundY(P.xz, dist0, true, uNear.z > 0.0 ? 2.5 * dist0 * uPixel : 99.0);
266
267
  float t = 0.5 * spacing(P.xz, dist0) + 0.25;
267
268
  if (uDetail > 0.5) t = min(t, 0.2 + 0.02 * dist0);
268
269
  // a pixel's own start along the ray: the edge of a rim's shadow is a line of steps, and a line of steps is jagged; with a start of its own each pixel it becomes a fine grain instead
@@ -132,3 +132,36 @@ export declare function clockText(t: number): {
132
132
  t: string;
133
133
  get: string;
134
134
  };
135
+ /** How far a drag has turned the watched view from where its camera points by itself, in degrees. */
136
+ export interface WatchTurn {
137
+ azimuth: number;
138
+ pitch: number;
139
+ }
140
+ /** The most a drag may tip the watched view up or down from where its camera points by itself, in degrees (the rover's view has the same limit). */
141
+ export declare const WATCH_PITCH_LIMIT = 60;
142
+ /**
143
+ * A drag turns the watched view (MODULES-1546): the camera follows the descent and points itself at each frame, so a drag cannot set where the view looks (the next frame would put it back); it adds to a turn kept
144
+ * beside it, which every frame adds to where the camera points by itself. Dragging right turns the view right, and dragging down tips it up, as in the standing view.
145
+ *
146
+ * @param turn - The turn so far.
147
+ * @param dx - How far the pointer moved across, in pixels, to the right positive.
148
+ * @param dy - How far it moved down, in pixels, down positive.
149
+ * @param degreesPerPixel - How many degrees a pixel of the drag turns the view (the field of view over the view's height).
150
+ * @returns The turn after the drag, the pitch kept within `WATCH_PITCH_LIMIT`.
151
+ */
152
+ export declare function turnedBy(turn: WatchTurn, dx: number, dy: number, degreesPerPixel: number): WatchTurn;
153
+ /**
154
+ * Where the watched view looks at a frame: where its camera points by itself (towards the descending stage from the ground, along the lunar module's heading and pitch from its window) turned by what the viewer has dragged.
155
+ * Pure, and the same at every frame for the same turn, so the turn survives the frames that follow it.
156
+ *
157
+ * @param camera - Where the camera points by itself: azimuth clockwise from north and pitch up from the horizon, in degrees.
158
+ * @param turn - The viewer's turn.
159
+ * @returns The azimuth from 0 up to 360 and the pitch, before the view's own limits.
160
+ */
161
+ export declare function watchedLook(camera: {
162
+ azimuth: number;
163
+ pitch: number;
164
+ }, turn: WatchTurn): {
165
+ azimuth: number;
166
+ pitch: number;
167
+ };
@@ -235,3 +235,29 @@ export function clockText(t) {
235
235
  const g = 110 * 3600 + 9 * 60 + 53 + s;
236
236
  return { t: `T+${two(s / 60)}:${two(s % 60)}`, get: `${Math.floor(g / 3600)}:${two((g % 3600) / 60)}:${two(g % 60)}` };
237
237
  }
238
+ /** The most a drag may tip the watched view up or down from where its camera points by itself, in degrees (the rover's view has the same limit). */
239
+ export const WATCH_PITCH_LIMIT = 60;
240
+ /**
241
+ * A drag turns the watched view (MODULES-1546): the camera follows the descent and points itself at each frame, so a drag cannot set where the view looks (the next frame would put it back); it adds to a turn kept
242
+ * beside it, which every frame adds to where the camera points by itself. Dragging right turns the view right, and dragging down tips it up, as in the standing view.
243
+ *
244
+ * @param turn - The turn so far.
245
+ * @param dx - How far the pointer moved across, in pixels, to the right positive.
246
+ * @param dy - How far it moved down, in pixels, down positive.
247
+ * @param degreesPerPixel - How many degrees a pixel of the drag turns the view (the field of view over the view's height).
248
+ * @returns The turn after the drag, the pitch kept within `WATCH_PITCH_LIMIT`.
249
+ */
250
+ export function turnedBy(turn, dx, dy, degreesPerPixel) {
251
+ return { azimuth: turn.azimuth - dx * degreesPerPixel, pitch: Math.max(-WATCH_PITCH_LIMIT, Math.min(WATCH_PITCH_LIMIT, turn.pitch + dy * degreesPerPixel)) };
252
+ }
253
+ /**
254
+ * Where the watched view looks at a frame: where its camera points by itself (towards the descending stage from the ground, along the lunar module's heading and pitch from its window) turned by what the viewer has dragged.
255
+ * Pure, and the same at every frame for the same turn, so the turn survives the frames that follow it.
256
+ *
257
+ * @param camera - Where the camera points by itself: azimuth clockwise from north and pitch up from the horizon, in degrees.
258
+ * @param turn - The viewer's turn.
259
+ * @returns The azimuth from 0 up to 360 and the pitch, before the view's own limits.
260
+ */
261
+ export function watchedLook(camera, turn) {
262
+ return { azimuth: (((camera.azimuth + turn.azimuth) % 360) + 360) % 360, pitch: camera.pitch + turn.pitch };
263
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johnmorrisdotca/wakusei-planets",
3
- "version": "0.66.0",
3
+ "version": "0.67.0",
4
4
  "description": "Wakusei Planets 惑星 — The Sun, planets and moons for the web: each as a clean line drawing, a shaded realistic drawing or a painted surface map, with real sizes, axial tilt and rotation as data, and positions of the moons for any date and time. SVG for the lines, three.js (optional) for the rest.",
5
5
  "keywords": [
6
6
  "planets",
@@ -241,6 +241,11 @@
241
241
  "import": "./dist/fact-sheets.js",
242
242
  "default": "./dist/fact-sheets.js"
243
243
  },
244
+ "./body-physics": {
245
+ "types": "./dist/body-physics.d.ts",
246
+ "import": "./dist/body-physics.js",
247
+ "default": "./dist/body-physics.js"
248
+ },
244
249
  "./discovery": {
245
250
  "types": "./dist/discovery.d.ts",
246
251
  "import": "./dist/discovery.js",