@johnmorrisdotca/chikyu-earth 0.60.2 → 0.62.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 +20 -1
- package/README.md +2 -2
- package/dist/markers/index.d.ts +2 -2
- package/dist/markers/index.js +1 -1
- package/dist/markers/place-layer.d.ts +48 -2
- package/dist/markers/place-layer.js +135 -16
- package/dist/markers/places.d.ts +70 -4
- package/dist/markers/places.js +70 -7
- package/dist/realistic/cloud-fade.d.ts +22 -0
- package/dist/realistic/cloud-fade.js +44 -0
- package/dist/realistic/earth.d.ts +3 -0
- package/dist/realistic/earth.js +6 -1
- package/dist/realistic/element-base.d.ts +38 -1
- package/dist/realistic/element-base.js +70 -7
- package/dist/realistic/shaders.d.ts +1 -1
- package/dist/realistic/shaders.js +10 -0
- package/dist/space/element-base.d.ts +124 -2
- package/dist/space/element-base.js +273 -32
- package/dist/space/fly.d.ts +292 -0
- package/dist/space/fly.js +293 -0
- package/dist/space/index.d.ts +1 -0
- package/dist/space/index.js +1 -0
- package/dist/space/scene.d.ts +5 -0
- package/dist/space/scene.js +12 -3
- package/package.json +2 -2
package/dist/markers/places.js
CHANGED
|
@@ -33,6 +33,9 @@ const EDGE = 0.02;
|
|
|
33
33
|
const FADE = 0.12;
|
|
34
34
|
const MARGIN = 60;
|
|
35
35
|
const SIZES = { here: { length: 46, ring: 9 }, favourite: { length: 28, ring: 6 } };
|
|
36
|
+
/** What a `small` place's stick and ring are of the kind's own. */
|
|
37
|
+
export const SMALL_LENGTH = 0.55;
|
|
38
|
+
export const SMALL_RING = 0.7;
|
|
36
39
|
const isObject = (value) => typeof value === "object" && value !== null;
|
|
37
40
|
/** A colour a page may give a place: a hex colour, `rgb()`/`hsl()` with numbers only, or a colour's name. Anything else is left out, so no other CSS gets in. */
|
|
38
41
|
const COLOR = /^(?:#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})|(?:rgb|hsl)a?\([0-9.,%\s/+-]{1,60}\)|[a-z]{3,24})$/i;
|
|
@@ -48,8 +51,8 @@ const nightOf = (cosine) => {
|
|
|
48
51
|
};
|
|
49
52
|
/**
|
|
50
53
|
* The places of a list a page handed over, made safe to draw: each needs a longitude from -180 to 180 and a latitude from -90 to 90; one without an `id` is given its place in the list, a
|
|
51
|
-
* label is cut to 80 letters, a kind that is not `here` is `favourite`, and a colour is kept only when it is a hex colour, `rgb()` or `hsl()` with numbers, or a colour's name.
|
|
52
|
-
* and at most {@link MAX_PLACES} are kept.
|
|
54
|
+
* label is cut to 80 letters, a kind that is not `here` is `favourite`, and a colour is kept only when it is a hex colour, `rgb()` or `hsl()` with numbers, or a colour's name. A `layer` is cut to 40 letters,
|
|
55
|
+
* a `size` is kept only when it is `small`, a `look` only when it is one of {@link PLACE_LOOKS} and a `namePriority` only when it is `low`. Anything else is left out, and at most {@link MAX_PLACES} are kept.
|
|
53
56
|
*
|
|
54
57
|
* @param list - What the page gave: an array of places, or anything.
|
|
55
58
|
* @returns The places to draw.
|
|
@@ -58,7 +61,7 @@ const nightOf = (cosine) => {
|
|
|
58
61
|
* ```ts
|
|
59
62
|
* import { cleanPlaces } from "@johnmorrisdotca/chikyu-earth/markers";
|
|
60
63
|
*
|
|
61
|
-
* console.log(cleanPlaces([{ lon: 2.35, lat: 48.86, label: "Paris", color: "#e8475f" }, { lon: 500, lat: 0 }]));
|
|
64
|
+
* console.log(cleanPlaces([{ lon: 2.35, lat: 48.86, label: "Paris", color: "#e8475f" }, { lon: 500, lat: 0 }, { id: "yvr", lon: -123.18, lat: 49.19, layer: "airports", size: "small", look: "ring" }]));
|
|
62
65
|
* ```
|
|
63
66
|
*/
|
|
64
67
|
export function cleanPlaces(list) {
|
|
@@ -79,6 +82,14 @@ export function cleanPlaces(list) {
|
|
|
79
82
|
place.label = item["label"].trim().slice(0, 80);
|
|
80
83
|
if (typeof item["color"] === "string" && COLOR.test(item["color"].trim()))
|
|
81
84
|
place.color = item["color"].trim();
|
|
85
|
+
if (typeof item["layer"] === "string" && item["layer"].trim())
|
|
86
|
+
place.layer = item["layer"].trim().slice(0, 40);
|
|
87
|
+
if (item["size"] === "small")
|
|
88
|
+
place.size = "small";
|
|
89
|
+
if (PLACE_LOOKS.includes(item["look"]))
|
|
90
|
+
place.look = item["look"];
|
|
91
|
+
if (item["namePriority"] === "low")
|
|
92
|
+
place.namePriority = "low";
|
|
82
93
|
out.push(place);
|
|
83
94
|
}
|
|
84
95
|
return out;
|
|
@@ -172,7 +183,7 @@ export function orthoView(pose) {
|
|
|
172
183
|
*
|
|
173
184
|
* @param places - The places, as {@link cleanPlaces} makes them.
|
|
174
185
|
* @param view - The picture.
|
|
175
|
-
* @param look - `beam`, `pin` or `ring
|
|
186
|
+
* @param look - `beam`, `pin` or `ring`, for each place that has no `look` of its own; a `small` place has a shorter stick and a smaller ring.
|
|
176
187
|
* @param options - The size of each name, boxes already used, the most names (16) and where the Sun is overhead.
|
|
177
188
|
* @returns The markers to draw and where the names go.
|
|
178
189
|
*
|
|
@@ -197,6 +208,8 @@ export function layoutPlaces(places, view, look, options = {}) {
|
|
|
197
208
|
if (point.x < -MARGIN || point.y < -MARGIN || point.x > view.width + MARGIN || point.y > view.height + MARGIN)
|
|
198
209
|
continue;
|
|
199
210
|
const size = SIZES[place.kind === "here" ? "here" : "favourite"];
|
|
211
|
+
const small = place.size === "small";
|
|
212
|
+
const own = place.look ?? look;
|
|
200
213
|
const side = Math.min(1, Math.hypot(point.upX, point.upY));
|
|
201
214
|
// straight up from the ground as seen, bent towards the top of the screen as the reader comes to look straight down on it
|
|
202
215
|
let dx = point.upX;
|
|
@@ -210,7 +223,7 @@ export function layoutPlaces(places, view, look, options = {}) {
|
|
|
210
223
|
dx /= norm;
|
|
211
224
|
dy /= norm;
|
|
212
225
|
}
|
|
213
|
-
const length =
|
|
226
|
+
const length = own === "ring" ? 0 : size.length * (small ? SMALL_LENGTH : 1) * (0.55 + 0.45 * side);
|
|
214
227
|
const shape = {
|
|
215
228
|
index,
|
|
216
229
|
x: point.x,
|
|
@@ -221,14 +234,14 @@ export function layoutPlaces(places, view, look, options = {}) {
|
|
|
221
234
|
length,
|
|
222
235
|
ringAngle: side > 1e-4 ? Math.atan2(point.upX, -point.upY) / RAD : 0,
|
|
223
236
|
squash: Math.max(0.08, Math.min(1, point.facing)),
|
|
224
|
-
ring: size.ring,
|
|
237
|
+
ring: size.ring * (small ? SMALL_RING : 1),
|
|
225
238
|
opacity: Math.min(1, (point.facing - EDGE) / FADE),
|
|
226
239
|
night: sun ? nightOf(dotUnit(place.lon, place.lat, sun)) : 0,
|
|
227
240
|
};
|
|
228
241
|
shapes.push(shape);
|
|
229
242
|
const box = place.label ? options.size?.(place, index) : null;
|
|
230
243
|
if (box) {
|
|
231
|
-
items.push({ x: shape.tipX, y: shape.tipY, r:
|
|
244
|
+
items.push({ x: shape.tipX, y: shape.tipY, r: own === "ring" ? shape.ring : 3, w: box.width, h: box.height, priority: place.kind === "here" ? 1 : 0 });
|
|
232
245
|
named.push(index);
|
|
233
246
|
}
|
|
234
247
|
}
|
|
@@ -340,3 +353,53 @@ export function groupPlaces(places, cell) {
|
|
|
340
353
|
* ```
|
|
341
354
|
*/
|
|
342
355
|
export const readPlaceGroups = (value) => (value ?? "").trim().toLowerCase() !== "off";
|
|
356
|
+
/**
|
|
357
|
+
* Which layers of places are shown (the attribute `place-layers`): a JSON object of layer names to true or false, such as `{"harbours":false}`. A layer that is not named is shown, and so is a place with no layer. Anything
|
|
358
|
+
* that is not an object of that kind is no switches.
|
|
359
|
+
*
|
|
360
|
+
* @param value - The attribute's text, or null.
|
|
361
|
+
* @returns The switches, a name to whether it is shown.
|
|
362
|
+
*
|
|
363
|
+
* @example
|
|
364
|
+
* ```ts
|
|
365
|
+
* import { readPlaceLayers } from "@johnmorrisdotca/chikyu-earth/markers";
|
|
366
|
+
*
|
|
367
|
+
* console.log(readPlaceLayers('{"harbours":false,"airports":true}')); // { harbours: false, airports: true }
|
|
368
|
+
* ```
|
|
369
|
+
*/
|
|
370
|
+
export function readPlaceLayers(value) {
|
|
371
|
+
if (!value)
|
|
372
|
+
return {};
|
|
373
|
+
try {
|
|
374
|
+
const parsed = JSON.parse(value);
|
|
375
|
+
if (!isObject(parsed))
|
|
376
|
+
return {};
|
|
377
|
+
const out = {};
|
|
378
|
+
for (const [name, on] of Object.entries(parsed))
|
|
379
|
+
if (typeof on === "boolean")
|
|
380
|
+
out[name] = on;
|
|
381
|
+
return out;
|
|
382
|
+
}
|
|
383
|
+
catch {
|
|
384
|
+
return {};
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* The places whose layer is shown: a place with no layer is always in, and a layer is in unless `layers` says `false` for it. The list is returned as it came when nothing is left out.
|
|
389
|
+
*
|
|
390
|
+
* @param places - The places, as {@link cleanPlaces} makes them.
|
|
391
|
+
* @param layers - The switches, a layer's name to whether it is shown ({@link readPlaceLayers}).
|
|
392
|
+
* @returns The places to draw.
|
|
393
|
+
*
|
|
394
|
+
* @example
|
|
395
|
+
* ```ts
|
|
396
|
+
* import { shownPlaces } from "@johnmorrisdotca/chikyu-earth/markers";
|
|
397
|
+
*
|
|
398
|
+
* const places = [{ id: "yvr", lon: -123.18, lat: 49.19, layer: "airports" }, { id: "cavan", lon: -123.1, lat: 49.29, layer: "harbours" }, { id: "me", lon: -79.4, lat: 43.7 }];
|
|
399
|
+
* console.log(shownPlaces(places, { harbours: false }).map((place) => place.id)); // ["yvr", "me"]
|
|
400
|
+
* ```
|
|
401
|
+
*/
|
|
402
|
+
export function shownPlaces(places, layers) {
|
|
403
|
+
const shown = places.filter((place) => !place.layer || layers[place.layer] !== false);
|
|
404
|
+
return shown.length === places.length ? places : shown;
|
|
405
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** The `cloud-fade` default: the texel width in device pixels at which the clouds are gone. 32 pixels of a 2048 texel is 0.6 km of ground a pixel, and the fade starts at 2.4 km a pixel; it keeps the clouds on the horizon seen from a low orbit. */
|
|
2
|
+
export declare const CLOUD_FADE_DEFAULT = 32;
|
|
3
|
+
/** The fade starts at this share of the width that ends it. */
|
|
4
|
+
export declare const CLOUD_FADE_START = 0.25;
|
|
5
|
+
/** The width of the finest cloud picture, in texels round the Earth. */
|
|
6
|
+
export declare const CLOUD_WIDTH: number;
|
|
7
|
+
/**
|
|
8
|
+
* A `cloud-fade` attribute: `off` or `0` is 0 (no fade), a number is the texel width in device pixels at which the clouds are gone (1 to 1000), anything else or leaving it out is the default.
|
|
9
|
+
*
|
|
10
|
+
* @param value - The attribute's text, or null.
|
|
11
|
+
* @returns The width, or 0 for off.
|
|
12
|
+
*/
|
|
13
|
+
export declare function readCloudFade(value: string | null): number;
|
|
14
|
+
/**
|
|
15
|
+
* How much of the clouds to show: 1 while a texel of the cloud picture is no wider than a quarter of `gone` device pixels, 0 from `gone` on, a smooth step between.
|
|
16
|
+
*
|
|
17
|
+
* @param radiusPx - The Earth's radius in device pixels at the nearest ground, as the map tiles read it.
|
|
18
|
+
* @param gone - The texel width in device pixels at which the clouds are gone; 0 or less turns the fade off.
|
|
19
|
+
* @param width - Texels round the Earth in the cloud picture.
|
|
20
|
+
* @returns A strength from 0 to 1.
|
|
21
|
+
*/
|
|
22
|
+
export declare function cloudFade(radiusPx: number, gone: number, width?: number): number;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// The clouds give way to the ground when the view is close. The cloud picture is one whole-Earth map at most 2048 pixels across (about 20 km a texel), so from a few hundred kilometres
|
|
2
|
+
// up its texels are many pixels wide and it blurs the sharp ground under it. Its strength goes from 1 to 0 as a texel grows from a few device pixels to many. The figure is the one the
|
|
3
|
+
// map tiles use (`tileLevel`): the disc's radius in device pixels, so a texel is `2 * PI * radiusPx / width` pixels. A state of the view, not of time: it changes only when the view does.
|
|
4
|
+
// The realistic Earth is orthographic, so one radius serves the whole disc and the clouds' opacity is set from it. The space view is in perspective: the cloud shader does the same sum for each fragment with
|
|
5
|
+
// `radiusPx = focal / distance` from the camera to that fragment, so the ground under the camera goes sharp while the far ground and the horizon keep their clouds.
|
|
6
|
+
import { TIERS } from "./tiers.js";
|
|
7
|
+
/** The `cloud-fade` default: the texel width in device pixels at which the clouds are gone. 32 pixels of a 2048 texel is 0.6 km of ground a pixel, and the fade starts at 2.4 km a pixel; it keeps the clouds on the horizon seen from a low orbit. */
|
|
8
|
+
export const CLOUD_FADE_DEFAULT = 32;
|
|
9
|
+
/** The fade starts at this share of the width that ends it. */
|
|
10
|
+
export const CLOUD_FADE_START = 0.25;
|
|
11
|
+
/** The width of the finest cloud picture, in texels round the Earth. */
|
|
12
|
+
export const CLOUD_WIDTH = TIERS.clouds[TIERS.clouds.length - 1];
|
|
13
|
+
/**
|
|
14
|
+
* A `cloud-fade` attribute: `off` or `0` is 0 (no fade), a number is the texel width in device pixels at which the clouds are gone (1 to 1000), anything else or leaving it out is the default.
|
|
15
|
+
*
|
|
16
|
+
* @param value - The attribute's text, or null.
|
|
17
|
+
* @returns The width, or 0 for off.
|
|
18
|
+
*/
|
|
19
|
+
export function readCloudFade(value) {
|
|
20
|
+
if (value === null)
|
|
21
|
+
return CLOUD_FADE_DEFAULT;
|
|
22
|
+
if (value.trim() === "off")
|
|
23
|
+
return 0;
|
|
24
|
+
const width = Number(value);
|
|
25
|
+
if (value.trim() === "" || !Number.isFinite(width) || width < 0)
|
|
26
|
+
return CLOUD_FADE_DEFAULT;
|
|
27
|
+
return width === 0 ? 0 : Math.min(1000, Math.max(1, width));
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* How much of the clouds to show: 1 while a texel of the cloud picture is no wider than a quarter of `gone` device pixels, 0 from `gone` on, a smooth step between.
|
|
31
|
+
*
|
|
32
|
+
* @param radiusPx - The Earth's radius in device pixels at the nearest ground, as the map tiles read it.
|
|
33
|
+
* @param gone - The texel width in device pixels at which the clouds are gone; 0 or less turns the fade off.
|
|
34
|
+
* @param width - Texels round the Earth in the cloud picture.
|
|
35
|
+
* @returns A strength from 0 to 1.
|
|
36
|
+
*/
|
|
37
|
+
export function cloudFade(radiusPx, gone, width = CLOUD_WIDTH) {
|
|
38
|
+
if (!(gone > 0))
|
|
39
|
+
return 1;
|
|
40
|
+
const texel = (2 * Math.PI * radiusPx) / width;
|
|
41
|
+
const from = gone * CLOUD_FADE_START;
|
|
42
|
+
const t = Math.min(1, Math.max(0, (texel - from) / (gone - from)));
|
|
43
|
+
return 1 - t * t * (3 - 2 * t);
|
|
44
|
+
}
|
|
@@ -82,6 +82,9 @@ export interface EarthModel {
|
|
|
82
82
|
airThickness: number;
|
|
83
83
|
/** 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. */
|
|
84
84
|
cloudDrift: number;
|
|
85
|
+
/** The texel width in device pixels at which the clouds are gone (`cloud-fade`), 0 for no fade; and the share of the clouds shown at the last draw. */
|
|
86
|
+
cloudFade: number;
|
|
87
|
+
cloudShown: number;
|
|
85
88
|
/** For the `space` camera: the Earth's turn against the stars (degrees) when the camera was set; null until the next draw sets it. */
|
|
86
89
|
cameraSpin: number | null;
|
|
87
90
|
/** Game seconds a second (the clock's speed): the satellites are placed from it. */
|
package/dist/realistic/earth.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { HOME_VIEW, lookAt } from "../view.js";
|
|
2
2
|
import { AIR_QUALITY, AIR_THICKNESS_DEFAULT, AIR_VERT, airFrag, airTop } from "./air.js";
|
|
3
3
|
import { CLOUD_FRAG, SURFACE_FRAG, SURFACE_VERT } from "./shaders.js";
|
|
4
|
+
import { cloudFade, CLOUD_FADE_DEFAULT } from "./cloud-fade.js";
|
|
4
5
|
import { newLightFade, stepLightFade } from "./light-fade.js";
|
|
5
6
|
import { prefersLessMotion } from "../meteors/note.js";
|
|
6
7
|
import { greenwichSidereal, subsolarPoint, unitVector } from "./sun.js";
|
|
@@ -49,6 +50,8 @@ export const newModel = () => ({
|
|
|
49
50
|
camera: "space",
|
|
50
51
|
airThickness: AIR_THICKNESS_DEFAULT,
|
|
51
52
|
cloudDrift: 0,
|
|
53
|
+
cloudFade: CLOUD_FADE_DEFAULT,
|
|
54
|
+
cloudShown: 1,
|
|
52
55
|
cameraSpin: null,
|
|
53
56
|
speed: 1,
|
|
54
57
|
satellites: newSatelliteState(),
|
|
@@ -247,12 +250,14 @@ export function createEarthItem(model, deps) {
|
|
|
247
250
|
sunDir.value.set(0, 0, 1);
|
|
248
251
|
}
|
|
249
252
|
cloudShift.value = -(((model.time / 3_600_000) * model.cloudDrift) % 360) / 360;
|
|
250
|
-
clouds.visible = model.clouds;
|
|
251
253
|
atmosphere.uniforms["thick"].value = model.airThickness;
|
|
252
254
|
glow.scale.setScalar(airTop(model.airThickness));
|
|
253
255
|
surface.uniforms["lights"].value = model.lights ? 1 - fade.mix : 0;
|
|
254
256
|
surface.uniforms["boost"].value = model.light === "boost" ? 1 : 0;
|
|
255
257
|
const radius = discRadius(size.width, size.height, view.zoom);
|
|
258
|
+
model.cloudShown = cloudFade(radius * model.ratio(), model.cloudFade);
|
|
259
|
+
cloudMaterial.uniforms["opacity"].value = 0.9 * model.cloudShown;
|
|
260
|
+
clouds.visible = model.clouds && model.cloudShown > 0;
|
|
256
261
|
camera.left = (-size.width / 2 - view.panX) / radius;
|
|
257
262
|
camera.right = (size.width / 2 - view.panX) / radius;
|
|
258
263
|
camera.top = (size.height / 2 + view.panY) / radius;
|
|
@@ -204,7 +204,8 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
|
|
|
204
204
|
* is a ring on the ground, all of them one draw call, and places that crowd are gathered into one ring with their count. They turn with the Earth, are hidden on its far side, are dimmer on its night side
|
|
205
205
|
* and keep their size in pixels at any zoom. Names never overlap one another; one with no room is left out. The element stores nothing and sends nothing: the page hands the places over and keeps them where
|
|
206
206
|
* it likes. Setting the property writes the attribute; at most `MAX_PLACES` are drawn. Nothing is drawn again at rest: the pulse is the page's own animation, stopped out of sight and for a reader who asked
|
|
207
|
-
* for less motion.
|
|
207
|
+
* for less motion. A place may also have a `layer` (shown or hidden with `place-layers`), a `size` (`small`), a `look` of its own (over `places-look`) and a `namePriority` (`low` lays its name after the cities'
|
|
208
|
+
* names). A press on a place sends `chikyu-place-click` with `detail: { id, kind, layer, label, lon, lat, x, y }`.
|
|
208
209
|
*/
|
|
209
210
|
get places(): Place[];
|
|
210
211
|
set places(value: readonly Place[]);
|
|
@@ -268,6 +269,39 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
|
|
|
268
269
|
*/
|
|
269
270
|
get placeGroups(): boolean;
|
|
270
271
|
set placeGroups(value: boolean);
|
|
272
|
+
/**
|
|
273
|
+
* Which layers of places are shown (the attribute `place-layers`, a JSON object of a layer's name to true or false): a place whose `layer` is named `false` is left out, and so is its name; any other place, and any layer not
|
|
274
|
+
* named, is shown. The page hands over every place once and switches the layers, instead of building a list for each switch. Setting the property writes the attribute; an empty object takes it away.
|
|
275
|
+
* `stats.places.hidden` counts the places left out.
|
|
276
|
+
*
|
|
277
|
+
* @example
|
|
278
|
+
* ```ts no-run
|
|
279
|
+
* import type { ChikyuEarthRealistic } from "@johnmorrisdotca/chikyu-earth/realistic/element";
|
|
280
|
+
*
|
|
281
|
+
* const earth = document.querySelector("chikyu-earth-realistic") as ChikyuEarthRealistic;
|
|
282
|
+
* earth.placeLayers = { harbours: false };
|
|
283
|
+
* earth.getAttribute("place-layers"); // '{"harbours":false}'
|
|
284
|
+
* earth.setPlaceLayer("harbours", true);
|
|
285
|
+
* earth.placeLayers; // { harbours: true }
|
|
286
|
+
* ```
|
|
287
|
+
*/
|
|
288
|
+
get placeLayers(): Record<string, boolean>;
|
|
289
|
+
set placeLayers(value: Readonly<Record<string, boolean>>);
|
|
290
|
+
/**
|
|
291
|
+
* Show or hide one layer of places, leaving the others as they are: the same as setting `placeLayers` with that layer changed.
|
|
292
|
+
*
|
|
293
|
+
* @param name - The layer's name, as in a place's `layer`.
|
|
294
|
+
* @param shown - Whether its places are shown.
|
|
295
|
+
*
|
|
296
|
+
* @example
|
|
297
|
+
* ```ts no-run
|
|
298
|
+
* import type { ChikyuEarthRealistic } from "@johnmorrisdotca/chikyu-earth/realistic/element";
|
|
299
|
+
*
|
|
300
|
+
* const earth = document.querySelector("chikyu-earth-realistic") as ChikyuEarthRealistic;
|
|
301
|
+
* earth.setPlaceLayer("airports", false);
|
|
302
|
+
* ```
|
|
303
|
+
*/
|
|
304
|
+
setPlaceLayer(name: string, shown: boolean): void;
|
|
271
305
|
/** How the places are drawn (the attribute `places-look`): `beam` (a light rising out of the ground with a ring at its foot, the default), `pin` (a thin stick with a round head) or `ring` (only the ring on the ground). */
|
|
272
306
|
get placesLook(): PlaceLook;
|
|
273
307
|
set placesLook(value: PlaceLook);
|
|
@@ -389,6 +423,8 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
|
|
|
389
423
|
mix: number;
|
|
390
424
|
fading: boolean;
|
|
391
425
|
};
|
|
426
|
+
/** The share of the clouds shown at the last draw, 1 to 0: they give way to the ground as the cloud picture's texels grow past a few device pixels (`cloud-fade`). The disc is orthographic, so it is the same over the whole disc. */
|
|
427
|
+
cloudFade: number;
|
|
392
428
|
/** The page's paths: asked for, drawn (with the chosen satellite's own), left out over the cap of 16, unmatched, whether the chosen satellite's own orbit is drawn, draw calls they took at the last draw (0 or 1), the path under the mouse and the `chikyu-path-click` events sent. */
|
|
393
429
|
paths: PathStats;
|
|
394
430
|
draws: number;
|
|
@@ -441,6 +477,7 @@ export declare class ChikyuEarthRealistic extends HTMLElement {
|
|
|
441
477
|
/** The places: how many were handed over, how many are drawn and named at the last draw, and how many times they were laid out. `sprites` is the rings in the picture's one draw call (0 when it cannot draw them); `dots` is the circles drawn in the page instead. */
|
|
442
478
|
places: {
|
|
443
479
|
places: number;
|
|
480
|
+
hidden: number;
|
|
444
481
|
shown: number;
|
|
445
482
|
labels: number;
|
|
446
483
|
renders: number;
|
|
@@ -22,10 +22,10 @@ import { folderSource } from "../door/map.js";
|
|
|
22
22
|
import { ownCredit } from "../door/own.js";
|
|
23
23
|
import { BODY_LABEL_ATTRIBUTES, bodyLabelText, loadMichroma, readBodyLabel } from "./body-label.js";
|
|
24
24
|
import { createSkyHost, SKY_ATTRIBUTES, SKY_STYLE } from "../sky/host.js";
|
|
25
|
-
import { cleanPlaces, orthoView, readPlaceGroups, readPlaces } from "../markers/places.js";
|
|
25
|
+
import { cleanPlaces, orthoView, readPlaceGroups, readPlaceLayers, readPlaces } from "../markers/places.js";
|
|
26
26
|
import { readHereCity } from "../markers/here-city.js";
|
|
27
27
|
import { createHereCity } from "../markers/here-city-host.js";
|
|
28
|
-
import { createPlaceLayer, PLACE_STYLE, placesLostNotice, readPlaceLook } from "../markers/place-layer.js";
|
|
28
|
+
import { createPlaceLayer, PLACE_STYLE, placeClick, placesLostNotice, readPlaceLook } from "../markers/place-layer.js";
|
|
29
29
|
import { aimAt, findPlace, glideView } from "../markers/go-to-place.js";
|
|
30
30
|
import { subsolarPoint } from "./sun.js";
|
|
31
31
|
import { CITY_NAMES_ATTRIBUTES, CITY_NAMES_STYLE, createCityHost } from "../cities/host.js";
|
|
@@ -43,6 +43,7 @@ import { framesPerSecond, readSmoothFps, smoothCap, SMOOTH_UP_TO, waitFor, watch
|
|
|
43
43
|
import { setSharedRenderer, setThreeLoader, takeRenderer } from "./shared.js";
|
|
44
44
|
export { setSharedRenderer, setThreeLoader };
|
|
45
45
|
import { MAX_TEXTURE, TIERS } from "./tiers.js";
|
|
46
|
+
import { readCloudFade } from "./cloud-fade.js";
|
|
46
47
|
import { mayWriteZoomMax, raisedZoomMax } from "./zoom-reach.js";
|
|
47
48
|
const STYLE = ":host{display:block;aspect-ratio:1/1;position:relative;isolation:isolate}" + IMMERSIVE_STYLE + "#stage,#overlay{position:absolute;inset:0}#overlay{pointer-events: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;pointer-events:none}.sp-sat[hidden]{display:none}.sp-sat[data-hover]{transition:opacity 180ms linear}@media (prefers-reduced-motion: reduce){.sp-sat[data-hover]{transition:none}}" + PLACE_STYLE + SKY_STYLE + COUNTRY_NAMES_STYLE + SEA_NAMES_STYLE + CITY_NAMES_STYLE + METEOR_NOTE_STYLE + NOTES_STYLE;
|
|
48
49
|
const RAD = Math.PI / 180;
|
|
@@ -166,7 +167,7 @@ export const readTime = (value) => {
|
|
|
166
167
|
* ```
|
|
167
168
|
*/
|
|
168
169
|
export class ChikyuEarthRealistic extends HTMLElement {
|
|
169
|
-
static observedAttributes = ["cloud-drift", "center", "time", "speed", "clouds", "lights", "light", "live-seconds", "smooth-fps", "tiles", "tiles-finer", "tiles-finer-layer", "tiles-finer-date", "tiles-finer-timeout", "data", "camera", "immersive", "meteors", "meteors-label", "meteors-strength", ...BODY_LABEL_ATTRIBUTES, ...SKY_ATTRIBUTES, ...CITY_NAMES_ATTRIBUTES, ...BORDER_ATTRIBUTES, ...GRID_ATTRIBUTES, ...COUNTRY_NAMES_ATTRIBUTES, ...SEA_NAMES_ATTRIBUTES, "air-thickness", "air-label", "lang", "places", "places-look", "place-groups", "here-city", "route", "satellite-tint", "satellite-streak-max", "hover-path", "names-on-hover", "selected-path", "path-light", "path-hit", "path-priority", "estimate-far"];
|
|
170
|
+
static observedAttributes = ["cloud-drift", "cloud-fade", "center", "time", "speed", "clouds", "lights", "light", "live-seconds", "smooth-fps", "tiles", "tiles-finer", "tiles-finer-layer", "tiles-finer-date", "tiles-finer-timeout", "data", "camera", "immersive", "meteors", "meteors-label", "meteors-strength", ...BODY_LABEL_ATTRIBUTES, ...SKY_ATTRIBUTES, ...CITY_NAMES_ATTRIBUTES, ...BORDER_ATTRIBUTES, ...GRID_ATTRIBUTES, ...COUNTRY_NAMES_ATTRIBUTES, ...SEA_NAMES_ATTRIBUTES, "air-thickness", "air-label", "lang", "places", "places-look", "place-groups", "place-layers", "here-city", "route", "satellite-tint", "satellite-streak-max", "hover-path", "names-on-hover", "selected-path", "path-light", "path-hit", "path-priority", "estimate-far"];
|
|
170
171
|
#model = newModel();
|
|
171
172
|
#paint = createPaintState();
|
|
172
173
|
#mode = "now";
|
|
@@ -247,6 +248,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
247
248
|
this.#model.light = readLight(this.getAttribute("light"));
|
|
248
249
|
this.#model.camera = readCamera(this.getAttribute("camera"));
|
|
249
250
|
this.#model.cloudDrift = readDrift(this.getAttribute("cloud-drift"));
|
|
251
|
+
this.#model.cloudFade = readCloudFade(this.getAttribute("cloud-fade"));
|
|
250
252
|
this.#model.airThickness = readAirThickness(this.getAttribute("air-thickness"));
|
|
251
253
|
this.#applyBodyLabel();
|
|
252
254
|
this.#door.book.ownOnly(this.getAttribute("data") === "own");
|
|
@@ -279,6 +281,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
279
281
|
this.#placeLayer.set(this.#here.named(this.#placeList));
|
|
280
282
|
this.#placeLayer.look = readPlaceLook(this.getAttribute("places-look"));
|
|
281
283
|
this.#placeLayer.grouping = readPlaceGroups(this.getAttribute("place-groups"));
|
|
284
|
+
this.#placeLayer.layers = readPlaceLayers(this.getAttribute("place-layers"));
|
|
282
285
|
this.#cities = createCityHost({
|
|
283
286
|
root,
|
|
284
287
|
attribute: (name) => this.getAttribute(name),
|
|
@@ -494,6 +497,10 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
494
497
|
this.#model.cloudDrift = readDrift(value);
|
|
495
498
|
this.#gate?.soon();
|
|
496
499
|
}
|
|
500
|
+
else if (name === "cloud-fade") {
|
|
501
|
+
this.#model.cloudFade = readCloudFade(value);
|
|
502
|
+
this.#gate?.soon();
|
|
503
|
+
}
|
|
497
504
|
else if (name === "meteors")
|
|
498
505
|
this.meteors = this.#meteorsAsked();
|
|
499
506
|
else if (name === "meteors-strength") {
|
|
@@ -536,6 +543,10 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
536
543
|
this.#placeLayer.grouping = readPlaceGroups(value);
|
|
537
544
|
this.#gate?.soon();
|
|
538
545
|
}
|
|
546
|
+
else if (name === "place-layers" && this.#placeLayer) {
|
|
547
|
+
this.#placeLayer.layers = readPlaceLayers(value);
|
|
548
|
+
this.#gate?.soon();
|
|
549
|
+
}
|
|
539
550
|
else if (name === "route") {
|
|
540
551
|
if (applyRoute(this.#model.route, readRoute(value)))
|
|
541
552
|
this.#gate?.soon();
|
|
@@ -692,7 +703,8 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
692
703
|
* is a ring on the ground, all of them one draw call, and places that crowd are gathered into one ring with their count. They turn with the Earth, are hidden on its far side, are dimmer on its night side
|
|
693
704
|
* and keep their size in pixels at any zoom. Names never overlap one another; one with no room is left out. The element stores nothing and sends nothing: the page hands the places over and keeps them where
|
|
694
705
|
* it likes. Setting the property writes the attribute; at most `MAX_PLACES` are drawn. Nothing is drawn again at rest: the pulse is the page's own animation, stopped out of sight and for a reader who asked
|
|
695
|
-
* for less motion.
|
|
706
|
+
* for less motion. A place may also have a `layer` (shown or hidden with `place-layers`), a `size` (`small`), a `look` of its own (over `places-look`) and a `namePriority` (`low` lays its name after the cities'
|
|
707
|
+
* names). A press on a place sends `chikyu-place-click` with `detail: { id, kind, layer, label, lon, lat, x, y }`.
|
|
696
708
|
*/
|
|
697
709
|
get places() {
|
|
698
710
|
return this.#placeList.map((place) => ({ ...place }));
|
|
@@ -826,6 +838,49 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
826
838
|
else
|
|
827
839
|
this.setAttribute("place-groups", "off");
|
|
828
840
|
}
|
|
841
|
+
/**
|
|
842
|
+
* Which layers of places are shown (the attribute `place-layers`, a JSON object of a layer's name to true or false): a place whose `layer` is named `false` is left out, and so is its name; any other place, and any layer not
|
|
843
|
+
* named, is shown. The page hands over every place once and switches the layers, instead of building a list for each switch. Setting the property writes the attribute; an empty object takes it away.
|
|
844
|
+
* `stats.places.hidden` counts the places left out.
|
|
845
|
+
*
|
|
846
|
+
* @example
|
|
847
|
+
* ```ts no-run
|
|
848
|
+
* import type { ChikyuEarthRealistic } from "@johnmorrisdotca/chikyu-earth/realistic/element";
|
|
849
|
+
*
|
|
850
|
+
* const earth = document.querySelector("chikyu-earth-realistic") as ChikyuEarthRealistic;
|
|
851
|
+
* earth.placeLayers = { harbours: false };
|
|
852
|
+
* earth.getAttribute("place-layers"); // '{"harbours":false}'
|
|
853
|
+
* earth.setPlaceLayer("harbours", true);
|
|
854
|
+
* earth.placeLayers; // { harbours: true }
|
|
855
|
+
* ```
|
|
856
|
+
*/
|
|
857
|
+
get placeLayers() {
|
|
858
|
+
return { ...(this.#placeLayer?.layers ?? readPlaceLayers(this.getAttribute("place-layers"))) };
|
|
859
|
+
}
|
|
860
|
+
set placeLayers(value) {
|
|
861
|
+
const names = Object.keys(value);
|
|
862
|
+
if (names.length === 0)
|
|
863
|
+
this.removeAttribute("place-layers");
|
|
864
|
+
else
|
|
865
|
+
this.setAttribute("place-layers", JSON.stringify(value));
|
|
866
|
+
}
|
|
867
|
+
/**
|
|
868
|
+
* Show or hide one layer of places, leaving the others as they are: the same as setting `placeLayers` with that layer changed.
|
|
869
|
+
*
|
|
870
|
+
* @param name - The layer's name, as in a place's `layer`.
|
|
871
|
+
* @param shown - Whether its places are shown.
|
|
872
|
+
*
|
|
873
|
+
* @example
|
|
874
|
+
* ```ts no-run
|
|
875
|
+
* import type { ChikyuEarthRealistic } from "@johnmorrisdotca/chikyu-earth/realistic/element";
|
|
876
|
+
*
|
|
877
|
+
* const earth = document.querySelector("chikyu-earth-realistic") as ChikyuEarthRealistic;
|
|
878
|
+
* earth.setPlaceLayer("airports", false);
|
|
879
|
+
* ```
|
|
880
|
+
*/
|
|
881
|
+
setPlaceLayer(name, shown) {
|
|
882
|
+
this.placeLayers = { ...this.placeLayers, [name]: shown };
|
|
883
|
+
}
|
|
829
884
|
/** The picture said whether it can draw the rings of the places that are not markers of their own. Without `Points` the places' layer draws them itself. */
|
|
830
885
|
#ringsDrawn(drawn) {
|
|
831
886
|
if (!this.#placeLayer || this.#placeLayer.ringsInPicture === drawn)
|
|
@@ -952,6 +1007,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
952
1007
|
#relayNames(cities, sky) {
|
|
953
1008
|
if (cities && this.#nameFrame)
|
|
954
1009
|
this.#cities?.frame(this.#nameFrame, this.#boxesBeforeCities());
|
|
1010
|
+
this.#placeLayer?.late(() => [...(this.#cities?.boxes ?? []), ...[...this.#claimedNames.values()].flat()]);
|
|
955
1011
|
this.#seaFrame();
|
|
956
1012
|
this.#countryFrame();
|
|
957
1013
|
if (sky)
|
|
@@ -962,7 +1018,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
962
1018
|
#boxesBeforeCities() {
|
|
963
1019
|
const out = this.#beforeCities;
|
|
964
1020
|
out.length = 0;
|
|
965
|
-
out.push(...(this.#placeLayer?.
|
|
1021
|
+
out.push(...(this.#placeLayer?.earlyBoxes ?? []));
|
|
966
1022
|
for (const boxes of this.#claimedNames.values())
|
|
967
1023
|
out.push(...boxes);
|
|
968
1024
|
return out;
|
|
@@ -1228,6 +1284,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
1228
1284
|
satellites: this.#satelliteStats(),
|
|
1229
1285
|
pace: { ...this.#pace },
|
|
1230
1286
|
lightFade: { mix: this.#model.lightFade.mix, fading: this.#model.lightFade.fading },
|
|
1287
|
+
cloudFade: this.#model.cloudShown,
|
|
1231
1288
|
paths: this.#pathControls?.stats() ?? emptyPathStats(),
|
|
1232
1289
|
tiles: this.#model.tiles?.stats ?? { ready: false, level: null, held: 0, shown: 0, loading: 0, failed: 0, requested: 0, heldBytes: 0, refused: 0, used: {}, finer: null, fading: false },
|
|
1233
1290
|
draws: stats?.draws ?? 0,
|
|
@@ -1237,7 +1294,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
1237
1294
|
meteors: { on: this.#model.meteors.on, strength: this.#model.meteors.strength, ...this.#model.meteors.drawn },
|
|
1238
1295
|
bodyLabel: { on: this.#model.bodyLabel.settings !== null, text: this.#model.bodyLabel.text, ...this.#model.bodyLabel.drawn },
|
|
1239
1296
|
sky: this.#sky?.stats ?? { on: false, loaded: false, names: 0, figures: 0, picked: null, pick: null, hover: null, constellations: 0, culture: "iau", renders: 0, lang: "", stars: [] },
|
|
1240
|
-
places: { ...(this.#placeLayer?.stats ?? { places: 0, shown: 0, labels: 0, renders: 0, marks: 0, groups: 0, sprites: 0, dots: 0, omitted: 0 }) },
|
|
1297
|
+
places: { ...(this.#placeLayer?.stats ?? { places: 0, hidden: 0, shown: 0, labels: 0, renders: 0, marks: 0, groups: 0, sprites: 0, dots: 0, omitted: 0 }) },
|
|
1241
1298
|
hereCity: this.#here?.stats ?? { on: false, maxKm: 0, loaded: false, pending: false },
|
|
1242
1299
|
cityNames: this.#cities?.stats ?? { on: false, max: 0, radius: 0, tiers: [], cities: 0, names: 0, renders: 0 },
|
|
1243
1300
|
borders: { ...this.#model.borders.stats, shown: { ...this.#model.borders.stats.shown }, loaded: [...this.#model.borders.stats.loaded] },
|
|
@@ -1679,7 +1736,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
1679
1736
|
#downX = 0;
|
|
1680
1737
|
#downY = 0;
|
|
1681
1738
|
#down = (event) => {
|
|
1682
|
-
if (event.button !== 0 || this.#model.satellites.groups.size === 0)
|
|
1739
|
+
if (event.button !== 0 || (this.#model.satellites.groups.size === 0 && this.#placeList.length === 0))
|
|
1683
1740
|
return;
|
|
1684
1741
|
this.#downX = event.clientX;
|
|
1685
1742
|
this.#downY = event.clientY;
|
|
@@ -1698,6 +1755,12 @@ export class ChikyuEarthRealistic extends HTMLElement {
|
|
|
1698
1755
|
if (satellite) {
|
|
1699
1756
|
claimPress(event);
|
|
1700
1757
|
this.dispatchEvent(new CustomEvent("chikyu-satellite-click", { detail: { ...satellite, info: this.satelliteInfo(satellite), ...this.#estimateOf(satellite) }, bubbles: true, composed: true }));
|
|
1758
|
+
return;
|
|
1759
|
+
}
|
|
1760
|
+
const place = this.#placeLayer?.pick(event.clientX - rect.left, event.clientY - rect.top);
|
|
1761
|
+
if (place) {
|
|
1762
|
+
claimPress(event);
|
|
1763
|
+
this.dispatchEvent(new CustomEvent("chikyu-place-click", { detail: placeClick(place, event.clientX - rect.left, event.clientY - rect.top), bubbles: true, composed: true }));
|
|
1701
1764
|
}
|
|
1702
1765
|
};
|
|
1703
1766
|
#wheel = (event) => immersiveWheel(this, event);
|
|
@@ -7,7 +7,7 @@ export declare const TILE_FRAG: string;
|
|
|
7
7
|
* `vUvG` is where the point is on the whole-Earth pictures.
|
|
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
|
-
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}";
|
|
10
|
+
export declare const CLOUD_FRAG = "\nuniform sampler2D cloudMap;\nuniform vec3 sunDir;\nuniform float shift;\nuniform float opacity;\nuniform float fadeGone;\nuniform float texelK;\nvarying vec2 vUv;\nvarying vec3 vNormal;\nvarying vec3 vWorld;\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 // a texel of the cloud picture is texelK / distance device pixels wide here; the clouds fade out as it grows (cloud-fade.ts, per fragment: the near ground goes sharp, the far ground and the horizon keep their clouds)\n if (fadeGone > 0.0 && texelK > 0.0) {\n float texel = texelK / length(vWorld - cameraPosition);\n float t = clamp((texel - fadeGone * 0.25) / (fadeGone * 0.75), 0.0, 1.0);\n a *= 1.0 - t * t * (3.0 - 2.0 * t);\n }\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
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. */
|
|
12
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}";
|
|
13
13
|
/** A flat quad facing the camera: the Sun's disc and its glow. */
|
|
@@ -1,5 +1,6 @@
|
|
|
1
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
2
|
// Colours are shaded in the textures' own (sRGB) space: a look, not a radiometric model.
|
|
3
|
+
import { CLOUD_FADE_START } from "./cloud-fade.js";
|
|
3
4
|
export const SURFACE_VERT = /* glsl */ `
|
|
4
5
|
varying vec2 vUv;
|
|
5
6
|
varying vec3 vNormal;
|
|
@@ -130,13 +131,22 @@ uniform sampler2D cloudMap;
|
|
|
130
131
|
uniform vec3 sunDir;
|
|
131
132
|
uniform float shift;
|
|
132
133
|
uniform float opacity;
|
|
134
|
+
uniform float fadeGone;
|
|
135
|
+
uniform float texelK;
|
|
133
136
|
varying vec2 vUv;
|
|
134
137
|
varying vec3 vNormal;
|
|
138
|
+
varying vec3 vWorld;
|
|
135
139
|
void main() {
|
|
136
140
|
vec3 n = normalize(vNormal);
|
|
137
141
|
float ndl = dot(n, sunDir);
|
|
138
142
|
float c = texture2D(cloudMap, vec2(vUv.x + shift, vUv.y)).r;
|
|
139
143
|
float a = smoothstep(0.28, 0.88, c) * opacity;
|
|
144
|
+
// a texel of the cloud picture is texelK / distance device pixels wide here; the clouds fade out as it grows (cloud-fade.ts, per fragment: the near ground goes sharp, the far ground and the horizon keep their clouds)
|
|
145
|
+
if (fadeGone > 0.0 && texelK > 0.0) {
|
|
146
|
+
float texel = texelK / length(vWorld - cameraPosition);
|
|
147
|
+
float t = clamp((texel - fadeGone * ${CLOUD_FADE_START}) / (fadeGone * ${1 - CLOUD_FADE_START}), 0.0, 1.0);
|
|
148
|
+
a *= 1.0 - t * t * (3.0 - 2.0 * t);
|
|
149
|
+
}
|
|
140
150
|
float day = smoothstep(-0.10, 0.25, ndl);
|
|
141
151
|
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)));
|
|
142
152
|
col += vec3(0.55, 0.28, 0.14) * smoothstep(-0.14, 0.0, ndl) * (1.0 - smoothstep(0.0, 0.25, ndl)) * 0.35;
|