@johnmorrisdotca/chikyu-earth 0.27.0 → 0.29.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 +8 -0
- package/README.md +1 -1
- package/dist/realistic/air-note.d.ts +19 -0
- package/dist/realistic/air-note.js +29 -0
- package/dist/realistic/air.d.ts +125 -0
- package/dist/realistic/air.js +239 -0
- package/dist/realistic/earth.d.ts +4 -0
- package/dist/realistic/earth.js +12 -7
- package/dist/realistic/element.d.ts +6 -0
- package/dist/realistic/element.js +26 -3
- package/dist/realistic/index.d.ts +2 -0
- package/dist/realistic/index.js +2 -0
- package/dist/realistic/shaders.d.ts +0 -2
- package/dist/realistic/shaders.js +4 -43
- package/dist/space/element.d.ts +6 -0
- package/dist/space/element.js +26 -3
- package/dist/space/scene.d.ts +4 -0
- package/dist/space/scene.js +13 -10
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.29.0 - 2026-11-11
|
|
6
|
+
|
|
7
|
+
- **The air is drawn 3 times its real thickness unless a page says otherwise, so the ring can be seen** (MODULES-904). At whole-Earth zoom the true 100 km shell is a line a pixel or two wide, and on a phone thinner than the old painted glow. `air-thickness` (and the property `airThickness`) on `<chikyu-earth-realistic>` and `<chikyu-space>` takes a number from 1 (the true thickness) to 5, and 3 when left out; the shell and the heights over which the air thins grow by it and the air is the same amount, so the physics and the colours do not change. While it is above 1 the element says so in a line under the picture, "The air is drawn 3 times its real thickness so it can be seen." (and in Japanese), which `air-label="off"` takes away. New exports `AIR_THICKNESS_DEFAULT`, `AIR_THICKNESS_MAX`, `readAirThickness`, `airTop` and `AIR_NOTE`. The demo has a True air thickness button on the realistic and space looks and on the full-screen page (`air-thickness=1` in the address). The cost is the same: a draw is the same program with one more uniform. Tests: `test/air.test.ts`, `e2e/air-visible.gl.ts`.
|
|
8
|
+
|
|
9
|
+
## 0.28.0 - 2026-11-11
|
|
10
|
+
|
|
11
|
+
- **The air is light scattered once, worked out in the shader** (MODULES-843). The realistic Earth and the space view draw the atmosphere as a shell 100 km thick (0.0157 of the Earth's radius), sampled along each ray toward the camera and toward the Sun in the fragment shader, with the samples packed where the air is thick: Rayleigh scattering (a blue haze that thickens toward the limb on the day side), Mie scattering (a glow toward the Sun), the reddening along the day and night line, and the thin lit ring seen from the night side looking toward the Sun are what the sums give, not things drawn. The surface under it is dimmed by what the air takes out of the light. The old rim in the surface program is gone. Our own code, from the published single-scattering model (Nishita and others, 1993; GPU Gems 2, chapter 16), no code taken from any project. `air="light"` (6 samples along the ray and 2 toward the Sun; the default on a small or slow device) or `air="full"` (12 and 4), on both elements. It costs nothing at rest, at most 30 frames a second as before. New in `/realistic`: `AIR_TOP`, `AIR_QUALITY`, `AIR_VERT`, `airFrag`, `airFor` and `AirSamples`. `ATMOSPHERE_OUTER` stays the room the page leaves for it. Guide in English and Japanese: `docs/guides/full-screen-and-camera.md`.
|
|
12
|
+
|
|
5
13
|
## 0.27.0 - 2026-11-10
|
|
6
14
|
|
|
7
15
|
- **The demo's line and thick globes open turning where it can be seen** (MODULES-898). Auto-turn opens on a new 1440× button (a day a minute, a turn in about a minute) beside 0.5×, 1× and 2×; 1× is still the Earth's own rate, `0.004178` degrees a second, and the package's elements and the embed page are unchanged. The 3D looks keep their own 6 degrees a second, and going back to a line look puts the 1440× back. A reader who prefers reduced motion still gets a still globe with Auto-turn ready. Tests: `e2e/globe-turn.demo.ts`, `e2e/speed.demo.ts`.
|
package/README.md
CHANGED
|
@@ -489,7 +489,7 @@ console.log(countryList().filter((country) => country.alpha2 === null).map((coun
|
|
|
489
489
|
|
|
490
490
|
## How to cite
|
|
491
491
|
|
|
492
|
-
> Morris, J. (2026). *Chikyu Earth* (version 0.
|
|
492
|
+
> Morris, J. (2026). *Chikyu Earth* (version 0.29.0) [Computer software]. https://github.com/johnmorrisdotca/chikyu-earth
|
|
493
493
|
|
|
494
494
|
GitHub's "Cite this repository" button reads [CITATION.cff](CITATION.cff) and gives BibTeX and APA. Cite the version you used (`npm ls @johnmorrisdotca/chikyu-earth`), and credit the sources behind the numbers and pictures: [NOTICE.md](NOTICE.md) says who made each one and under what terms.
|
|
495
495
|
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The line, in the two languages the family's pages are written in; `{n}` is how many times its real thickness the air is drawn.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { AIR_NOTE } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
7
|
+
* console.log(AIR_NOTE.en.replace("{n}", "3"));
|
|
8
|
+
* ```
|
|
9
|
+
*/
|
|
10
|
+
export declare const AIR_NOTE: {
|
|
11
|
+
readonly en: "The air is drawn {n} times its real thickness so it can be seen.";
|
|
12
|
+
readonly ja: "大気は、見やすいように実際の厚さの{n}倍で描いています。";
|
|
13
|
+
};
|
|
14
|
+
/** The styles of the lines under the picture (`#notes`, with the air's `#air-note` and the meteors' `#meteor-note` in it, one above the other) in an element's shadow root. */
|
|
15
|
+
export declare const NOTES_STYLE = "#notes{position:absolute;left:8px;right:8px;bottom:6px;display:flex;flex-direction:column;align-items:flex-start;gap:4px;pointer-events:none}#notes>p{position:static;margin:0;max-width:100%;font:11px/1.3 system-ui,sans-serif;color:#dfe6f2;background:#0b0e14b3;padding:2px 6px;border-radius:4px}#notes>p[hidden]{display:none}";
|
|
16
|
+
/** The words of the line for a thickness: a whole number is written plainly, any other with up to one decimal. */
|
|
17
|
+
export declare function airNoteText(lang: "en" | "ja", thickness: number): string;
|
|
18
|
+
/** Put the line right: its words in the language of the element or the page, shown only while the air is thicker than it is (`air-thickness` above 1) and `air-label` is not `off`. */
|
|
19
|
+
export declare function setAirNote(note: HTMLElement | undefined, host: HTMLElement, thickness: number): void;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// The line an element shows under its picture while the air is drawn thicker than it is, so nobody takes the ring for the true size of the atmosphere.
|
|
2
|
+
/**
|
|
3
|
+
* The line, in the two languages the family's pages are written in; `{n}` is how many times its real thickness the air is drawn.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { AIR_NOTE } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
8
|
+
* console.log(AIR_NOTE.en.replace("{n}", "3"));
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export const AIR_NOTE = {
|
|
12
|
+
en: "The air is drawn {n} times its real thickness so it can be seen.",
|
|
13
|
+
ja: "大気は、見やすいように実際の厚さの{n}倍で描いています。",
|
|
14
|
+
};
|
|
15
|
+
/** The styles of the lines under the picture (`#notes`, with the air's `#air-note` and the meteors' `#meteor-note` in it, one above the other) in an element's shadow root. */
|
|
16
|
+
export const NOTES_STYLE = "#notes{position:absolute;left:8px;right:8px;bottom:6px;display:flex;flex-direction:column;align-items:flex-start;gap:4px;pointer-events:none}#notes>p{position:static;margin:0;max-width:100%;font:11px/1.3 system-ui,sans-serif;color:#dfe6f2;background:#0b0e14b3;padding:2px 6px;border-radius:4px}#notes>p[hidden]{display:none}";
|
|
17
|
+
/** The words of the line for a thickness: a whole number is written plainly, any other with up to one decimal. */
|
|
18
|
+
export function airNoteText(lang, thickness) {
|
|
19
|
+
return AIR_NOTE[lang].replace("{n}", String(Math.round(thickness * 10) / 10));
|
|
20
|
+
}
|
|
21
|
+
/** Put the line right: its words in the language of the element or the page, shown only while the air is thicker than it is (`air-thickness` above 1) and `air-label` is not `off`. */
|
|
22
|
+
export function setAirNote(note, host, thickness) {
|
|
23
|
+
if (!note)
|
|
24
|
+
return;
|
|
25
|
+
const lang = (host.closest("[lang]")?.getAttribute("lang") ?? "").toLowerCase().startsWith("ja") ? "ja" : "en";
|
|
26
|
+
note.textContent = airNoteText(lang, thickness);
|
|
27
|
+
note.lang = lang;
|
|
28
|
+
note.hidden = thickness <= 1 || host.getAttribute("air-label") === "off";
|
|
29
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The air's own top, in Earth radii: 100 km of the Earth's 6,371. The element leaves `ATMOSPHERE_OUTER` of room for it, so it is never cut at the box's edge.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { AIR_TOP } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
7
|
+
* console.log(((AIR_TOP - 1) * 6371).toFixed(0), "km thick");
|
|
8
|
+
* ```
|
|
9
|
+
*/
|
|
10
|
+
export declare const AIR_TOP: number;
|
|
11
|
+
/**
|
|
12
|
+
* How many times its real thickness the air is drawn when a page says nothing: 3. The air is a shell 100 km thick on a globe 12,742 km across, a hair's breadth, and at whole-Earth zoom it comes to a line a pixel or two wide (on a phone, thinner still);
|
|
13
|
+
* three times is a ring the eye can find, with the same physics and the same colours. `1` is the true thickness. The page's `air-thickness` attribute chooses.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { AIR_THICKNESS_DEFAULT } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
18
|
+
* console.log(AIR_THICKNESS_DEFAULT);
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare const AIR_THICKNESS_DEFAULT = 3;
|
|
22
|
+
/**
|
|
23
|
+
* The most the air may be thickened: 5, which is as far as the element's box leaves room for (its top is then 1.0785 Earth radii out, inside the 1.08 the box is fitted to).
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* import { AIR_THICKNESS_MAX } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
28
|
+
* console.log(AIR_THICKNESS_MAX);
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare const AIR_THICKNESS_MAX = 5;
|
|
32
|
+
/**
|
|
33
|
+
* What a page's `air-thickness` attribute means: a number from 1 (the true thickness) to 5, given as it is written; with none, or something that is not a number, `AIR_THICKNESS_DEFAULT`. A number outside the range is brought to its nearest end.
|
|
34
|
+
*
|
|
35
|
+
* @param given - The attribute's value, or `null` when the page has none.
|
|
36
|
+
* @returns How many times its real thickness the air is drawn, between 1 and 5.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* import { readAirThickness } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
41
|
+
* console.log(readAirThickness(null), readAirThickness("1"), readAirThickness("9"));
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare function readAirThickness(given: string | null): number;
|
|
45
|
+
/**
|
|
46
|
+
* Where the air's top is, in Earth radii, when it is drawn `thickness` times its real thickness: 1 plus 100 km times that, over the Earth's 6,371.
|
|
47
|
+
*
|
|
48
|
+
* @param thickness - 1 for the true thickness (the top is then `AIR_TOP`).
|
|
49
|
+
* @returns The radius of the shell's outside, in Earth radii.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* import { airTop } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
54
|
+
* console.log(airTop(3).toFixed(4));
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare const airTop: (thickness: number) => number;
|
|
58
|
+
/**
|
|
59
|
+
* How many samples the air takes: along the ray toward the camera and, at each of those, along the ray toward the Sun.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* import { AIR_QUALITY, type AirSamples } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
64
|
+
* const light: AirSamples = AIR_QUALITY.light;
|
|
65
|
+
* console.log(light.view, light.light);
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export interface AirSamples {
|
|
69
|
+
view: number;
|
|
70
|
+
light: number;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* The two costs of the air. `full` takes 12 samples along the ray toward the camera and 4 toward the Sun at each; `light` (a small or slow device) takes 6 and 2.
|
|
74
|
+
* Both put their samples where the air is thick (close to the ground, or at the nearest point of a ray that skims it), not evenly, so even the light one has no bands.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* import { AIR_QUALITY } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
79
|
+
* console.log(AIR_QUALITY.full);
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export declare const AIR_QUALITY: Record<"full" | "light", AirSamples>;
|
|
83
|
+
/**
|
|
84
|
+
* How much the air costs for a page: what its `air` attribute says (`full` or `light`), else `light` on a small or slow device (4 cores or fewer, 4 GB of memory or less, or a touch screen with no mouse) and `full` on the rest.
|
|
85
|
+
*
|
|
86
|
+
* @param given - The page's `air` attribute, or `null` when it has none.
|
|
87
|
+
* @returns `full` or `light`.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* import { airFor } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
92
|
+
* console.log(airFor("light"));
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
export declare function airFor(given: string | null): "full" | "light";
|
|
96
|
+
/**
|
|
97
|
+
* The air's program: where the shell is, in the world's own axes (the Earth sits at the origin and does not turn here, the view turns round it).
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts
|
|
101
|
+
* import { AIR_VERT } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
102
|
+
* console.log(AIR_VERT.includes("vWorld"));
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export declare const AIR_VERT = "\nvarying vec3 vWorld;\nvoid main() {\n vWorld = (modelMatrix * vec4(position, 1.0)).xyz;\n gl_Position = projectionMatrix * viewMatrix * vec4(vWorld, 1.0);\n}";
|
|
106
|
+
/**
|
|
107
|
+
* The air as light scattered once, worked out for each pixel: a ray from the camera through the shell, sampled `view` times, each sample looking `light` times toward the Sun.
|
|
108
|
+
* Rayleigh scattering (the air's own molecules: thicker the longer the path, and bluer) and Mie scattering (haze and dust: a bright halo round the Sun's direction), with the
|
|
109
|
+
* scale heights and coefficients of the standard sea-level air (Rayleigh 8 km, Mie 1.2 km; the Mie coefficient is that of very clear air, 0.4 of the usual, so the haze stays blue). What the sums give, and nothing drawn: the blue haze thickening toward the limb on the day side,
|
|
110
|
+
* the glow toward the Sun, the reddening along the day and night line (the Sun's light has crossed a long, low path) and the thin lit ring seen from the night side looking toward the Sun.
|
|
111
|
+
* The surface under it is dimmed by what the air takes out of the light (the shader's alpha is what gets through) and what it adds is the colour.
|
|
112
|
+
* Our own code, from the published single-scattering model (Nishita and others, 1993; O'Neil, GPU Gems 2, chapter 16), no code taken from any project.
|
|
113
|
+
* The air can be drawn thicker than it is (`thick`, a uniform: 1 is the true 100 km, 3 the default of the elements): the shell and both scale heights grow by it and what each unit of length holds shrinks by it, so the same air gives the same colours over a wider glow.
|
|
114
|
+
* The Sun is in the world's axes (`sunDir`, toward the Sun); `ortho` is 1 when the camera looks down the z axis from far away (the realistic Earth) and 0 for a camera at a place (the space view).
|
|
115
|
+
*
|
|
116
|
+
* @param samples - How many samples to take (`AIR_QUALITY.full` or `AIR_QUALITY.light`).
|
|
117
|
+
* @returns The fragment program's source, for a `ShaderMaterial`.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```ts
|
|
121
|
+
* import { airFrag, AIR_QUALITY } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
122
|
+
* console.log(airFrag(AIR_QUALITY.light).includes("N_VIEW 6"));
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
export declare const airFrag: (samples: AirSamples) => string;
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
// The air round the Earth: light scattered once on its way through a shell 100 km thick, worked out for each pixel in the fragment shader and added to what is behind it.
|
|
2
|
+
// Both elements that draw the Earth (the realistic one and the space view) use this one program; it knows nothing of either, only the Earth at the origin with a radius of 1.
|
|
3
|
+
/**
|
|
4
|
+
* The air's own top, in Earth radii: 100 km of the Earth's 6,371. The element leaves `ATMOSPHERE_OUTER` of room for it, so it is never cut at the box's edge.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { AIR_TOP } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
9
|
+
* console.log(((AIR_TOP - 1) * 6371).toFixed(0), "km thick");
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export const AIR_TOP = 1 + 100 / 6371;
|
|
13
|
+
/**
|
|
14
|
+
* How many times its real thickness the air is drawn when a page says nothing: 3. The air is a shell 100 km thick on a globe 12,742 km across, a hair's breadth, and at whole-Earth zoom it comes to a line a pixel or two wide (on a phone, thinner still);
|
|
15
|
+
* three times is a ring the eye can find, with the same physics and the same colours. `1` is the true thickness. The page's `air-thickness` attribute chooses.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { AIR_THICKNESS_DEFAULT } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
20
|
+
* console.log(AIR_THICKNESS_DEFAULT);
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export const AIR_THICKNESS_DEFAULT = 3;
|
|
24
|
+
/**
|
|
25
|
+
* The most the air may be thickened: 5, which is as far as the element's box leaves room for (its top is then 1.0785 Earth radii out, inside the 1.08 the box is fitted to).
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* import { AIR_THICKNESS_MAX } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
30
|
+
* console.log(AIR_THICKNESS_MAX);
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export const AIR_THICKNESS_MAX = 5;
|
|
34
|
+
/**
|
|
35
|
+
* What a page's `air-thickness` attribute means: a number from 1 (the true thickness) to 5, given as it is written; with none, or something that is not a number, `AIR_THICKNESS_DEFAULT`. A number outside the range is brought to its nearest end.
|
|
36
|
+
*
|
|
37
|
+
* @param given - The attribute's value, or `null` when the page has none.
|
|
38
|
+
* @returns How many times its real thickness the air is drawn, between 1 and 5.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* import { readAirThickness } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
43
|
+
* console.log(readAirThickness(null), readAirThickness("1"), readAirThickness("9"));
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export function readAirThickness(given) {
|
|
47
|
+
if (given === null || given.trim() === "")
|
|
48
|
+
return AIR_THICKNESS_DEFAULT;
|
|
49
|
+
const value = Number(given);
|
|
50
|
+
if (!Number.isFinite(value))
|
|
51
|
+
return AIR_THICKNESS_DEFAULT;
|
|
52
|
+
return Math.min(AIR_THICKNESS_MAX, Math.max(1, value));
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Where the air's top is, in Earth radii, when it is drawn `thickness` times its real thickness: 1 plus 100 km times that, over the Earth's 6,371.
|
|
56
|
+
*
|
|
57
|
+
* @param thickness - 1 for the true thickness (the top is then `AIR_TOP`).
|
|
58
|
+
* @returns The radius of the shell's outside, in Earth radii.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* import { airTop } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
63
|
+
* console.log(airTop(3).toFixed(4));
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export const airTop = (thickness) => 1 + (thickness * 100) / 6371;
|
|
67
|
+
/**
|
|
68
|
+
* The two costs of the air. `full` takes 12 samples along the ray toward the camera and 4 toward the Sun at each; `light` (a small or slow device) takes 6 and 2.
|
|
69
|
+
* Both put their samples where the air is thick (close to the ground, or at the nearest point of a ray that skims it), not evenly, so even the light one has no bands.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```ts
|
|
73
|
+
* import { AIR_QUALITY } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
74
|
+
* console.log(AIR_QUALITY.full);
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export const AIR_QUALITY = {
|
|
78
|
+
full: { view: 12, light: 4 },
|
|
79
|
+
light: { view: 6, light: 2 },
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* How much the air costs for a page: what its `air` attribute says (`full` or `light`), else `light` on a small or slow device (4 cores or fewer, 4 GB of memory or less, or a touch screen with no mouse) and `full` on the rest.
|
|
83
|
+
*
|
|
84
|
+
* @param given - The page's `air` attribute, or `null` when it has none.
|
|
85
|
+
* @returns `full` or `light`.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```ts
|
|
89
|
+
* import { airFor } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
90
|
+
* console.log(airFor("light"));
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
export function airFor(given) {
|
|
94
|
+
if (given === "full" || given === "light")
|
|
95
|
+
return given;
|
|
96
|
+
const nav = typeof navigator === "undefined" ? undefined : navigator;
|
|
97
|
+
const coarse = typeof matchMedia === "function" && matchMedia("(pointer: coarse) and (hover: none)").matches;
|
|
98
|
+
return coarse || (nav?.hardwareConcurrency ?? 8) <= 4 || (nav?.deviceMemory ?? 8) <= 4 ? "light" : "full";
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The air's program: where the shell is, in the world's own axes (the Earth sits at the origin and does not turn here, the view turns round it).
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* import { AIR_VERT } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
106
|
+
* console.log(AIR_VERT.includes("vWorld"));
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
export const AIR_VERT = /* glsl */ `
|
|
110
|
+
varying vec3 vWorld;
|
|
111
|
+
void main() {
|
|
112
|
+
vWorld = (modelMatrix * vec4(position, 1.0)).xyz;
|
|
113
|
+
gl_Position = projectionMatrix * viewMatrix * vec4(vWorld, 1.0);
|
|
114
|
+
}`;
|
|
115
|
+
/**
|
|
116
|
+
* The air as light scattered once, worked out for each pixel: a ray from the camera through the shell, sampled `view` times, each sample looking `light` times toward the Sun.
|
|
117
|
+
* Rayleigh scattering (the air's own molecules: thicker the longer the path, and bluer) and Mie scattering (haze and dust: a bright halo round the Sun's direction), with the
|
|
118
|
+
* scale heights and coefficients of the standard sea-level air (Rayleigh 8 km, Mie 1.2 km; the Mie coefficient is that of very clear air, 0.4 of the usual, so the haze stays blue). What the sums give, and nothing drawn: the blue haze thickening toward the limb on the day side,
|
|
119
|
+
* the glow toward the Sun, the reddening along the day and night line (the Sun's light has crossed a long, low path) and the thin lit ring seen from the night side looking toward the Sun.
|
|
120
|
+
* The surface under it is dimmed by what the air takes out of the light (the shader's alpha is what gets through) and what it adds is the colour.
|
|
121
|
+
* Our own code, from the published single-scattering model (Nishita and others, 1993; O'Neil, GPU Gems 2, chapter 16), no code taken from any project.
|
|
122
|
+
* The air can be drawn thicker than it is (`thick`, a uniform: 1 is the true 100 km, 3 the default of the elements): the shell and both scale heights grow by it and what each unit of length holds shrinks by it, so the same air gives the same colours over a wider glow.
|
|
123
|
+
* The Sun is in the world's axes (`sunDir`, toward the Sun); `ortho` is 1 when the camera looks down the z axis from far away (the realistic Earth) and 0 for a camera at a place (the space view).
|
|
124
|
+
*
|
|
125
|
+
* @param samples - How many samples to take (`AIR_QUALITY.full` or `AIR_QUALITY.light`).
|
|
126
|
+
* @returns The fragment program's source, for a `ShaderMaterial`.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```ts
|
|
130
|
+
* import { airFrag, AIR_QUALITY } from "@johnmorrisdotca/chikyu-earth/realistic";
|
|
131
|
+
* console.log(airFrag(AIR_QUALITY.light).includes("N_VIEW 6"));
|
|
132
|
+
* ```
|
|
133
|
+
*/
|
|
134
|
+
export const airFrag = (samples) => /* glsl */ `
|
|
135
|
+
#define N_VIEW ${samples.view}
|
|
136
|
+
#define N_LIGHT ${samples.light}
|
|
137
|
+
uniform vec3 sunDir;
|
|
138
|
+
uniform float ortho;
|
|
139
|
+
uniform float thick;
|
|
140
|
+
varying vec3 vWorld;
|
|
141
|
+
const float TOP1 = ${AIR_TOP.toFixed(6)};
|
|
142
|
+
const float HR1 = 0.001256;
|
|
143
|
+
const float HM1 = 0.000188;
|
|
144
|
+
// drawn thick times its real thickness: the shell and both scale heights are that many times larger
|
|
145
|
+
#define TOP (1.0 + (TOP1 - 1.0) * thick)
|
|
146
|
+
#define HR (HR1 * thick)
|
|
147
|
+
#define HM (HM1 * thick)
|
|
148
|
+
// the same amount of air, spread over the taller shell: each unit of length holds that much less of it, so the air looks straight down through is as thin a veil as ever, and only the glow at the limb is wider
|
|
149
|
+
#define DENS (1.0 / thick)
|
|
150
|
+
const vec3 BETA_R = vec3(36.95, 86.0, 210.9);
|
|
151
|
+
const float BETA_M = 53.5;
|
|
152
|
+
const float G = 0.76;
|
|
153
|
+
const float PI = 3.14159265358979;
|
|
154
|
+
const float SUN = 110.0;
|
|
155
|
+
// the nearest and the farthest point where a ray from o along d meets a sphere of radius r about the Earth's centre (-1 for both when it misses)
|
|
156
|
+
vec2 hit(vec3 o, vec3 d, float r) {
|
|
157
|
+
float b = dot(o, d);
|
|
158
|
+
float h = b * b - (dot(o, o) - r * r);
|
|
159
|
+
if (h < 0.0) return vec2(-1.0, -1.0);
|
|
160
|
+
h = sqrt(h);
|
|
161
|
+
return vec2(-b - h, -b + h);
|
|
162
|
+
}
|
|
163
|
+
// Sample i of n along a ray of length tEnd whose air is thickest at tDense: half of them each side of it, close together near it and wide apart away from it. Gives where it is (t) and the length of ray it stands for (dt).
|
|
164
|
+
void place(int i, int n, float tDense, float tEnd, out float t, out float dt) {
|
|
165
|
+
float near = tDense;
|
|
166
|
+
float far = max(tEnd - tDense, 0.0);
|
|
167
|
+
float nNear = near < 1e-6 ? 0.0 : (far < 1e-6 ? float(n) : floor(float(n) * 0.5));
|
|
168
|
+
float fi = float(i);
|
|
169
|
+
if (fi < nNear) {
|
|
170
|
+
float w = 1.0 - (fi + 0.5) / nNear;
|
|
171
|
+
t = near * (1.0 - w * w);
|
|
172
|
+
dt = 2.0 * near * w / nNear;
|
|
173
|
+
} else {
|
|
174
|
+
float cnt = float(n) - nNear;
|
|
175
|
+
float v = (fi - nNear + 0.5) / cnt;
|
|
176
|
+
t = tDense + far * v * v;
|
|
177
|
+
dt = 2.0 * far * v / cnt;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
// the air's thickness (Rayleigh, Mie) from p along dir to the top of the shell
|
|
181
|
+
vec2 column(vec3 p, vec3 dir) {
|
|
182
|
+
float tEnd = hit(p, dir, TOP).y;
|
|
183
|
+
float tDense = clamp(-dot(p, dir), 0.0, tEnd);
|
|
184
|
+
vec2 sum = vec2(0.0);
|
|
185
|
+
for (int j = 0; j < N_LIGHT; j++) {
|
|
186
|
+
float t;
|
|
187
|
+
float dt;
|
|
188
|
+
place(j, N_LIGHT, tDense, tEnd, t, dt);
|
|
189
|
+
float height = max(length(p + dir * t) - 1.0, 0.0);
|
|
190
|
+
sum += vec2(exp(-height / HR), exp(-height / HM)) * dt;
|
|
191
|
+
}
|
|
192
|
+
return sum;
|
|
193
|
+
}
|
|
194
|
+
void main() {
|
|
195
|
+
vec3 o = vWorld;
|
|
196
|
+
vec3 d = ortho > 0.5 ? vec3(0.0, 0.0, -1.0) : normalize(vWorld - cameraPosition);
|
|
197
|
+
float b = dot(o, d);
|
|
198
|
+
// the ray ends where it meets the ground, or leaves the shell; the air is thickest at the ground, or at the nearest point of a ray that skims it
|
|
199
|
+
vec2 ground = hit(o, d, 1.0);
|
|
200
|
+
bool onGround = ground.x > 0.0;
|
|
201
|
+
float tEnd = onGround ? ground.x : hit(o, d, TOP).y;
|
|
202
|
+
float tDense = onGround ? ground.x : clamp(-b, 0.0, tEnd);
|
|
203
|
+
float mu = dot(d, sunDir);
|
|
204
|
+
float phaseR = 3.0 / (16.0 * PI) * (1.0 + mu * mu);
|
|
205
|
+
float phaseM = 3.0 / (8.0 * PI) * ((1.0 - G * G) * (1.0 + mu * mu)) / ((2.0 + G * G) * pow(1.0 + G * G - 2.0 * G * mu, 1.5));
|
|
206
|
+
// most of the disc is a short, steep path through the air: half the samples do for it, and only the limb takes them all
|
|
207
|
+
int used = onGround && tEnd < 0.08 ? N_VIEW / 2 : N_VIEW;
|
|
208
|
+
vec2 depth = vec2(0.0);
|
|
209
|
+
vec3 sumR = vec3(0.0);
|
|
210
|
+
vec3 sumM = vec3(0.0);
|
|
211
|
+
for (int i = 0; i < N_VIEW; i++) {
|
|
212
|
+
if (i >= used) break;
|
|
213
|
+
float t;
|
|
214
|
+
float dt;
|
|
215
|
+
place(i, used, tDense, tEnd, t, dt);
|
|
216
|
+
vec3 p = o + d * t;
|
|
217
|
+
float height = max(length(p) - 1.0, 0.0);
|
|
218
|
+
vec2 here = vec2(exp(-height / HR), exp(-height / HM)) * dt;
|
|
219
|
+
float shade = 1.0;
|
|
220
|
+
// behind the Earth's edge the Sun's light does not reach; the edge is soft by a few kilometres, as the lowest air makes it
|
|
221
|
+
float ahead = dot(p, sunDir);
|
|
222
|
+
if (ahead < 0.0) shade = smoothstep(1.0 - 0.003, 1.0 + 0.003, sqrt(max(dot(p, p) - ahead * ahead, 0.0)));
|
|
223
|
+
vec2 sun = shade > 0.0 ? column(p, sunDir) : vec2(0.0);
|
|
224
|
+
vec2 path = depth + 0.5 * here;
|
|
225
|
+
vec3 gone = exp(-DENS * (BETA_R * (path.x + sun.x) + BETA_M * 1.1 * (path.y + sun.y)));
|
|
226
|
+
sumR += gone * here.x * shade;
|
|
227
|
+
sumM += gone * here.y * shade;
|
|
228
|
+
depth += here;
|
|
229
|
+
}
|
|
230
|
+
vec3 colour = SUN * DENS * (sumR * BETA_R * phaseR + sumM * BETA_M * phaseM);
|
|
231
|
+
vec3 through = exp(-DENS * (BETA_R * depth.x + BETA_M * 1.1 * depth.y));
|
|
232
|
+
// the colour is premultiplied: what is added, and how much of what is behind it gets through
|
|
233
|
+
// a steep look at the ground through the air has only a thin veil over it; the haze gathers toward the limb, where the path through the air is long
|
|
234
|
+
colour *= onGround ? 0.1 + 0.9 * smoothstep(0.02, 0.16, tEnd) : 1.0;
|
|
235
|
+
// brightness is squeezed to what a screen shows by its strongest channel, so a thick, bright path stays blue instead of going grey; the curve keeps thin air quiet
|
|
236
|
+
float peak = max(max(colour.r, colour.g), colour.b);
|
|
237
|
+
vec3 shown = colour * pow(1.0 - exp(-peak), 2.0) / max(peak, 1e-6);
|
|
238
|
+
gl_FragColor = vec4(shown, 1.0 - through.g);
|
|
239
|
+
}`;
|
|
@@ -60,6 +60,8 @@ export interface EarthModel {
|
|
|
60
60
|
light: LightMode;
|
|
61
61
|
/** How the camera is held (see `CameraMode`). */
|
|
62
62
|
camera: CameraMode;
|
|
63
|
+
/** How many times its real thickness the air is drawn, 1 to 5 (`AIR_THICKNESS_DEFAULT` until the element says otherwise); read at every draw. */
|
|
64
|
+
airThickness: number;
|
|
63
65
|
/** How fast the cloud picture is made to move eastward against the ground, degrees an hour: 0 (the default) keeps the clouds where the picture has them. The picture is one snapshot, not a forecast; a drift is only for life. */
|
|
64
66
|
cloudDrift: number;
|
|
65
67
|
/** For the `space` camera: the Earth's turn against the stars (degrees) when the camera was set; null until the next draw sets it. */
|
|
@@ -97,6 +99,8 @@ export interface EarthDeps {
|
|
|
97
99
|
invalidate: () => void;
|
|
98
100
|
onError?: (error: unknown) => void;
|
|
99
101
|
onTier?: (layer: Layer, width: number) => void;
|
|
102
|
+
/** How much the air costs: `full` (12 samples along the ray and 4 toward the Sun) or `light` (6 and 2, for a small or slow device). Read once, when the scene is built. */
|
|
103
|
+
air?: () => "full" | "light";
|
|
100
104
|
/** The satellites could not be drawn (the three.js parts handed over lack `Points`). */
|
|
101
105
|
onSatellitesError?: (error: unknown) => void;
|
|
102
106
|
/** Told at the start of every draw, before anything is read for it. */
|
package/dist/realistic/earth.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { HOME_VIEW, lookAt } from "../view.js";
|
|
2
|
-
import {
|
|
2
|
+
import { AIR_QUALITY, AIR_THICKNESS_DEFAULT, AIR_VERT, airFrag, airTop } from "./air.js";
|
|
3
|
+
import { CLOUD_FRAG, SURFACE_FRAG, SURFACE_VERT } from "./shaders.js";
|
|
3
4
|
import { greenwichSidereal, subsolarPoint, unitVector } from "./sun.js";
|
|
4
5
|
import { createSatelliteLayer, newSatelliteState } from "../space/satellite-layer.js";
|
|
5
6
|
import { createTextureSet } from "./textures.js";
|
|
@@ -27,6 +28,7 @@ export const newModel = () => ({
|
|
|
27
28
|
lights: true,
|
|
28
29
|
light: "sun",
|
|
29
30
|
camera: "space",
|
|
31
|
+
airThickness: AIR_THICKNESS_DEFAULT,
|
|
30
32
|
cloudDrift: 0,
|
|
31
33
|
cameraSpin: null,
|
|
32
34
|
speed: 1,
|
|
@@ -146,13 +148,14 @@ export function createEarthItem(model, deps) {
|
|
|
146
148
|
transparent: true,
|
|
147
149
|
depthWrite: false,
|
|
148
150
|
});
|
|
151
|
+
// the air: light scattered once on its way through a shell 100 km thick, worked out for each pixel and laid over the surface. A device that is small or slow takes fewer samples (the `light` quality).
|
|
149
152
|
const atmosphere = new three.ShaderMaterial({
|
|
150
|
-
vertexShader:
|
|
151
|
-
fragmentShader:
|
|
152
|
-
uniforms: {
|
|
153
|
+
vertexShader: AIR_VERT,
|
|
154
|
+
fragmentShader: airFrag(AIR_QUALITY[deps.air?.() ?? "full"]),
|
|
155
|
+
uniforms: { sunDir, ortho: { value: 1 }, thick: { value: model.airThickness } },
|
|
153
156
|
transparent: true,
|
|
157
|
+
premultipliedAlpha: true,
|
|
154
158
|
depthWrite: false,
|
|
155
|
-
side: three.BackSide,
|
|
156
159
|
});
|
|
157
160
|
const turned = new three.Group();
|
|
158
161
|
const earth = new three.Mesh(grid, surface);
|
|
@@ -163,8 +166,8 @@ export function createEarthItem(model, deps) {
|
|
|
163
166
|
clouds.renderOrder = 2;
|
|
164
167
|
turned.add(earth, clouds);
|
|
165
168
|
const glow = new three.Mesh(grid, atmosphere);
|
|
166
|
-
glow.scale.setScalar(
|
|
167
|
-
glow.renderOrder =
|
|
169
|
+
glow.scale.setScalar(airTop(model.airThickness));
|
|
170
|
+
glow.renderOrder = 3;
|
|
168
171
|
glow.frustumCulled = false;
|
|
169
172
|
const scene = new three.Scene();
|
|
170
173
|
scene.add(turned, glow);
|
|
@@ -199,6 +202,8 @@ export function createEarthItem(model, deps) {
|
|
|
199
202
|
sunDir.value.set(0, 0, 1);
|
|
200
203
|
cloudShift.value = -(((model.time / 3_600_000) * model.cloudDrift) % 360) / 360;
|
|
201
204
|
clouds.visible = model.clouds;
|
|
205
|
+
atmosphere.uniforms["thick"].value = model.airThickness;
|
|
206
|
+
glow.scale.setScalar(airTop(model.airThickness));
|
|
202
207
|
surface.uniforms["lights"].value = model.lights && model.light !== "lit" ? 1 : 0;
|
|
203
208
|
surface.uniforms["boost"].value = model.light === "boost" ? 1 : 0;
|
|
204
209
|
const radius = discRadius(size.width, size.height, view.zoom);
|
|
@@ -103,6 +103,12 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
|
|
|
103
103
|
connectedCallback(): void;
|
|
104
104
|
disconnectedCallback(): void;
|
|
105
105
|
attributeChangedCallback(name: string, _old: string | null, value: string | null): void;
|
|
106
|
+
/**
|
|
107
|
+
* How many times its real thickness the air is drawn, from 1 (the true thickness) to 5 (the attribute `air-thickness`; 3 when the page says nothing). The shell, and the heights over which the air thins, are that many times larger, and the
|
|
108
|
+
* air's own light is the same, so a ring that is a hair's breadth at whole-Earth zoom can be seen. While it is above 1 the element says so in a line under the picture (`air-label="off"` takes the line away, for a page that says it itself).
|
|
109
|
+
*/
|
|
110
|
+
get airThickness(): number;
|
|
111
|
+
set airThickness(value: number);
|
|
106
112
|
/**
|
|
107
113
|
* Meteors seen from space, on or off (the attribute `meteors`): see the class's description. Off by default, and nothing of theirs is made until they are first switched on.
|
|
108
114
|
*/
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
// changes, at most 30 times a second, and nothing at all while it is out of sight or the tab is hidden.
|
|
4
4
|
import { carryControls } from "@johnmorrisdotca/kazoku-ui/view-controls";
|
|
5
5
|
import { adoptStyles } from "../adopt.js";
|
|
6
|
+
import { airFor, readAirThickness } from "./air.js";
|
|
7
|
+
import { NOTES_STYLE, setAirNote } from "./air-note.js";
|
|
6
8
|
import { cameraCentre, createEarthItem, discRadius, lookAt, newModel } from "./earth.js";
|
|
7
9
|
import { MAX_SATELLITE_SPEED } from "../satellites/limits.js";
|
|
8
10
|
import { MAX_ORBIT_GROUP } from "../space/satellite-layer.js";
|
|
@@ -11,7 +13,7 @@ import { createGate, frameCap } from "./gate.js";
|
|
|
11
13
|
import { setSharedRenderer, setThreeLoader, takeRenderer } from "./shared.js";
|
|
12
14
|
export { setSharedRenderer, setThreeLoader };
|
|
13
15
|
import { MAX_TEXTURE, TIERS } from "./tiers.js";
|
|
14
|
-
const STYLE = ":host{display:block;aspect-ratio:1/1;position:relative}:host([immersive]){aspect-ratio:auto;width:100%;height:100%;touch-action:none!important;user-select:none;-webkit-user-select:none;-webkit-tap-highlight-color:transparent}#stage,#overlay{position:absolute;inset:0}#overlay{pointer-events:none}" + METEOR_NOTE_STYLE;
|
|
16
|
+
const STYLE = ":host{display:block;aspect-ratio:1/1;position:relative}:host([immersive]){aspect-ratio:auto;width:100%;height:100%;touch-action:none!important;user-select:none;-webkit-user-select:none;-webkit-tap-highlight-color:transparent}#stage,#overlay{position:absolute;inset:0}#overlay{pointer-events:none}" + METEOR_NOTE_STYLE + NOTES_STYLE;
|
|
15
17
|
const RAD = Math.PI / 180;
|
|
16
18
|
/** The Sun and the clouds are re-placed this often at real time: 15 degrees an hour is 0.25 degree a minute. */
|
|
17
19
|
const LIVE_TICK_MS = 60_000;
|
|
@@ -121,7 +123,7 @@ export const readTime = (value) => {
|
|
|
121
123
|
* ```
|
|
122
124
|
*/
|
|
123
125
|
export class ChikyuEarthRealistic extends HTMLElement {
|
|
124
|
-
static observedAttributes = ["cloud-drift", "center", "time", "speed", "clouds", "lights", "light", "live-seconds", "tiles", "camera", "immersive", "meteors", "meteors-label", "lang"];
|
|
126
|
+
static observedAttributes = ["cloud-drift", "center", "time", "speed", "clouds", "lights", "light", "live-seconds", "tiles", "camera", "immersive", "meteors", "meteors-label", "air-thickness", "air-label", "lang"];
|
|
125
127
|
#model = newModel();
|
|
126
128
|
#mode = "now";
|
|
127
129
|
#view;
|
|
@@ -146,6 +148,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
146
148
|
/** The page has set a `speed` since the element came into the page: for a reader who prefers reduced motion, that is the Play that lets meteors start. */
|
|
147
149
|
#played = false;
|
|
148
150
|
#note;
|
|
151
|
+
#airNote;
|
|
149
152
|
#onContext = (state) => {
|
|
150
153
|
if (state === "unavailable")
|
|
151
154
|
this.#fail("WebGL is not available");
|
|
@@ -164,22 +167,25 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
164
167
|
this.#model.light = readLight(this.getAttribute("light"));
|
|
165
168
|
this.#model.camera = readCamera(this.getAttribute("camera"));
|
|
166
169
|
this.#model.cloudDrift = readDrift(this.getAttribute("cloud-drift"));
|
|
170
|
+
this.#model.airThickness = readAirThickness(this.getAttribute("air-thickness"));
|
|
167
171
|
this.#model.speed = this.speed;
|
|
168
172
|
if (!this.hasAttribute("role"))
|
|
169
173
|
this.setAttribute("role", "img");
|
|
170
174
|
if (!this.hasAttribute("aria-label"))
|
|
171
175
|
this.setAttribute("aria-label", "The Earth from space, with its sunlit and dark sides");
|
|
172
176
|
const root = this.shadowRoot ?? this.attachShadow({ mode: "open" });
|
|
173
|
-
root.innerHTML = `<div id="stage"></div><div id="overlay"></div><p id="meteor-note" hidden></p>`;
|
|
177
|
+
root.innerHTML = `<div id="stage"></div><div id="overlay"></div><div id="notes"><p id="air-note" hidden></p><p id="meteor-note" hidden></p></div>`;
|
|
174
178
|
adoptStyles(root, STYLE, this.nonce);
|
|
175
179
|
this.#stage = root.getElementById("stage");
|
|
176
180
|
this.#overlay = root.getElementById("overlay");
|
|
177
181
|
this.#note = root.getElementById("meteor-note");
|
|
182
|
+
this.#airNote = root.getElementById("air-note");
|
|
178
183
|
this.#played = false;
|
|
179
184
|
this.#model.meteors.on = this.#meteorsAsked();
|
|
180
185
|
this.#model.meteors.running = () => this.speed !== 0 && document.visibilityState !== "hidden" && (this.#played || !prefersLessMotion());
|
|
181
186
|
this.#model.meteors.onShower = (shower, zhr) => this.dispatchEvent(new CustomEvent("chikyu-meteors", { detail: { shower, zhr } }));
|
|
182
187
|
this.#meteorNote();
|
|
188
|
+
setAirNote(this.#airNote, this, this.#model.airThickness);
|
|
183
189
|
this.#stage.addEventListener("webglcontextlost", this.#lost, true);
|
|
184
190
|
this.#stage.addEventListener("webglcontextrestored", this.#restored, true);
|
|
185
191
|
const nav = navigator;
|
|
@@ -206,6 +212,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
206
212
|
}
|
|
207
213
|
this.dispatchEvent(new CustomEvent("chikyu-tiles", { detail: { layers } }));
|
|
208
214
|
},
|
|
215
|
+
air: () => airFor(this.getAttribute("air")),
|
|
209
216
|
invalidate: () => this.#gate?.soon(),
|
|
210
217
|
onDraw: () => this.#gate?.drawn(),
|
|
211
218
|
onPose: (pose) => {
|
|
@@ -289,8 +296,14 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
289
296
|
}
|
|
290
297
|
else if (name === "meteors")
|
|
291
298
|
this.meteors = this.#meteorsAsked();
|
|
299
|
+
else if (name === "air-thickness") {
|
|
300
|
+
this.#model.airThickness = readAirThickness(value);
|
|
301
|
+
this.#gate?.soon();
|
|
302
|
+
}
|
|
292
303
|
else if (name === "meteors-label" || name === "lang")
|
|
293
304
|
this.#meteorNote();
|
|
305
|
+
if (name === "air-thickness" || name === "air-label" || name === "lang")
|
|
306
|
+
setAirNote(this.#airNote, this, this.#model.airThickness);
|
|
294
307
|
}
|
|
295
308
|
#meteorsAsked() {
|
|
296
309
|
return this.hasAttribute("meteors") && this.getAttribute("meteors") !== "off";
|
|
@@ -299,6 +312,16 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
299
312
|
#meteorNote() {
|
|
300
313
|
setMeteorNote(this.#note, this, this.#model.meteors.on);
|
|
301
314
|
}
|
|
315
|
+
/**
|
|
316
|
+
* How many times its real thickness the air is drawn, from 1 (the true thickness) to 5 (the attribute `air-thickness`; 3 when the page says nothing). The shell, and the heights over which the air thins, are that many times larger, and the
|
|
317
|
+
* air's own light is the same, so a ring that is a hair's breadth at whole-Earth zoom can be seen. While it is above 1 the element says so in a line under the picture (`air-label="off"` takes the line away, for a page that says it itself).
|
|
318
|
+
*/
|
|
319
|
+
get airThickness() {
|
|
320
|
+
return this.#model.airThickness;
|
|
321
|
+
}
|
|
322
|
+
set airThickness(value) {
|
|
323
|
+
this.setAttribute("air-thickness", String(value));
|
|
324
|
+
}
|
|
302
325
|
/**
|
|
303
326
|
* Meteors seen from space, on or off (the attribute `meteors`): see the class's description. Off by default, and nothing of theirs is made until they are first switched on.
|
|
304
327
|
*/
|
|
@@ -5,3 +5,5 @@ export { lookAt, discRadius, ATMOSPHERE_OUTER, cameraCentre, type CameraMode, ty
|
|
|
5
5
|
export type { ThreeParts } from "./earth.ts";
|
|
6
6
|
export { TEXEL_SLACK, coveringTile, parseManifest, pointOnEarth, tileColumns, tileLevel, tileRect, tileRows, tilesInView, type TileCamera, type TileId, type TileLayer, type VisibleTile } from "./tiles.ts";
|
|
7
7
|
export { TILE_KEEP_MS, TILE_LIMIT } from "./tile-set.ts";
|
|
8
|
+
export { AIR_QUALITY, AIR_THICKNESS_DEFAULT, AIR_THICKNESS_MAX, AIR_TOP, AIR_VERT, airFor, airFrag, airTop, readAirThickness, type AirSamples } from "./air.ts";
|
|
9
|
+
export { AIR_NOTE } from "./air-note.ts";
|
package/dist/realistic/index.js
CHANGED
|
@@ -6,3 +6,5 @@ export { createGate, frameCap } from "./gate.js";
|
|
|
6
6
|
export { lookAt, discRadius, ATMOSPHERE_OUTER, cameraCentre } from "./earth.js";
|
|
7
7
|
export { TEXEL_SLACK, coveringTile, parseManifest, pointOnEarth, tileColumns, tileLevel, tileRect, tileRows, tilesInView } from "./tiles.js";
|
|
8
8
|
export { TILE_KEEP_MS, TILE_LIMIT } from "./tile-set.js";
|
|
9
|
+
export { AIR_QUALITY, AIR_THICKNESS_DEFAULT, AIR_THICKNESS_MAX, AIR_TOP, AIR_VERT, airFor, airFrag, airTop, readAirThickness } from "./air.js";
|
|
10
|
+
export { AIR_NOTE } from "./air-note.js";
|
|
@@ -8,8 +8,6 @@ export declare const TILE_FRAG: string;
|
|
|
8
8
|
*/
|
|
9
9
|
export declare const TILE_VERT = "\nuniform vec4 rect;\nuniform float radius;\nvarying vec2 vUv;\nvarying vec2 vUvG;\nvarying vec3 vNormal;\nvarying vec3 vWorld;\nvoid main() {\n vUv = uv;\n float lon = mix(rect.x, rect.z, uv.x);\n float lat = mix(rect.y, rect.w, uv.y);\n vec3 unit = vec3(cos(lat) * sin(lon), sin(lat), cos(lat) * cos(lon));\n vUvG = vec2((lon + 3.14159265358979) / 6.28318530717959, 0.5 - lat / 3.14159265358979);\n vNormal = normalize(mat3(modelMatrix) * unit);\n vec4 world = modelMatrix * vec4(unit * radius, 1.0);\n vWorld = world.xyz;\n gl_Position = projectionMatrix * viewMatrix * world;\n}";
|
|
10
10
|
export declare const CLOUD_FRAG = "\nuniform sampler2D cloudMap;\nuniform vec3 sunDir;\nuniform float shift;\nuniform float opacity;\nvarying vec2 vUv;\nvarying vec3 vNormal;\nvoid main() {\n vec3 n = normalize(vNormal);\n float ndl = dot(n, sunDir);\n float c = texture2D(cloudMap, vec2(vUv.x + shift, vUv.y)).r;\n float a = smoothstep(0.28, 0.88, c) * opacity;\n float day = smoothstep(-0.10, 0.25, ndl);\n vec3 col = mix(vec3(0.015, 0.02, 0.04), vec3(1.0), day * (0.18 + 0.82 * pow(max(ndl, 0.0), 0.45)));\n col += vec3(0.55, 0.28, 0.14) * smoothstep(-0.14, 0.0, ndl) * (1.0 - smoothstep(0.0, 0.25, ndl)) * 0.35;\n gl_FragColor = vec4(col, a);\n}";
|
|
11
|
-
export declare const ATMOSPHERE_VERT = "\nvarying vec3 vPosView;\nvarying vec3 vNormalView;\nvoid main() {\n vec4 view = modelViewMatrix * vec4(position, 1.0);\n vPosView = view.xyz;\n vNormalView = normalize(normalMatrix * position);\n gl_Position = projectionMatrix * view;\n}";
|
|
12
|
-
export declare const ATMOSPHERE_FRAG = "\nuniform vec3 sunView;\nuniform float outer;\nuniform float ortho;\nvarying vec3 vPosView;\nvarying vec3 vNormalView;\nvoid main() {\n vec3 n = normalize(vNormalView);\n vec3 v = ortho > 0.5 ? vec3(0.0, 0.0, 1.0) : normalize(-vPosView);\n float nz = clamp(dot(n, v), -1.0, 1.0);\n float rho = outer * sqrt(max(0.0, 1.0 - nz * nz));\n float t = clamp((rho - 1.0) / (outer - 1.0), 0.0, 1.0);\n vec2 dir = normalize(n.xy + vec2(1e-5, 0.0));\n // the Sun's light at this point of the limb: 1 where the Sun stands behind it, 0 at the terminator, -1 on the night side\n float toward = dot(vec3(dir, 0.0), sunView);\n float side = smoothstep(-0.45, 0.45, toward);\n // a thin bright layer on the limb and a wide faint halo, both fading to nothing at the outer edge\n float limb = pow(1.0 - t, 5.0);\n float halo = pow(1.0 - t, 2.2);\n float glow = (limb * 0.85 + halo * 0.35) * (0.06 + 0.94 * side);\n vec3 day = mix(vec3(0.30, 0.52, 0.95), vec3(0.50, 0.74, 1.0), limb);\n vec3 dusk = mix(vec3(1.0, 0.42, 0.16), vec3(1.0, 0.62, 0.30), limb);\n float band = exp(-pow(toward / 0.32, 2.0));\n vec3 col = mix(mix(vec3(0.06, 0.12, 0.35), day, side), dusk, band * 0.85);\n gl_FragColor = vec4(col, clamp(glow, 0.0, 1.0) * (1.0 - t));\n}";
|
|
13
11
|
/** The Moon and other plain bodies: a picture (or a flat colour) lit by the Sun, with a trace of light on the dark side. */
|
|
14
12
|
export declare const BODY_FRAG = "\nuniform sampler2D map;\nuniform vec3 tint;\nuniform float textured;\nuniform float ambient;\nuniform vec3 sunDir;\nvarying vec2 vUv;\nvarying vec3 vNormal;\nvoid main() {\n vec3 n = normalize(vNormal);\n float ndl = dot(n, sunDir);\n vec3 albedo = textured > 0.5 ? texture2D(map, vUv).rgb : tint;\n float lit = smoothstep(-0.04, 0.12, ndl) * (0.10 + 0.95 * pow(max(ndl, 0.0), 0.6));\n gl_FragColor = vec4(albedo * (ambient + lit), 1.0);\n}";
|
|
15
13
|
/** A flat quad facing the camera: the Sun's disc and its glow. */
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// The
|
|
2
|
-
//
|
|
1
|
+
// The programs of the realistic Earth, as GLSL strings: the surface (day, night, sun glint), the cloud layer and the Moon and the Sun's glow. The air is `air.ts`.
|
|
2
|
+
// Colours are shaded in the textures' own (sRGB) space: a look, not a radiometric model.
|
|
3
3
|
export const SURFACE_VERT = /* glsl */ `
|
|
4
4
|
varying vec2 vUv;
|
|
5
5
|
varying vec3 vNormal;
|
|
@@ -17,8 +17,8 @@ void main() {
|
|
|
17
17
|
* - the Sun's light reddens towards the terminator and the twilight has a warm band on the lit side and a blue hour beyond it;
|
|
18
18
|
* - the ocean is a clearer blue, with a hard glint under the Sun, a broad sheen round it, and the sky reflected at grazing angles; clouds hide the glint;
|
|
19
19
|
* - the clouds throw a shadow on the ground, displaced away from the Sun and longer as it gets low;
|
|
20
|
-
* - the night side has the city lights warm and softly spread, dimmed where cloud covers them
|
|
21
|
-
*
|
|
20
|
+
* - the night side has the city lights warm and softly spread, dimmed where cloud covers them.
|
|
21
|
+
* The air over it is the air program's (`air.ts`), drawn over the surface, so the surface has no rim of its own.
|
|
22
22
|
*/
|
|
23
23
|
const surfaceFrag = (tile) => /* glsl */ `
|
|
24
24
|
uniform sampler2D dayMap;
|
|
@@ -83,10 +83,6 @@ void main() {
|
|
|
83
83
|
vec3 col = mix(night, lit, day);
|
|
84
84
|
col += pow(albedo, vec3(0.75)) * boost * 0.65 * (1.0 - day);
|
|
85
85
|
|
|
86
|
-
float rim = pow(1.0 - ndv, 3.0);
|
|
87
|
-
float sunSide = 0.12 + 0.88 * smoothstep(-0.25, 0.5, ndl);
|
|
88
|
-
vec3 rimColour = mix(vec3(0.20, 0.45, 1.0), vec3(1.0, 0.45, 0.18), 0.8 * (1.0 - smoothstep(0.0, 0.30, abs(ndl))));
|
|
89
|
-
col += rimColour * rim * sunSide * 0.6;
|
|
90
86
|
gl_FragColor = vec4(col, 1.0);
|
|
91
87
|
}`;
|
|
92
88
|
export const SURFACE_FRAG = surfaceFrag(false);
|
|
@@ -131,41 +127,6 @@ void main() {
|
|
|
131
127
|
col += vec3(0.55, 0.28, 0.14) * smoothstep(-0.14, 0.0, ndl) * (1.0 - smoothstep(0.0, 0.25, ndl)) * 0.35;
|
|
132
128
|
gl_FragColor = vec4(col, a);
|
|
133
129
|
}`;
|
|
134
|
-
export const ATMOSPHERE_VERT = /* glsl */ `
|
|
135
|
-
varying vec3 vPosView;
|
|
136
|
-
varying vec3 vNormalView;
|
|
137
|
-
void main() {
|
|
138
|
-
vec4 view = modelViewMatrix * vec4(position, 1.0);
|
|
139
|
-
vPosView = view.xyz;
|
|
140
|
-
vNormalView = normalize(normalMatrix * position);
|
|
141
|
-
gl_Position = projectionMatrix * view;
|
|
142
|
-
}`;
|
|
143
|
-
export const ATMOSPHERE_FRAG = /* glsl */ `
|
|
144
|
-
uniform vec3 sunView;
|
|
145
|
-
uniform float outer;
|
|
146
|
-
uniform float ortho;
|
|
147
|
-
varying vec3 vPosView;
|
|
148
|
-
varying vec3 vNormalView;
|
|
149
|
-
void main() {
|
|
150
|
-
vec3 n = normalize(vNormalView);
|
|
151
|
-
vec3 v = ortho > 0.5 ? vec3(0.0, 0.0, 1.0) : normalize(-vPosView);
|
|
152
|
-
float nz = clamp(dot(n, v), -1.0, 1.0);
|
|
153
|
-
float rho = outer * sqrt(max(0.0, 1.0 - nz * nz));
|
|
154
|
-
float t = clamp((rho - 1.0) / (outer - 1.0), 0.0, 1.0);
|
|
155
|
-
vec2 dir = normalize(n.xy + vec2(1e-5, 0.0));
|
|
156
|
-
// the Sun's light at this point of the limb: 1 where the Sun stands behind it, 0 at the terminator, -1 on the night side
|
|
157
|
-
float toward = dot(vec3(dir, 0.0), sunView);
|
|
158
|
-
float side = smoothstep(-0.45, 0.45, toward);
|
|
159
|
-
// a thin bright layer on the limb and a wide faint halo, both fading to nothing at the outer edge
|
|
160
|
-
float limb = pow(1.0 - t, 5.0);
|
|
161
|
-
float halo = pow(1.0 - t, 2.2);
|
|
162
|
-
float glow = (limb * 0.85 + halo * 0.35) * (0.06 + 0.94 * side);
|
|
163
|
-
vec3 day = mix(vec3(0.30, 0.52, 0.95), vec3(0.50, 0.74, 1.0), limb);
|
|
164
|
-
vec3 dusk = mix(vec3(1.0, 0.42, 0.16), vec3(1.0, 0.62, 0.30), limb);
|
|
165
|
-
float band = exp(-pow(toward / 0.32, 2.0));
|
|
166
|
-
vec3 col = mix(mix(vec3(0.06, 0.12, 0.35), day, side), dusk, band * 0.85);
|
|
167
|
-
gl_FragColor = vec4(col, clamp(glow, 0.0, 1.0) * (1.0 - t));
|
|
168
|
-
}`;
|
|
169
130
|
/** The Moon and other plain bodies: a picture (or a flat colour) lit by the Sun, with a trace of light on the dark side. */
|
|
170
131
|
export const BODY_FRAG = /* glsl */ `
|
|
171
132
|
uniform sampler2D map;
|
package/dist/space/element.d.ts
CHANGED
|
@@ -155,6 +155,12 @@ export declare class ChikyuSpace extends HTMLElement {
|
|
|
155
155
|
*/
|
|
156
156
|
get meteors(): boolean;
|
|
157
157
|
set meteors(value: boolean);
|
|
158
|
+
/**
|
|
159
|
+
* How many times its real thickness the air is drawn, from 1 (the true thickness) to 5 (the attribute `air-thickness`; 3 when the page says nothing): see `<chikyu-earth-realistic>`. While it is above 1 the element says so in a line
|
|
160
|
+
* under the picture (`air-label="off"` takes the line away, for a page that says it itself).
|
|
161
|
+
*/
|
|
162
|
+
get airThickness(): number;
|
|
163
|
+
set airThickness(value: number);
|
|
158
164
|
get centre(): GeoPoint;
|
|
159
165
|
set centre(value: GeoPoint);
|
|
160
166
|
/**
|
package/dist/space/element.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { carryControls } from "@johnmorrisdotca/kazoku-ui/view-controls";
|
|
2
2
|
import { adoptStyles } from "../adopt.js";
|
|
3
|
+
import { airFor, readAirThickness } from "../realistic/air.js";
|
|
3
4
|
import { createGate, frameCap } from "../realistic/gate.js";
|
|
4
5
|
import { setThreeLoader, takeRenderer } from "../realistic/shared.js";
|
|
6
|
+
import { NOTES_STYLE, setAirNote } from "../realistic/air-note.js";
|
|
5
7
|
import { METEOR_NOTE_STYLE, prefersLessMotion, setMeteorNote } from "../meteors/note.js";
|
|
6
8
|
import { MAX_TEXTURE } from "../realistic/tiers.js";
|
|
7
9
|
import { MAX_SATELLITE_SPEED } from "../satellites/limits.js";
|
|
@@ -71,7 +73,7 @@ const readTime = (value) => {
|
|
|
71
73
|
const ms = Date.parse(value);
|
|
72
74
|
return Number.isFinite(ms) ? ms : "now";
|
|
73
75
|
};
|
|
74
|
-
const STYLE = `:host{display:block;aspect-ratio:1/1;position:relative;overflow:hidden}#stage,#labels{position:absolute;inset:0}#labels{pointer-events:none;overflow:hidden}.sp-label{position:absolute;left:0;top:0;margin:0;padding:0;border:0;background:none;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none}.sp-label:focus-visible{outline:2px solid #6cd0ff;outline-offset:2px;border-radius:4px}.sp-label::before{content:"";display:inline-block;width:5px;height:5px;margin:0 5px 1px -2px;border-radius:50%;background:#fff}.sp-label[hidden]{display:none}.sp-sat{position:absolute;left:0;top:0;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none}.sp-sat[hidden]{display:none}${METEOR_NOTE_STYLE}`;
|
|
76
|
+
const STYLE = `:host{display:block;aspect-ratio:1/1;position:relative;overflow:hidden}#stage,#labels{position:absolute;inset:0}#labels{pointer-events:none;overflow:hidden}.sp-label{position:absolute;left:0;top:0;margin:0;padding:0;border:0;background:none;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none}.sp-label:focus-visible{outline:2px solid #6cd0ff;outline-offset:2px;border-radius:4px}.sp-label::before{content:"";display:inline-block;width:5px;height:5px;margin:0 5px 1px -2px;border-radius:50%;background:#fff}.sp-label[hidden]{display:none}.sp-sat{position:absolute;left:0;top:0;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none}.sp-sat[hidden]{display:none}${METEOR_NOTE_STYLE}${NOTES_STYLE}`;
|
|
75
77
|
/**
|
|
76
78
|
* The `<chikyu-space>` custom element: the Earth, the Moon, the Sun and the planets where they are at a date and time, drawn with three.js through the shared renderer. It takes `center`, `time` (`now` or an ISO date), `speed` (1 is real time, 0 holds, 86400 is a day a second, negative runs backwards), `scale` (`compressed` or `true`), `labels` and `orbits` (`off` hides them); positions are computed in the browser by astronomy-engine, an optional peer dependency. It draws only when something changes, and nothing while it is out of sight.
|
|
77
79
|
*
|
|
@@ -97,7 +99,7 @@ const STYLE = `:host{display:block;aspect-ratio:1/1;position:relative;overflow:h
|
|
|
97
99
|
* ```
|
|
98
100
|
*/
|
|
99
101
|
export class ChikyuSpace extends HTMLElement {
|
|
100
|
-
static observedAttributes = ["cloud-drift", "camera", "earth-size", "earth-x", "earth-y", "center", "time", "speed", "scale", "labels", "orbits", "bodies", "light", "meteors", "meteors-label", "lang"];
|
|
102
|
+
static observedAttributes = ["cloud-drift", "camera", "earth-size", "earth-x", "earth-y", "center", "time", "speed", "scale", "labels", "orbits", "bodies", "light", "meteors", "meteors-label", "air-thickness", "air-label", "lang"];
|
|
101
103
|
#model = newSpaceModel();
|
|
102
104
|
#mode = "now";
|
|
103
105
|
#speed = 1;
|
|
@@ -105,6 +107,7 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
105
107
|
/** The page has set a `speed` since the element came into the page: for a reader who prefers reduced motion, that is the Play that lets meteors start. */
|
|
106
108
|
#played = false;
|
|
107
109
|
#note;
|
|
110
|
+
#airNote;
|
|
108
111
|
#gate;
|
|
109
112
|
#taken;
|
|
110
113
|
#stage;
|
|
@@ -147,11 +150,14 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
147
150
|
if (!this.hasAttribute("aria-label"))
|
|
148
151
|
this.setAttribute("aria-label", "The Earth, the Moon, the Sun and the planets in their places for the date shown");
|
|
149
152
|
const root = this.shadowRoot ?? this.attachShadow({ mode: "open" });
|
|
150
|
-
root.innerHTML = `<div id="stage"></div><div id="labels" aria-hidden="true"></div><p id="meteor-note" hidden></p>`;
|
|
153
|
+
root.innerHTML = `<div id="stage"></div><div id="labels" aria-hidden="true"></div><div id="notes"><p id="air-note" hidden></p><p id="meteor-note" hidden></p></div>`;
|
|
151
154
|
adoptStyles(root, STYLE, this.nonce);
|
|
152
155
|
this.#stage = root.getElementById("stage");
|
|
153
156
|
this.#labelBox = root.getElementById("labels");
|
|
154
157
|
this.#note = root.getElementById("meteor-note");
|
|
158
|
+
this.#airNote = root.getElementById("air-note");
|
|
159
|
+
this.#model.airThickness = readAirThickness(this.getAttribute("air-thickness"));
|
|
160
|
+
setAirNote(this.#airNote, this, this.#model.airThickness);
|
|
155
161
|
this.#played = false;
|
|
156
162
|
this.#model.meteors.on = this.#meteorsAsked();
|
|
157
163
|
this.#model.meteors.running = () => this.#speed !== 0 && document.visibilityState !== "hidden" && (this.#played || !prefersLessMotion());
|
|
@@ -171,6 +177,7 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
171
177
|
assets: taken.renderer.assets,
|
|
172
178
|
textureBase: () => this.#textureBase(),
|
|
173
179
|
cap: () => this.#textureCap(),
|
|
180
|
+
air: () => airFor(this.getAttribute("air")),
|
|
174
181
|
invalidate: () => this.#gate?.request(),
|
|
175
182
|
onError: (error) => this.#fail(error instanceof Error ? error.message : String(error)),
|
|
176
183
|
onTier: (layer, width) => {
|
|
@@ -246,8 +253,14 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
246
253
|
this.earthY = readNumber(value, 0.5, -2, 3);
|
|
247
254
|
else if (name === "meteors")
|
|
248
255
|
this.meteors = this.#meteorsAsked();
|
|
256
|
+
else if (name === "air-thickness") {
|
|
257
|
+
this.#model.airThickness = readAirThickness(value);
|
|
258
|
+
this.#gate?.request();
|
|
259
|
+
}
|
|
249
260
|
else if (name === "meteors-label" || name === "lang")
|
|
250
261
|
setMeteorNote(this.#note, this, this.#model.meteors.on);
|
|
262
|
+
if (name === "air-thickness" || name === "air-label" || name === "lang")
|
|
263
|
+
setAirNote(this.#airNote, this, this.#model.airThickness);
|
|
251
264
|
}
|
|
252
265
|
#meteorsAsked() {
|
|
253
266
|
return this.hasAttribute("meteors") && this.getAttribute("meteors") !== "off";
|
|
@@ -273,6 +286,16 @@ export class ChikyuSpace extends HTMLElement {
|
|
|
273
286
|
setMeteorNote(this.#note, this, value);
|
|
274
287
|
this.#gate?.request();
|
|
275
288
|
}
|
|
289
|
+
/**
|
|
290
|
+
* How many times its real thickness the air is drawn, from 1 (the true thickness) to 5 (the attribute `air-thickness`; 3 when the page says nothing): see `<chikyu-earth-realistic>`. While it is above 1 the element says so in a line
|
|
291
|
+
* under the picture (`air-label="off"` takes the line away, for a page that says it itself).
|
|
292
|
+
*/
|
|
293
|
+
get airThickness() {
|
|
294
|
+
return this.#model.airThickness;
|
|
295
|
+
}
|
|
296
|
+
set airThickness(value) {
|
|
297
|
+
this.setAttribute("air-thickness", String(value));
|
|
298
|
+
}
|
|
276
299
|
get centre() {
|
|
277
300
|
return { ...this.#model.centre };
|
|
278
301
|
}
|
package/dist/space/scene.d.ts
CHANGED
|
@@ -109,6 +109,8 @@ export interface SpaceModel {
|
|
|
109
109
|
};
|
|
110
110
|
/** Which way the camera is held (see `CameraMode`). */
|
|
111
111
|
camera: CameraMode;
|
|
112
|
+
/** How many times its real thickness the air is drawn, 1 to 5 (`AIR_THICKNESS_DEFAULT` until the element says otherwise); read at every draw. */
|
|
113
|
+
airThickness: number;
|
|
112
114
|
/** Degrees an hour the cloud picture is made to move eastward against the ground: 0, the default (it is one snapshot, not a forecast). */
|
|
113
115
|
cloudDrift: number;
|
|
114
116
|
/** For the `space` camera: the Earth's turn against the stars (degrees) at the moment the camera was set, so it stays in the stars while the Earth turns beneath; null until the next draw sets it. */
|
|
@@ -274,6 +276,8 @@ export interface SpaceDeps {
|
|
|
274
276
|
invalidate: () => void;
|
|
275
277
|
onError?: (error: unknown) => void;
|
|
276
278
|
onTier?: (layer: Layer, width: number) => void;
|
|
279
|
+
/** How much the air costs: `full` (12 samples along the ray and 4 toward the Sun) or `light` (6 and 2, for a small or slow device). Read once, when the scene is built. */
|
|
280
|
+
air?: () => "full" | "light";
|
|
277
281
|
/** Where each body is on the screen, in CSS pixels in the box, or null when it is behind the camera. Called at each draw. */
|
|
278
282
|
onLabels?: (places: Record<BodyName, BodyPlace | null>) => void;
|
|
279
283
|
/** Where the chosen satellite is on the screen, or null. Called at each draw while a satellite is chosen (and once when it is let go). */
|
package/dist/space/scene.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { AIR_QUALITY, AIR_THICKNESS_DEFAULT, AIR_VERT, airFrag, airTop } from "../realistic/air.js";
|
|
2
|
+
import { sphere } from "../realistic/earth.js";
|
|
3
|
+
import { BODY_FRAG, CLOUD_FRAG, GLOW_FRAG, GLOW_VERT, SURFACE_FRAG, SURFACE_VERT } from "../realistic/shaders.js";
|
|
3
4
|
import { createTextureSet } from "../realistic/textures.js";
|
|
4
5
|
import { createTrack, orbitPath, PLANETS } from "./ephemeris.js";
|
|
5
6
|
import { placeAround, placeMoon, placeSun, RADIUS } from "./scale.js";
|
|
@@ -56,6 +57,7 @@ export const newSpaceModel = () => ({
|
|
|
56
57
|
view: { yaw: 0, tilt: 0, zoom: 1 },
|
|
57
58
|
centre: { lon: 0, lat: 0 },
|
|
58
59
|
camera: "space",
|
|
60
|
+
airThickness: AIR_THICKNESS_DEFAULT,
|
|
59
61
|
cloudDrift: 0,
|
|
60
62
|
cameraSpin: null,
|
|
61
63
|
earth: { size: DEFAULT_EARTH_SIZE, x: 0.5, y: 0.5 },
|
|
@@ -161,7 +163,6 @@ export function createSpaceItem(model, deps) {
|
|
|
161
163
|
/** The Sun in the Earth's own axes (the surface program finds where a cloud's shadow falls from it). */
|
|
162
164
|
const sunLocal = { value: new three.Vector3(1, 0, 0) };
|
|
163
165
|
const cloudShift = { value: 0 };
|
|
164
|
-
const sunView = { value: new three.Vector3(1, 0, 0) };
|
|
165
166
|
const grid = sphere(three, 96, 48);
|
|
166
167
|
const solid = sphere(three, 48, 24);
|
|
167
168
|
const earthMaterial = new three.ShaderMaterial({
|
|
@@ -176,21 +177,22 @@ export function createSpaceItem(model, deps) {
|
|
|
176
177
|
transparent: true,
|
|
177
178
|
depthWrite: false,
|
|
178
179
|
});
|
|
180
|
+
// the air: light scattered once on its way through a shell 100 km thick, worked out for each pixel (the same program as the realistic Earth's), in the world's own axes
|
|
179
181
|
const atmosphereMaterial = new three.ShaderMaterial({
|
|
180
|
-
vertexShader:
|
|
181
|
-
fragmentShader:
|
|
182
|
-
uniforms: {
|
|
182
|
+
vertexShader: AIR_VERT,
|
|
183
|
+
fragmentShader: airFrag(AIR_QUALITY[deps.air?.() ?? "full"]),
|
|
184
|
+
uniforms: { sunDir: sunEarth, ortho: { value: 0 }, thick: { value: model.airThickness } },
|
|
183
185
|
transparent: true,
|
|
186
|
+
premultipliedAlpha: true,
|
|
184
187
|
depthWrite: false,
|
|
185
|
-
side: three.BackSide,
|
|
186
188
|
});
|
|
187
189
|
const earth = new three.Mesh(grid, earthMaterial);
|
|
188
190
|
const clouds = new three.Mesh(grid, cloudMaterial);
|
|
189
191
|
clouds.scale.setScalar(1.006);
|
|
190
192
|
clouds.renderOrder = 3;
|
|
191
193
|
const glow = new three.Mesh(grid, atmosphereMaterial);
|
|
192
|
-
glow.scale.setScalar(
|
|
193
|
-
glow.renderOrder =
|
|
194
|
+
glow.scale.setScalar(airTop(model.airThickness));
|
|
195
|
+
glow.renderOrder = 4;
|
|
194
196
|
glow.frustumCulled = false;
|
|
195
197
|
const moonSun = { value: new three.Vector3(1, 0, 0) };
|
|
196
198
|
const moon = new three.Mesh(solid, new three.ShaderMaterial({ vertexShader: SURFACE_VERT, fragmentShader: BODY_FRAG, uniforms: { map: uniform.moon, tint: { value: new three.Color("#bbbbbb") }, textured: { value: 1 }, sunDir: moonSun, ambient: { value: 0.03 } } }));
|
|
@@ -309,6 +311,8 @@ export function createSpaceItem(model, deps) {
|
|
|
309
311
|
sunLocal.value.set(toSun[0] * Math.cos(back) + toSun[2] * Math.sin(back), toSun[1], -toSun[0] * Math.sin(back) + toSun[2] * Math.cos(back));
|
|
310
312
|
}
|
|
311
313
|
cloudShift.value = -(((model.time / 3_600_000) * model.cloudDrift) % 360) / 360;
|
|
314
|
+
atmosphereMaterial.uniforms["thick"].value = model.airThickness;
|
|
315
|
+
glow.scale.setScalar(airTop(model.airThickness));
|
|
312
316
|
earthMaterial.uniforms["lights"].value = model.light === "lit" ? 0 : 1;
|
|
313
317
|
earthMaterial.uniforms["boost"].value = model.light === "boost" ? 1 : 0;
|
|
314
318
|
// the Moon, with its near side to the Earth
|
|
@@ -483,7 +487,6 @@ export function createSpaceItem(model, deps) {
|
|
|
483
487
|
// always lit: the light comes from the camera's side of the Earth (the Sun, Moon and planets stay where they are)
|
|
484
488
|
if (model.light === "lit")
|
|
485
489
|
sunEarth.value.set(camera.position.x, camera.position.y, camera.position.z).normalize();
|
|
486
|
-
sunView.value.copy(sunEarth.value).transformDirection(camera.matrixWorldInverse);
|
|
487
490
|
const pose = model.pose;
|
|
488
491
|
pose.p[0] = camera.position.x;
|
|
489
492
|
pose.p[1] = camera.position.y;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnmorrisdotca/chikyu-earth",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.29.0",
|
|
4
4
|
"description": "Chikyu Earth 地球 — A line-drawn globe for the web: country outlines that turn at the Earth's own rate, centred on where you are, with an optional realistic Earth from space (three.js), the Sun, Moon and planets, satellites on their orbits, and markers for any place. A web component and an SVG string.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"earth",
|