@johnmorrisdotca/wakusei-planets 0.68.0 → 0.70.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 +56 -0
- package/NOTICE.md +29 -1
- package/README.md +7 -7
- package/dist/bodies/moons-jupiter.js +2 -0
- package/dist/bodies/moons-mars.js +2 -2
- package/dist/bodies/moons-neptune.js +2 -1
- package/dist/bodies/moons-pluto.js +2 -2
- package/dist/bodies/moons-saturn.js +14 -2
- package/dist/data/discovery.js +225 -0
- package/dist/data/moon-catalogue.js +15 -15
- package/dist/data/orbits.js +15 -0
- package/dist/data/shapes/amalthea.d.ts +2 -0
- package/dist/data/shapes/amalthea.js +1 -0
- package/dist/data/shapes/atlas.d.ts +2 -0
- package/dist/data/shapes/atlas.js +1 -0
- package/dist/data/shapes/calypso.d.ts +2 -0
- package/dist/data/shapes/calypso.js +1 -0
- package/dist/data/shapes/daphnis.d.ts +2 -0
- package/dist/data/shapes/daphnis.js +1 -0
- package/dist/data/shapes/deimos.d.ts +2 -0
- package/dist/data/shapes/deimos.js +1 -0
- package/dist/data/shapes/epimetheus.d.ts +2 -0
- package/dist/data/shapes/epimetheus.js +1 -0
- package/dist/data/shapes/helene.d.ts +2 -0
- package/dist/data/shapes/helene.js +1 -0
- package/dist/data/shapes/hydra.d.ts +2 -0
- package/dist/data/shapes/hydra.js +1 -0
- package/dist/data/shapes/hyperion.d.ts +2 -0
- package/dist/data/shapes/hyperion.js +1 -0
- package/dist/data/shapes/janus.d.ts +2 -0
- package/dist/data/shapes/janus.js +1 -0
- package/dist/data/shapes/larissa.d.ts +2 -0
- package/dist/data/shapes/larissa.js +1 -0
- package/dist/data/shapes/nix.d.ts +2 -0
- package/dist/data/shapes/nix.js +1 -0
- package/dist/data/shapes/pan.d.ts +2 -0
- package/dist/data/shapes/pan.js +1 -0
- package/dist/data/shapes/pandora.d.ts +2 -0
- package/dist/data/shapes/pandora.js +1 -0
- package/dist/data/shapes/phobos.d.ts +2 -0
- package/dist/data/shapes/phobos.js +1 -0
- package/dist/data/shapes/phoebe.d.ts +2 -0
- package/dist/data/shapes/phoebe.js +1 -0
- package/dist/data/shapes/prometheus.d.ts +2 -0
- package/dist/data/shapes/prometheus.js +1 -0
- package/dist/data/shapes/proteus.d.ts +2 -0
- package/dist/data/shapes/proteus.js +1 -0
- package/dist/data/shapes/telesto.d.ts +2 -0
- package/dist/data/shapes/telesto.js +1 -0
- package/dist/data/shapes/thebe.d.ts +2 -0
- package/dist/data/shapes/thebe.js +1 -0
- package/dist/discovery.d.ts +1 -1
- package/dist/earth-places.d.ts +23 -6
- package/dist/earth-places.js +29 -8
- package/dist/facts.d.ts +21 -4
- package/dist/facts.js +71 -38
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/moon-catalogue.d.ts +1 -1
- package/dist/nearest.js +2 -0
- package/dist/picture-credits.js +3 -0
- package/dist/place-search.d.ts +22 -0
- package/dist/place-search.js +25 -0
- package/dist/places/search.d.ts +19 -2
- package/dist/places/search.js +50 -1
- package/dist/scene/body-places.d.ts +98 -0
- package/dist/scene/body-places.js +112 -0
- package/dist/scene/body.js +10 -5
- package/dist/scene/earth-places.d.ts +114 -1
- package/dist/scene/earth-places.js +200 -7
- package/dist/scene/glsl.d.ts +2 -2
- package/dist/scene/glsl.js +11 -0
- package/dist/scene/look.d.ts +7 -0
- package/dist/scene/look.js +1 -0
- package/dist/scene/painter.js +18 -3
- package/dist/scene/recipes.js +6 -2
- package/dist/scene/rings.js +11 -2
- package/dist/scene/shape.d.ts +50 -0
- package/dist/scene/shape.js +110 -0
- package/dist/shape-basis.d.ts +43 -0
- package/dist/shape-basis.js +45 -0
- package/dist/space/all-moons.d.ts +6 -1
- package/dist/space/all-moons.js +5 -1
- package/dist/space/element.d.ts +52 -2
- package/dist/space/element.js +279 -33
- package/dist/space/orbit-lines.d.ts +66 -0
- package/dist/space/orbit-lines.js +118 -0
- package/dist/space/scale.d.ts +1 -1
- package/dist/space/scale.js +20 -5
- package/dist/space/scene.d.ts +13 -0
- package/dist/space/scene.js +137 -9
- package/dist/stops.js +12 -0
- package/dist/surface/element.js +3 -3
- package/dist/surface/glsl.d.ts +2 -2
- package/dist/surface/glsl.js +15 -3
- package/dist/surface/height.d.ts +7 -0
- package/dist/surface/height.js +10 -0
- package/dist/textures/deimos-1024.webp +0 -0
- package/dist/textures/deimos-512.webp +0 -0
- package/dist/textures/phobos-1024.webp +0 -0
- package/dist/textures/phobos-512.webp +0 -0
- package/dist/textures/phoebe-1024.webp +0 -0
- package/dist/textures/phoebe-512.webp +0 -0
- package/package.json +1 -1
package/dist/surface/glsl.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export declare const GROUND_VERTEX = "\nprecision highp float;\nprecision highp
|
|
|
7
7
|
/** What the ground, the rocks and their shadows all need to be lit: the Sun, the eyes, the heights and the made detail, the ground's height with the craters on it, and a point's light (a hard shadow by a march toward the Sun). */
|
|
8
8
|
export declare const LIGHT = "\nuniform vec3 uSun;\nuniform vec3 uEye;\nuniform vec2 uEyeEN;\nuniform float uExposure;\nuniform float uAlbedo;\nuniform float uMaxY; // the highest ground over the site's, for the end of a shadow's march\nuniform float uEarthshine; // the light of the sunlit ground round the shade, a small share of a lit slope's (on Mars the sky's light, a good deal more)\nuniform vec3 uTint; // the ground's colour over its grey: white on the Moon\nuniform float uShadows; // 1 for the ground to shadow itself (the default), 0 for none (a try-out)\nuniform float uSunDegrees; // the Sun's elevation in degrees\nuniform vec3 uNear; // the near march: steps, the distance it reaches in metres, the distance out to which the made craters are in it (the quality of the draw)\n\nuniform sampler2D uH0;\nuniform sampler2D uH1;\nuniform sampler2D uH2;\nuniform sampler2D uH3;\nuniform sampler2D uA0; // the ground picture on the first three levels, 0 to 1 with the middle at 0.5\nuniform sampler2D uA1;\nuniform sampler2D uA2;\nuniform float uPicture; // 1 where the picture is there\nuniform vec4 uL0; // half width, metres a sample, samples across, the distance out to which this level is used\nuniform vec4 uL1;\nuniform vec4 uL2;\nuniform vec4 uL3;\nuniform float uHmin;\nuniform float uHrange;\nuniform float uGround;\nuniform float uRadius;\n\nuniform vec2 uFarHeight; // the range the coarse level is encoded over: its minimum and its span\nfloat dec(vec4 t, vec2 hr) { return hr.x + (t.r * 255.0 * 256.0 + t.g * 255.0) / 65535.0 * hr.y; }\n\nfloat lin(sampler2D s, vec2 p, vec4 l, vec2 hr) {\n vec2 f = vec2((p.x + l.x) / l.y - 0.5, (l.x - p.y) / l.y - 0.5);\n vec2 i = floor(f);\n vec2 t = f - i;\n float st = 1.0 / l.z;\n vec2 uv = (i + 0.5) * st;\n float a = dec(texture2D(s, uv), hr);\n float b = dec(texture2D(s, uv + vec2(st, 0.0)), hr);\n float c = dec(texture2D(s, uv + vec2(0.0, st)), hr);\n float d = dec(texture2D(s, uv + vec2(st, st)), hr);\n return mix(mix(a, b, t.x), mix(c, d, t.x), t.y);\n}\n\nfloat nearest(sampler2D s, vec2 p, vec4 l, vec2 hr) {\n vec2 uv = vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z));\n return dec(texture2D(s, uv), hr);\n}\n\nbool holds(vec2 p, vec4 l, float dist) { return dist < l.w && abs(p.x) < l.x - 2.0 * l.y && abs(p.y) < l.x - 2.0 * l.y; }\n\n// the ground's height over the site's, the sphere's fall taken off; `fine` reads four samples, otherwise one\nfloat terrainY(vec2 p, float dist, bool fine) {\n float h;\n if (holds(p, uL0, dist)) h = fine ? lin(uH0, p, uL0, vec2(uHmin, uHrange)) : nearest(uH0, p, uL0, vec2(uHmin, uHrange));\n else if (holds(p, uL1, dist)) h = fine ? lin(uH1, p, uL1, vec2(uHmin, uHrange)) : nearest(uH1, p, uL1, vec2(uHmin, uHrange));\n else if (holds(p, uL2, dist)) h = fine ? lin(uH2, p, uL2, vec2(uHmin, uHrange)) : nearest(uH2, p, uL2, vec2(uHmin, uHrange));\n else h = fine ? lin(uH3, p, uL3, uFarHeight) : nearest(uH3, p, uL3, uFarHeight);\n return h - uGround - dot(p, p) / (2.0 * uRadius);\n}\n\n// the ground's own brightness at a point, from the picture of the level that serves it, 1 where it is the middle\nfloat albedoAt(vec2 p, float dist) {\n if (uPicture < 0.5) return 1.0;\n vec4 l;\n if (holds(p, uL0, dist)) { l = uL0; return 2.0 * texture2D(uA0, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n if (holds(p, uL1, dist)) { l = uL1; return 2.0 * texture2D(uA1, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n if (holds(p, uL2, dist)) { l = uL2; return 2.0 * texture2D(uA2, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n return 1.0;\n}\n\n// the measured ground's shadows, baked (scripts/make-moon-terrain.py): for a point, the elevation angle in degrees of the horizon toward the Sun, read from the finest of the three horizon maps that holds the point\nuniform sampler2D uZ0;\nuniform sampler2D uZ1;\nuniform sampler2D uZ2;\nuniform float uHzOn; // 1 where the maps are there\nuniform vec3 uHzSun; // the two directions (of 18) the Sun's azimuth lies between, and the share of the second\nuniform vec2 uHzRange; // the degrees the codes 0 and 255 stand for\n\nfloat hzSector(sampler2D s, vec2 cell, float k) {\n float slab = floor(k / 3.0);\n float ch = k - slab * 3.0;\n vec3 v = texture2D(s, vec2((cell.x + slab) / 6.0, cell.y)).rgb;\n return ch < 0.5 ? v.r : (ch < 1.5 ? v.g : v.b);\n}\n\nfloat hzFrom(sampler2D s, vec2 p, float reach) {\n vec2 cell = clamp(vec2((p.x + reach) / (2.0 * reach), (reach - p.y) / (2.0 * reach)), vec2(0.5 / 512.0), vec2(1.0 - 0.5 / 512.0));\n float code = mix(hzSector(s, cell, uHzSun.x), hzSector(s, cell, uHzSun.y), uHzSun.z);\n return uHzRange.x + code * (uHzRange.y - uHzRange.x);\n}\n\nfloat horizonAt(vec2 p) {\n if (abs(p.x) < uL0.x && abs(p.y) < uL0.x) return hzFrom(uZ0, p, uL0.x);\n if (abs(p.x) < uL1.x && abs(p.y) < uL1.x) return hzFrom(uZ1, p, uL1.x);\n if (abs(p.x) < uL2.x && abs(p.y) < uL2.x) return hzFrom(uZ2, p, uL2.x);\n return -90.0;\n}\n\n// the spacing of the level that serves a point, for the step of a slope\nfloat spacing(vec2 p, float dist) {\n if (holds(p, uL0, dist)) return uL0.y;\n if (holds(p, uL1, dist)) return uL1.y;\n if (holds(p, uL2, dist)) return uL2.y;\n return uL3.y;\n}\n\n\nuniform float uPixel; // the angle one pixel takes, radians\nuniform float uDetail; // 1 for the made detail, 0 for none\n\nuvec2 pcg2d(uvec2 v) {\n v = v * 1664525u + 1013904223u;\n v.x += v.y * 1664525u;\n v.y += v.x * 1664525u;\n v = v ^ (v >> 16u);\n v.x += v.y * 1664525u;\n v.y += v.x * 1664525u;\n v = v ^ (v >> 16u);\n return v;\n}\nfloat u24(uint h) { return float(h >> 8u) * (1.0 / 16777216.0); }\n\nuniform vec4 uKeep[6]; // the objects the made ground keeps away from: east, north, the distance inside which nothing is made, the distance outside which it all is\nuniform float uKeepCount;\nfloat keepMask(vec2 p) {\n float keep = 1.0;\n for (int i = 0; i < 6; i += 1) {\n if (float(i) >= uKeepCount) break;\n vec4 k = uKeep[i];\n float t = clamp((distance(p, k.xy) - k.z) / (k.w - k.z), 0.0, 1.0);\n keep = min(keep, t * t * (3.0 - 2.0 * t));\n }\n return keep;\n}\n\n// the made ground at a point: x the height in metres, yz the slope east and north, from every crater of every octave whose nominal diameter is over `fromD`\nvec3 madeGround(vec2 p, float fromD) {\n vec3 sum = vec3(0.0);\n for (int octave = 5; octave >= 0; octave -= 1) {\n float nominal = 0.5 * exp2(float(octave));\n float fade = clamp(nominal / fromD - 1.0, 0.0, 1.0);\n if (fade <= 0.0) break;\n float cell = 3.0 * nominal;\n ivec2 base = ivec2(floor(p / cell));\n vec2 fr = p / cell - vec2(base);\n float occ = (octave >= 3 ? 0.5 : 1.0) * 0.36 * exp2(-0.5 * float(octave));\n for (int j = -1; j <= 1; j += 1) {\n for (int i = -1; i <= 1; i += 1) {\n // a crater is kept to the middle of its cell, so a neighbour's reaches this cell only within a fifth of the edge\n if ((i == -1 && fr.x > 0.2) || (i == 1 && fr.x < 0.8) || (j == -1 && fr.y > 0.2) || (j == 1 && fr.y < 0.8)) continue;\n ivec2 c = base + ivec2(i, j);\n uvec2 ab = pcg2d(uvec2(uint(c.x), uint(c.y + octave * 7919)));\n if (u24(ab.x) >= occ) continue;\n uvec2 cd = pcg2d(uvec2(uint(c.x + 104729), uint(c.y + octave * 7919 + 15485863)));\n float diameter = nominal * (1.0 + (octave == 5 ? 0.25 : 1.0) * u24(cd.y));\n float r4 = float(ab.x & 255u) / 255.0;\n float age = 1.0 - r4 * r4 * r4 * r4;\n float radius = 0.5 * diameter;\n float vary = 0.6 + 0.4 * (float(cd.x & 255u) / 255.0);\n float depth = diameter * (0.2 - 0.17 * age) * vary;\n float rim = 0.045 * diameter * pow(1.0 - age, 1.5);\n float rimWidth = 0.22 + 0.5 * age;\n vec2 centre = vec2(float(c.x) + 0.25 + 0.5 * u24(ab.y), float(c.y) + 0.25 + 0.5 * u24(cd.x)) * cell;\n vec2 d = p - centre;\n float r = length(d);\n float x = r / radius;\n float h = 0.0;\n float dh = 0.0;\n if (x < 1.0) { float bowl = 1.0 - x * x; float pw = 1.0 + age; h = -depth * pow(bowl, pw); dh = 2.0 * depth * pw * x * pow(bowl, age); }\n float e = (x - 1.0) / rimWidth;\n float ex = exp(-e * e);\n h += rim * ex;\n dh += -2.0 * rim * e * ex / rimWidth;\n if (x > 1.0) { float t = 1.0 / x; h += 0.25 * rim * t * t * t; dh += -0.75 * rim * t * t * t * t; }\n float k = r > 1e-6 ? dh / (radius * r) : 0.0;\n sum += fade * vec3(h, k * d.x, k * d.y);\n }\n }\n }\n return sum * keepMask(p);\n}\n\nfloat vnoise(vec2 p) {\n vec2 i = floor(p);\n vec2 f = p - i;\n vec2 w = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);\n uvec2 c = uvec2(ivec2(i));\n float a = u24(pcg2d(c).x);\n float b = u24(pcg2d(c + uvec2(1u, 0u)).x);\n float cc = u24(pcg2d(c + uvec2(0u, 1u)).x);\n float d = u24(pcg2d(c + uvec2(1u, 1u)).x);\n return mix(mix(a, b, w.x), mix(cc, d, w.x), w.y);\n}\n\n// a fine roughness of the dust: two scales, as a slope (east, north), faded out where a pixel covers more than a few of its grains\nvec2 roughness(vec2 p, float footprint) {\n vec2 g = vec2(0.0);\n for (int k = 0; k < 2; k += 1) {\n float s = k == 0 ? 0.07 : 0.3;\n float amp = k == 0 ? 0.3 : 0.28;\n float fade = smoothstep(footprint * 2.0, footprint * 7.0, s);\n if (fade <= 0.0) continue;\n float d = s * 0.25;\n vec2 q = (k == 0 ? vec2(p.x * 0.629 + p.y * 0.777, p.y * 0.629 - p.x * 0.777) : vec2(p.x * 0.857 - p.y * 0.515, p.x * 0.515 + p.y * 0.857)) / s;\n float dx = vnoise(q + vec2(0.25, 0.0)) - vnoise(q - vec2(0.25, 0.0));\n float dy = vnoise(q + vec2(0.0, 0.25)) - vnoise(q - vec2(0.0, 0.25));\n g += fade * amp * vec2(dx, dy) / (0.5 * s) * 0.012;\n }\n return g;\n}\n\n\n// the ground's height at a point: the measured heights and, near the eyes, the made craters (kept to the ones a pixel here can show)\nfloat groundY(vec2 p, float dist, bool fine, float fromD) {\n float y = terrainY(p, dist, fine);\n if (uDetail > 0.5 && fromD < 24.0) y += madeGround(p, fromD).x;\n return y;\n}\n\n// 1 where the Sun reaches a point, 0 where the ground is in its way. The measured ground's shadow is read from the baked horizon; the march toward the Sun over the heights (and the made craters) is the near\n// field's only, a few tens of metres with a fixed number of steps, as sharp as the Sun's edge. Where there is no baked horizon the march goes all the way, as it did before the maps.\nfloat lit(vec3 P, float dist0) {\n vec2 dir = normalize(uSun.xz);\n float slope = uSun.y / max(length(uSun.xz), 1e-4);\n if (uHzOn > 0.5 && horizonAt(P.xz) - 0.3 > uSunDegrees) return 0.0;\n // the ground at the point from the heights themselves, not the mesh's slope between its corners, which can be a long way off on a far mountain\n // the made craters are in the ground at the point only where they are in the march too (uNear.z is 0 in the quality of motion, which leaves them out of the march): a point set down in a made crater's floor and a ray over the ground without the crater put the whole floor under the ground's height, black\n P.y = groundY(P.xz, dist0, true, uNear.z > 0.0 ? 2.5 * dist0 * uPixel : 99.0);\n float t = 0.5 * spacing(P.xz, dist0) + 0.25;\n if (uDetail > 0.5) t = min(t, 0.2 + 0.02 * dist0);\n // a pixel's own start along the ray: the edge of a rim's shadow is a line of steps, and a line of steps is jagged; with a start of its own each pixel it becomes a fine grain instead\n float jitter = fract(sin(dot(P.xz, vec2(12.9898, 78.233))) * 43758.5453);\n float range = uHzOn > 0.5 ? uNear.y : 80000.0;\n for (int i = 0; i < 260; i += 1) {\n if (float(i) >= uNear.x) break;\n vec2 q = P.xz + dir * t;\n float y = P.y + slope * t;\n float dist = max(t, distance(q, uEyeEN));\n float res = spacing(q, dist);\n float h = groundY(q, dist, t < 600.0, t < uNear.z ? max(0.2 * t, 2.5 * dist * uPixel) : 99.0);\n float bias = (t < 40.0 ? 0.01 : 0.3 * res) + 0.002 * t;\n if (h > y + bias) return 0.0;\n if (y > uMaxY || t > range) break;\n float step = t < 30.0 ? t * 0.045 + 0.04 : t * 0.06 + 0.5;\n t += step * (0.65 + 0.7 * jitter);\n }\n return 1.0;\n}\n";
|
|
9
9
|
/** The ground's light. */
|
|
10
|
-
export declare const GROUND_FRAGMENT = "\nprecision highp float;\nprecision highp sampler2D;\n\nuniform vec3 uSun;\nuniform vec3 uEye;\nuniform vec2 uEyeEN;\nuniform float uExposure;\nuniform float uAlbedo;\nuniform float uMaxY; // the highest ground over the site's, for the end of a shadow's march\nuniform float uEarthshine; // the light of the sunlit ground round the shade, a small share of a lit slope's (on Mars the sky's light, a good deal more)\nuniform vec3 uTint; // the ground's colour over its grey: white on the Moon\nuniform float uShadows; // 1 for the ground to shadow itself (the default), 0 for none (a try-out)\nuniform float uSunDegrees; // the Sun's elevation in degrees\nuniform vec3 uNear; // the near march: steps, the distance it reaches in metres, the distance out to which the made craters are in it (the quality of the draw)\n\nuniform sampler2D uH0;\nuniform sampler2D uH1;\nuniform sampler2D uH2;\nuniform sampler2D uH3;\nuniform sampler2D uA0; // the ground picture on the first three levels, 0 to 1 with the middle at 0.5\nuniform sampler2D uA1;\nuniform sampler2D uA2;\nuniform float uPicture; // 1 where the picture is there\nuniform vec4 uL0; // half width, metres a sample, samples across, the distance out to which this level is used\nuniform vec4 uL1;\nuniform vec4 uL2;\nuniform vec4 uL3;\nuniform float uHmin;\nuniform float uHrange;\nuniform float uGround;\nuniform float uRadius;\n\nuniform vec2 uFarHeight; // the range the coarse level is encoded over: its minimum and its span\nfloat dec(vec4 t, vec2 hr) { return hr.x + (t.r * 255.0 * 256.0 + t.g * 255.0) / 65535.0 * hr.y; }\n\nfloat lin(sampler2D s, vec2 p, vec4 l, vec2 hr) {\n vec2 f = vec2((p.x + l.x) / l.y - 0.5, (l.x - p.y) / l.y - 0.5);\n vec2 i = floor(f);\n vec2 t = f - i;\n float st = 1.0 / l.z;\n vec2 uv = (i + 0.5) * st;\n float a = dec(texture2D(s, uv), hr);\n float b = dec(texture2D(s, uv + vec2(st, 0.0)), hr);\n float c = dec(texture2D(s, uv + vec2(0.0, st)), hr);\n float d = dec(texture2D(s, uv + vec2(st, st)), hr);\n return mix(mix(a, b, t.x), mix(c, d, t.x), t.y);\n}\n\nfloat nearest(sampler2D s, vec2 p, vec4 l, vec2 hr) {\n vec2 uv = vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z));\n return dec(texture2D(s, uv), hr);\n}\n\nbool holds(vec2 p, vec4 l, float dist) { return dist < l.w && abs(p.x) < l.x - 2.0 * l.y && abs(p.y) < l.x - 2.0 * l.y; }\n\n// the ground's height over the site's, the sphere's fall taken off; `fine` reads four samples, otherwise one\nfloat terrainY(vec2 p, float dist, bool fine) {\n float h;\n if (holds(p, uL0, dist)) h = fine ? lin(uH0, p, uL0, vec2(uHmin, uHrange)) : nearest(uH0, p, uL0, vec2(uHmin, uHrange));\n else if (holds(p, uL1, dist)) h = fine ? lin(uH1, p, uL1, vec2(uHmin, uHrange)) : nearest(uH1, p, uL1, vec2(uHmin, uHrange));\n else if (holds(p, uL2, dist)) h = fine ? lin(uH2, p, uL2, vec2(uHmin, uHrange)) : nearest(uH2, p, uL2, vec2(uHmin, uHrange));\n else h = fine ? lin(uH3, p, uL3, uFarHeight) : nearest(uH3, p, uL3, uFarHeight);\n return h - uGround - dot(p, p) / (2.0 * uRadius);\n}\n\n// the ground's own brightness at a point, from the picture of the level that serves it, 1 where it is the middle\nfloat albedoAt(vec2 p, float dist) {\n if (uPicture < 0.5) return 1.0;\n vec4 l;\n if (holds(p, uL0, dist)) { l = uL0; return 2.0 * texture2D(uA0, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n if (holds(p, uL1, dist)) { l = uL1; return 2.0 * texture2D(uA1, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n if (holds(p, uL2, dist)) { l = uL2; return 2.0 * texture2D(uA2, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n return 1.0;\n}\n\n// the measured ground's shadows, baked (scripts/make-moon-terrain.py): for a point, the elevation angle in degrees of the horizon toward the Sun, read from the finest of the three horizon maps that holds the point\nuniform sampler2D uZ0;\nuniform sampler2D uZ1;\nuniform sampler2D uZ2;\nuniform float uHzOn; // 1 where the maps are there\nuniform vec3 uHzSun; // the two directions (of 18) the Sun's azimuth lies between, and the share of the second\nuniform vec2 uHzRange; // the degrees the codes 0 and 255 stand for\n\nfloat hzSector(sampler2D s, vec2 cell, float k) {\n float slab = floor(k / 3.0);\n float ch = k - slab * 3.0;\n vec3 v = texture2D(s, vec2((cell.x + slab) / 6.0, cell.y)).rgb;\n return ch < 0.5 ? v.r : (ch < 1.5 ? v.g : v.b);\n}\n\nfloat hzFrom(sampler2D s, vec2 p, float reach) {\n vec2 cell = clamp(vec2((p.x + reach) / (2.0 * reach), (reach - p.y) / (2.0 * reach)), vec2(0.5 / 512.0), vec2(1.0 - 0.5 / 512.0));\n float code = mix(hzSector(s, cell, uHzSun.x), hzSector(s, cell, uHzSun.y), uHzSun.z);\n return uHzRange.x + code * (uHzRange.y - uHzRange.x);\n}\n\nfloat horizonAt(vec2 p) {\n if (abs(p.x) < uL0.x && abs(p.y) < uL0.x) return hzFrom(uZ0, p, uL0.x);\n if (abs(p.x) < uL1.x && abs(p.y) < uL1.x) return hzFrom(uZ1, p, uL1.x);\n if (abs(p.x) < uL2.x && abs(p.y) < uL2.x) return hzFrom(uZ2, p, uL2.x);\n return -90.0;\n}\n\n// the spacing of the level that serves a point, for the step of a slope\nfloat spacing(vec2 p, float dist) {\n if (holds(p, uL0, dist)) return uL0.y;\n if (holds(p, uL1, dist)) return uL1.y;\n if (holds(p, uL2, dist)) return uL2.y;\n return uL3.y;\n}\n\n\nuniform float uPixel; // the angle one pixel takes, radians\nuniform float uDetail; // 1 for the made detail, 0 for none\n\nuvec2 pcg2d(uvec2 v) {\n v = v * 1664525u + 1013904223u;\n v.x += v.y * 1664525u;\n v.y += v.x * 1664525u;\n v = v ^ (v >> 16u);\n v.x += v.y * 1664525u;\n v.y += v.x * 1664525u;\n v = v ^ (v >> 16u);\n return v;\n}\nfloat u24(uint h) { return float(h >> 8u) * (1.0 / 16777216.0); }\n\nuniform vec4 uKeep[6]; // the objects the made ground keeps away from: east, north, the distance inside which nothing is made, the distance outside which it all is\nuniform float uKeepCount;\nfloat keepMask(vec2 p) {\n float keep = 1.0;\n for (int i = 0; i < 6; i += 1) {\n if (float(i) >= uKeepCount) break;\n vec4 k = uKeep[i];\n float t = clamp((distance(p, k.xy) - k.z) / (k.w - k.z), 0.0, 1.0);\n keep = min(keep, t * t * (3.0 - 2.0 * t));\n }\n return keep;\n}\n\n// the made ground at a point: x the height in metres, yz the slope east and north, from every crater of every octave whose nominal diameter is over `fromD`\nvec3 madeGround(vec2 p, float fromD) {\n vec3 sum = vec3(0.0);\n for (int octave = 5; octave >= 0; octave -= 1) {\n float nominal = 0.5 * exp2(float(octave));\n float fade = clamp(nominal / fromD - 1.0, 0.0, 1.0);\n if (fade <= 0.0) break;\n float cell = 3.0 * nominal;\n ivec2 base = ivec2(floor(p / cell));\n vec2 fr = p / cell - vec2(base);\n float occ = (octave >= 3 ? 0.5 : 1.0) * 0.36 * exp2(-0.5 * float(octave));\n for (int j = -1; j <= 1; j += 1) {\n for (int i = -1; i <= 1; i += 1) {\n // a crater is kept to the middle of its cell, so a neighbour's reaches this cell only within a fifth of the edge\n if ((i == -1 && fr.x > 0.2) || (i == 1 && fr.x < 0.8) || (j == -1 && fr.y > 0.2) || (j == 1 && fr.y < 0.8)) continue;\n ivec2 c = base + ivec2(i, j);\n uvec2 ab = pcg2d(uvec2(uint(c.x), uint(c.y + octave * 7919)));\n if (u24(ab.x) >= occ) continue;\n uvec2 cd = pcg2d(uvec2(uint(c.x + 104729), uint(c.y + octave * 7919 + 15485863)));\n float diameter = nominal * (1.0 + (octave == 5 ? 0.25 : 1.0) * u24(cd.y));\n float r4 = float(ab.x & 255u) / 255.0;\n float age = 1.0 - r4 * r4 * r4 * r4;\n float radius = 0.5 * diameter;\n float vary = 0.6 + 0.4 * (float(cd.x & 255u) / 255.0);\n float depth = diameter * (0.2 - 0.17 * age) * vary;\n float rim = 0.045 * diameter * pow(1.0 - age, 1.5);\n float rimWidth = 0.22 + 0.5 * age;\n vec2 centre = vec2(float(c.x) + 0.25 + 0.5 * u24(ab.y), float(c.y) + 0.25 + 0.5 * u24(cd.x)) * cell;\n vec2 d = p - centre;\n float r = length(d);\n float x = r / radius;\n float h = 0.0;\n float dh = 0.0;\n if (x < 1.0) { float bowl = 1.0 - x * x; float pw = 1.0 + age; h = -depth * pow(bowl, pw); dh = 2.0 * depth * pw * x * pow(bowl, age); }\n float e = (x - 1.0) / rimWidth;\n float ex = exp(-e * e);\n h += rim * ex;\n dh += -2.0 * rim * e * ex / rimWidth;\n if (x > 1.0) { float t = 1.0 / x; h += 0.25 * rim * t * t * t; dh += -0.75 * rim * t * t * t * t; }\n float k = r > 1e-6 ? dh / (radius * r) : 0.0;\n sum += fade * vec3(h, k * d.x, k * d.y);\n }\n }\n }\n return sum * keepMask(p);\n}\n\nfloat vnoise(vec2 p) {\n vec2 i = floor(p);\n vec2 f = p - i;\n vec2 w = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);\n uvec2 c = uvec2(ivec2(i));\n float a = u24(pcg2d(c).x);\n float b = u24(pcg2d(c + uvec2(1u, 0u)).x);\n float cc = u24(pcg2d(c + uvec2(0u, 1u)).x);\n float d = u24(pcg2d(c + uvec2(1u, 1u)).x);\n return mix(mix(a, b, w.x), mix(cc, d, w.x), w.y);\n}\n\n// a fine roughness of the dust: two scales, as a slope (east, north), faded out where a pixel covers more than a few of its grains\nvec2 roughness(vec2 p, float footprint) {\n vec2 g = vec2(0.0);\n for (int k = 0; k < 2; k += 1) {\n float s = k == 0 ? 0.07 : 0.3;\n float amp = k == 0 ? 0.3 : 0.28;\n float fade = smoothstep(footprint * 2.0, footprint * 7.0, s);\n if (fade <= 0.0) continue;\n float d = s * 0.25;\n vec2 q = (k == 0 ? vec2(p.x * 0.629 + p.y * 0.777, p.y * 0.629 - p.x * 0.777) : vec2(p.x * 0.857 - p.y * 0.515, p.x * 0.515 + p.y * 0.857)) / s;\n float dx = vnoise(q + vec2(0.25, 0.0)) - vnoise(q - vec2(0.25, 0.0));\n float dy = vnoise(q + vec2(0.0, 0.25)) - vnoise(q - vec2(0.0, 0.25));\n g += fade * amp * vec2(dx, dy) / (0.5 * s) * 0.012;\n }\n return g;\n}\n\n\n// the ground's height at a point: the measured heights and, near the eyes, the made craters (kept to the ones a pixel here can show)\nfloat groundY(vec2 p, float dist, bool fine, float fromD) {\n float y = terrainY(p, dist, fine);\n if (uDetail > 0.5 && fromD < 24.0) y += madeGround(p, fromD).x;\n return y;\n}\n\n// 1 where the Sun reaches a point, 0 where the ground is in its way. The measured ground's shadow is read from the baked horizon; the march toward the Sun over the heights (and the made craters) is the near\n// field's only, a few tens of metres with a fixed number of steps, as sharp as the Sun's edge. Where there is no baked horizon the march goes all the way, as it did before the maps.\nfloat lit(vec3 P, float dist0) {\n vec2 dir = normalize(uSun.xz);\n float slope = uSun.y / max(length(uSun.xz), 1e-4);\n if (uHzOn > 0.5 && horizonAt(P.xz) - 0.3 > uSunDegrees) return 0.0;\n // the ground at the point from the heights themselves, not the mesh's slope between its corners, which can be a long way off on a far mountain\n // the made craters are in the ground at the point only where they are in the march too (uNear.z is 0 in the quality of motion, which leaves them out of the march): a point set down in a made crater's floor and a ray over the ground without the crater put the whole floor under the ground's height, black\n P.y = groundY(P.xz, dist0, true, uNear.z > 0.0 ? 2.5 * dist0 * uPixel : 99.0);\n float t = 0.5 * spacing(P.xz, dist0) + 0.25;\n if (uDetail > 0.5) t = min(t, 0.2 + 0.02 * dist0);\n // a pixel's own start along the ray: the edge of a rim's shadow is a line of steps, and a line of steps is jagged; with a start of its own each pixel it becomes a fine grain instead\n float jitter = fract(sin(dot(P.xz, vec2(12.9898, 78.233))) * 43758.5453);\n float range = uHzOn > 0.5 ? uNear.y : 80000.0;\n for (int i = 0; i < 260; i += 1) {\n if (float(i) >= uNear.x) break;\n vec2 q = P.xz + dir * t;\n float y = P.y + slope * t;\n float dist = max(t, distance(q, uEyeEN));\n float res = spacing(q, dist);\n float h = groundY(q, dist, t < 600.0, t < uNear.z ? max(0.2 * t, 2.5 * dist * uPixel) : 99.0);\n float bias = (t < 40.0 ? 0.01 : 0.3 * res) + 0.002 * t;\n if (h > y + bias) return 0.0;\n if (y > uMaxY || t > range) break;\n float step = t < 30.0 ? t * 0.045 + 0.04 : t * 0.06 + 0.5;\n t += step * (0.65 + 0.7 * jitter);\n }\n return 1.0;\n}\n\nvarying vec3 vP;\n\nvoid main() {\n float dist = distance(vP.xz, uEyeEN);\n float fromD = 2.5 * dist * uPixel;\n float e = max(spacing(vP.xz, dist), dist * 0.001);\n float hE = terrainY(vP.xz + vec2(e, 0.0), dist, true);\n float hW = terrainY(vP.xz - vec2(e, 0.0), dist, true);\n float hN = terrainY(vP.xz + vec2(0.0, e), dist, true);\n float hS = terrainY(vP.xz - vec2(0.0, e), dist, true);\n vec2 slope = vec2((hE - hW) / (2.0 * e), (hN - hS) / (2.0 * e));\n if (uDetail > 0.5) {\n if (fromD < 24.0) slope += madeGround(vP.xz, fromD).yz;\n slope += roughness(vP.xz, dist * uPixel);\n }\n vec3 n = normalize(vec3(-slope.x, 1.0, -slope.y));\n float mu0 = dot(n, uSun);\n float mu = max(dot(n, normalize(uEye - vP)), 0.03);\n float shine = 0.0;\n if (mu0 > 0.0 && uSun.y > -0.01) shine = (uShadows > 0.5 ? lit(vP, dist) : 1.0) * 2.0 * mu0 / (mu0 + mu);\n float light = uAlbedo * albedoAt(vP.xz, dist) * (shine + uEarthshine * max(n.y, 0.0)) * uExposure;\n gl_FragColor = vec4(pow(clamp(vec3(light) * uTint, 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);\n}\n";
|
|
10
|
+
export declare const GROUND_FRAGMENT = "\nprecision highp float;\nprecision highp sampler2D;\n\nuniform vec3 uSun;\nuniform vec3 uEye;\nuniform vec2 uEyeEN;\nuniform float uExposure;\nuniform float uAlbedo;\nuniform float uMaxY; // the highest ground over the site's, for the end of a shadow's march\nuniform float uEarthshine; // the light of the sunlit ground round the shade, a small share of a lit slope's (on Mars the sky's light, a good deal more)\nuniform vec3 uTint; // the ground's colour over its grey: white on the Moon\nuniform float uShadows; // 1 for the ground to shadow itself (the default), 0 for none (a try-out)\nuniform float uSunDegrees; // the Sun's elevation in degrees\nuniform vec3 uNear; // the near march: steps, the distance it reaches in metres, the distance out to which the made craters are in it (the quality of the draw)\n\nuniform sampler2D uH0;\nuniform sampler2D uH1;\nuniform sampler2D uH2;\nuniform sampler2D uH3;\nuniform sampler2D uA0; // the ground picture on the first three levels, 0 to 1 with the middle at 0.5\nuniform sampler2D uA1;\nuniform sampler2D uA2;\nuniform float uPicture; // 1 where the picture is there\nuniform vec4 uL0; // half width, metres a sample, samples across, the distance out to which this level is used\nuniform vec4 uL1;\nuniform vec4 uL2;\nuniform vec4 uL3;\nuniform float uHmin;\nuniform float uHrange;\nuniform float uGround;\nuniform float uRadius;\n\nuniform vec2 uFarHeight; // the range the coarse level is encoded over: its minimum and its span\nfloat dec(vec4 t, vec2 hr) { return hr.x + (t.r * 255.0 * 256.0 + t.g * 255.0) / 65535.0 * hr.y; }\n\nfloat lin(sampler2D s, vec2 p, vec4 l, vec2 hr) {\n vec2 f = vec2((p.x + l.x) / l.y - 0.5, (l.x - p.y) / l.y - 0.5);\n vec2 i = floor(f);\n vec2 t = f - i;\n float st = 1.0 / l.z;\n vec2 uv = (i + 0.5) * st;\n float a = dec(texture2D(s, uv), hr);\n float b = dec(texture2D(s, uv + vec2(st, 0.0)), hr);\n float c = dec(texture2D(s, uv + vec2(0.0, st)), hr);\n float d = dec(texture2D(s, uv + vec2(st, st)), hr);\n return mix(mix(a, b, t.x), mix(c, d, t.x), t.y);\n}\n\nfloat nearest(sampler2D s, vec2 p, vec4 l, vec2 hr) {\n vec2 uv = vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z));\n return dec(texture2D(s, uv), hr);\n}\n\nbool holds(vec2 p, vec4 l, float dist) { return dist < l.w && abs(p.x) < l.x - 2.0 * l.y && abs(p.y) < l.x - 2.0 * l.y; }\n\n// the ground's height over the site's, the sphere's fall taken off; `fine` reads four samples, otherwise one\nfloat terrainY(vec2 p, float dist, bool fine) {\n float h;\n if (holds(p, uL0, dist)) h = fine ? lin(uH0, p, uL0, vec2(uHmin, uHrange)) : nearest(uH0, p, uL0, vec2(uHmin, uHrange));\n else if (holds(p, uL1, dist)) h = fine ? lin(uH1, p, uL1, vec2(uHmin, uHrange)) : nearest(uH1, p, uL1, vec2(uHmin, uHrange));\n else if (holds(p, uL2, dist)) h = fine ? lin(uH2, p, uL2, vec2(uHmin, uHrange)) : nearest(uH2, p, uL2, vec2(uHmin, uHrange));\n else h = fine ? lin(uH3, p, uL3, uFarHeight) : nearest(uH3, p, uL3, uFarHeight);\n return h - uGround - dot(p, p) / (2.0 * uRadius);\n}\n\n// the ground's own brightness at a point, from the picture of the level that serves it, 1 where it is the middle\nfloat albedoAt(vec2 p, float dist) {\n if (uPicture < 0.5) return 1.0;\n vec4 l;\n if (holds(p, uL0, dist)) { l = uL0; return 2.0 * texture2D(uA0, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n if (holds(p, uL1, dist)) { l = uL1; return 2.0 * texture2D(uA1, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n if (holds(p, uL2, dist)) { l = uL2; return 2.0 * texture2D(uA2, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n return 1.0;\n}\n\n// the measured ground's shadows, baked (scripts/make-moon-terrain.py): for a point, the elevation angle in degrees of the horizon toward the Sun, read from the finest of the three horizon maps that holds the point\nuniform sampler2D uZ0;\nuniform sampler2D uZ1;\nuniform sampler2D uZ2;\nuniform float uHzOn; // 1 where the maps are there\nuniform vec3 uHzSun; // the two directions (of 18) the Sun's azimuth lies between, and the share of the second\nuniform vec2 uHzRange; // the degrees the codes 0 and 255 stand for\n\nfloat hzSector(sampler2D s, vec2 cell, float k) {\n float slab = floor(k / 3.0);\n float ch = k - slab * 3.0;\n vec3 v = texture2D(s, vec2((cell.x + slab) / 6.0, cell.y)).rgb;\n return ch < 0.5 ? v.r : (ch < 1.5 ? v.g : v.b);\n}\n\nfloat hzFrom(sampler2D s, vec2 p, float reach) {\n vec2 cell = clamp(vec2((p.x + reach) / (2.0 * reach), (reach - p.y) / (2.0 * reach)), vec2(0.5 / 512.0), vec2(1.0 - 0.5 / 512.0));\n float code = mix(hzSector(s, cell, uHzSun.x), hzSector(s, cell, uHzSun.y), uHzSun.z);\n return uHzRange.x + code * (uHzRange.y - uHzRange.x);\n}\n\nfloat horizonAt(vec2 p) {\n if (abs(p.x) < uL0.x && abs(p.y) < uL0.x) return hzFrom(uZ0, p, uL0.x);\n if (abs(p.x) < uL1.x && abs(p.y) < uL1.x) return hzFrom(uZ1, p, uL1.x);\n if (abs(p.x) < uL2.x && abs(p.y) < uL2.x) return hzFrom(uZ2, p, uL2.x);\n return -90.0;\n}\n\n// the spacing of the level that serves a point, for the step of a slope\nfloat spacing(vec2 p, float dist) {\n if (holds(p, uL0, dist)) return uL0.y;\n if (holds(p, uL1, dist)) return uL1.y;\n if (holds(p, uL2, dist)) return uL2.y;\n return uL3.y;\n}\n\n\nuniform float uPixel; // the angle one pixel takes, radians\nuniform float uDetail; // 1 for the made detail, 0 for none\n\nuvec2 pcg2d(uvec2 v) {\n v = v * 1664525u + 1013904223u;\n v.x += v.y * 1664525u;\n v.y += v.x * 1664525u;\n v = v ^ (v >> 16u);\n v.x += v.y * 1664525u;\n v.y += v.x * 1664525u;\n v = v ^ (v >> 16u);\n return v;\n}\nfloat u24(uint h) { return float(h >> 8u) * (1.0 / 16777216.0); }\n\nuniform vec4 uKeep[6]; // the objects the made ground keeps away from: east, north, the distance inside which nothing is made, the distance outside which it all is\nuniform float uKeepCount;\nfloat keepMask(vec2 p) {\n float keep = 1.0;\n for (int i = 0; i < 6; i += 1) {\n if (float(i) >= uKeepCount) break;\n vec4 k = uKeep[i];\n float t = clamp((distance(p, k.xy) - k.z) / (k.w - k.z), 0.0, 1.0);\n keep = min(keep, t * t * (3.0 - 2.0 * t));\n }\n return keep;\n}\n\n// the made ground at a point: x the height in metres, yz the slope east and north, from every crater of every octave whose nominal diameter is over `fromD`\nvec3 madeGround(vec2 p, float fromD) {\n vec3 sum = vec3(0.0);\n for (int octave = 5; octave >= 0; octave -= 1) {\n float nominal = 0.5 * exp2(float(octave));\n float fade = clamp(nominal / fromD - 1.0, 0.0, 1.0);\n if (fade <= 0.0) break;\n float cell = 3.0 * nominal;\n ivec2 base = ivec2(floor(p / cell));\n vec2 fr = p / cell - vec2(base);\n float occ = (octave >= 3 ? 0.5 : 1.0) * 0.36 * exp2(-0.5 * float(octave));\n for (int j = -1; j <= 1; j += 1) {\n for (int i = -1; i <= 1; i += 1) {\n // a crater is kept to the middle of its cell, so a neighbour's reaches this cell only within a fifth of the edge\n if ((i == -1 && fr.x > 0.2) || (i == 1 && fr.x < 0.8) || (j == -1 && fr.y > 0.2) || (j == 1 && fr.y < 0.8)) continue;\n ivec2 c = base + ivec2(i, j);\n uvec2 ab = pcg2d(uvec2(uint(c.x), uint(c.y + octave * 7919)));\n if (u24(ab.x) >= occ) continue;\n uvec2 cd = pcg2d(uvec2(uint(c.x + 104729), uint(c.y + octave * 7919 + 15485863)));\n float diameter = nominal * (1.0 + (octave == 5 ? 0.25 : 1.0) * u24(cd.y));\n float r4 = float(ab.x & 255u) / 255.0;\n float age = 1.0 - r4 * r4 * r4 * r4;\n float radius = 0.5 * diameter;\n float vary = 0.6 + 0.4 * (float(cd.x & 255u) / 255.0);\n float depth = diameter * (0.2 - 0.17 * age) * vary;\n float rim = 0.045 * diameter * pow(1.0 - age, 1.5);\n float rimWidth = 0.22 + 0.5 * age;\n vec2 centre = vec2(float(c.x) + 0.25 + 0.5 * u24(ab.y), float(c.y) + 0.25 + 0.5 * u24(cd.x)) * cell;\n vec2 d = p - centre;\n float r = length(d);\n float x = r / radius;\n float h = 0.0;\n float dh = 0.0;\n if (x < 1.0) { float bowl = 1.0 - x * x; float pw = 1.0 + age; h = -depth * pow(bowl, pw); dh = 2.0 * depth * pw * x * pow(bowl, age); }\n float e = (x - 1.0) / rimWidth;\n float ex = exp(-e * e);\n h += rim * ex;\n dh += -2.0 * rim * e * ex / rimWidth;\n if (x > 1.0) { float t = 1.0 / x; h += 0.25 * rim * t * t * t; dh += -0.75 * rim * t * t * t * t; }\n float k = r > 1e-6 ? dh / (radius * r) : 0.0;\n sum += fade * vec3(h, k * d.x, k * d.y);\n }\n }\n }\n return sum * keepMask(p);\n}\n\nfloat vnoise(vec2 p) {\n vec2 i = floor(p);\n vec2 f = p - i;\n vec2 w = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);\n uvec2 c = uvec2(ivec2(i));\n float a = u24(pcg2d(c).x);\n float b = u24(pcg2d(c + uvec2(1u, 0u)).x);\n float cc = u24(pcg2d(c + uvec2(0u, 1u)).x);\n float d = u24(pcg2d(c + uvec2(1u, 1u)).x);\n return mix(mix(a, b, w.x), mix(cc, d, w.x), w.y);\n}\n\n// a fine roughness of the dust: two scales, as a slope (east, north), faded out where a pixel covers more than a few of its grains\nvec2 roughness(vec2 p, float footprint) {\n vec2 g = vec2(0.0);\n for (int k = 0; k < 2; k += 1) {\n float s = k == 0 ? 0.07 : 0.3;\n float amp = k == 0 ? 0.3 : 0.28;\n float fade = smoothstep(footprint * 2.0, footprint * 7.0, s);\n if (fade <= 0.0) continue;\n float d = s * 0.25;\n vec2 q = (k == 0 ? vec2(p.x * 0.629 + p.y * 0.777, p.y * 0.629 - p.x * 0.777) : vec2(p.x * 0.857 - p.y * 0.515, p.x * 0.515 + p.y * 0.857)) / s;\n float dx = vnoise(q + vec2(0.25, 0.0)) - vnoise(q - vec2(0.25, 0.0));\n float dy = vnoise(q + vec2(0.0, 0.25)) - vnoise(q - vec2(0.0, 0.25));\n g += fade * amp * vec2(dx, dy) / (0.5 * s) * 0.012;\n }\n return g;\n}\n\n\n// the ground's height at a point: the measured heights and, near the eyes, the made craters (kept to the ones a pixel here can show)\nfloat groundY(vec2 p, float dist, bool fine, float fromD) {\n float y = terrainY(p, dist, fine);\n if (uDetail > 0.5 && fromD < 24.0) y += madeGround(p, fromD).x;\n return y;\n}\n\n// 1 where the Sun reaches a point, 0 where the ground is in its way. The measured ground's shadow is read from the baked horizon; the march toward the Sun over the heights (and the made craters) is the near\n// field's only, a few tens of metres with a fixed number of steps, as sharp as the Sun's edge. Where there is no baked horizon the march goes all the way, as it did before the maps.\nfloat lit(vec3 P, float dist0) {\n vec2 dir = normalize(uSun.xz);\n float slope = uSun.y / max(length(uSun.xz), 1e-4);\n if (uHzOn > 0.5 && horizonAt(P.xz) - 0.3 > uSunDegrees) return 0.0;\n // the ground at the point from the heights themselves, not the mesh's slope between its corners, which can be a long way off on a far mountain\n // the made craters are in the ground at the point only where they are in the march too (uNear.z is 0 in the quality of motion, which leaves them out of the march): a point set down in a made crater's floor and a ray over the ground without the crater put the whole floor under the ground's height, black\n P.y = groundY(P.xz, dist0, true, uNear.z > 0.0 ? 2.5 * dist0 * uPixel : 99.0);\n float t = 0.5 * spacing(P.xz, dist0) + 0.25;\n if (uDetail > 0.5) t = min(t, 0.2 + 0.02 * dist0);\n // a pixel's own start along the ray: the edge of a rim's shadow is a line of steps, and a line of steps is jagged; with a start of its own each pixel it becomes a fine grain instead\n float jitter = fract(sin(dot(P.xz, vec2(12.9898, 78.233))) * 43758.5453);\n float range = uHzOn > 0.5 ? uNear.y : 80000.0;\n for (int i = 0; i < 260; i += 1) {\n if (float(i) >= uNear.x) break;\n vec2 q = P.xz + dir * t;\n float y = P.y + slope * t;\n float dist = max(t, distance(q, uEyeEN));\n float res = spacing(q, dist);\n float h = groundY(q, dist, t < 600.0, t < uNear.z ? max(0.2 * t, 2.5 * dist * uPixel) : 99.0);\n float bias = (t < 40.0 ? 0.01 : 0.3 * res) + 0.002 * t;\n if (h > y + bias) return 0.0;\n if (y > uMaxY || t > range) break;\n float step = t < 30.0 ? t * 0.045 + 0.04 : t * 0.06 + 0.5;\n t += step * (0.65 + 0.7 * jitter);\n }\n return 1.0;\n}\n\nvarying vec3 vP;\n\nvoid main() {\n float dist = distance(vP.xz, uEyeEN);\n float fromD = 2.5 * dist * uPixel;\n float e = max(spacing(vP.xz, dist), dist * 0.001);\n float hE = terrainY(vP.xz + vec2(e, 0.0), dist, true);\n float hW = terrainY(vP.xz - vec2(e, 0.0), dist, true);\n float hN = terrainY(vP.xz + vec2(0.0, e), dist, true);\n float hS = terrainY(vP.xz - vec2(0.0, e), dist, true);\n vec2 slope = vec2((hE - hW) / (2.0 * e), (hN - hS) / (2.0 * e));\n if (uDetail > 0.5) {\n if (fromD < 24.0) slope += madeGround(vP.xz, fromD).yz;\n // the dust's grain only where the Sun is well on the ground: where it grazes, a grain a degree off lights or darkens each cell and the grain reads as blocks\n slope += roughness(vP.xz, dist * uPixel) * smoothstep(0.0, 0.12, dot(normalize(vec3(-slope.x, 1.0, -slope.y)), uSun));\n }\n vec3 n = normalize(vec3(-slope.x, 1.0, -slope.y));\n float mu0 = dot(n, uSun);\n float mu = max(dot(n, normalize(uEye - vP)), 0.03);\n float shine = 0.0;\n if (mu0 > 0.0 && uSun.y > -0.01) shine = (uShadows > 0.5 ? lit(vP, dist) : 1.0) * 2.0 * mu0 / (mu0 + mu);\n float light = uAlbedo * albedoAt(vP.xz, dist) * (shine + uEarthshine * max(n.y, 0.0)) * uExposure;\n gl_FragColor = vec4(pow(clamp(vec3(light) * uTint, 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);\n}\n";
|
|
11
11
|
/** The rocks: pieces of ground standing on it. Their corners come from the page already in the site's plane (east, up, north). */
|
|
12
12
|
export declare const ROCK_VERTEX = "\nprecision highp float;\n// position, normal and uv are declared by three.js\nattribute float tone;\nuniform mat4 uVP;\nvarying vec3 vP;\nvarying vec3 vN;\nvarying float vTone;\nvoid main() {\n vP = position;\n vN = normal;\n vTone = tone;\n gl_Position = uVP * vec4(position.x, position.y, -position.z, 1.0);\n}\n";
|
|
13
13
|
export declare const ROCK_FRAGMENT = "\nprecision highp float;\nprecision highp sampler2D;\n\nuniform vec3 uSun;\nuniform vec3 uEye;\nuniform vec2 uEyeEN;\nuniform float uExposure;\nuniform float uAlbedo;\nuniform float uMaxY; // the highest ground over the site's, for the end of a shadow's march\nuniform float uEarthshine; // the light of the sunlit ground round the shade, a small share of a lit slope's (on Mars the sky's light, a good deal more)\nuniform vec3 uTint; // the ground's colour over its grey: white on the Moon\nuniform float uShadows; // 1 for the ground to shadow itself (the default), 0 for none (a try-out)\nuniform float uSunDegrees; // the Sun's elevation in degrees\nuniform vec3 uNear; // the near march: steps, the distance it reaches in metres, the distance out to which the made craters are in it (the quality of the draw)\n\nuniform sampler2D uH0;\nuniform sampler2D uH1;\nuniform sampler2D uH2;\nuniform sampler2D uH3;\nuniform sampler2D uA0; // the ground picture on the first three levels, 0 to 1 with the middle at 0.5\nuniform sampler2D uA1;\nuniform sampler2D uA2;\nuniform float uPicture; // 1 where the picture is there\nuniform vec4 uL0; // half width, metres a sample, samples across, the distance out to which this level is used\nuniform vec4 uL1;\nuniform vec4 uL2;\nuniform vec4 uL3;\nuniform float uHmin;\nuniform float uHrange;\nuniform float uGround;\nuniform float uRadius;\n\nuniform vec2 uFarHeight; // the range the coarse level is encoded over: its minimum and its span\nfloat dec(vec4 t, vec2 hr) { return hr.x + (t.r * 255.0 * 256.0 + t.g * 255.0) / 65535.0 * hr.y; }\n\nfloat lin(sampler2D s, vec2 p, vec4 l, vec2 hr) {\n vec2 f = vec2((p.x + l.x) / l.y - 0.5, (l.x - p.y) / l.y - 0.5);\n vec2 i = floor(f);\n vec2 t = f - i;\n float st = 1.0 / l.z;\n vec2 uv = (i + 0.5) * st;\n float a = dec(texture2D(s, uv), hr);\n float b = dec(texture2D(s, uv + vec2(st, 0.0)), hr);\n float c = dec(texture2D(s, uv + vec2(0.0, st)), hr);\n float d = dec(texture2D(s, uv + vec2(st, st)), hr);\n return mix(mix(a, b, t.x), mix(c, d, t.x), t.y);\n}\n\nfloat nearest(sampler2D s, vec2 p, vec4 l, vec2 hr) {\n vec2 uv = vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z));\n return dec(texture2D(s, uv), hr);\n}\n\nbool holds(vec2 p, vec4 l, float dist) { return dist < l.w && abs(p.x) < l.x - 2.0 * l.y && abs(p.y) < l.x - 2.0 * l.y; }\n\n// the ground's height over the site's, the sphere's fall taken off; `fine` reads four samples, otherwise one\nfloat terrainY(vec2 p, float dist, bool fine) {\n float h;\n if (holds(p, uL0, dist)) h = fine ? lin(uH0, p, uL0, vec2(uHmin, uHrange)) : nearest(uH0, p, uL0, vec2(uHmin, uHrange));\n else if (holds(p, uL1, dist)) h = fine ? lin(uH1, p, uL1, vec2(uHmin, uHrange)) : nearest(uH1, p, uL1, vec2(uHmin, uHrange));\n else if (holds(p, uL2, dist)) h = fine ? lin(uH2, p, uL2, vec2(uHmin, uHrange)) : nearest(uH2, p, uL2, vec2(uHmin, uHrange));\n else h = fine ? lin(uH3, p, uL3, uFarHeight) : nearest(uH3, p, uL3, uFarHeight);\n return h - uGround - dot(p, p) / (2.0 * uRadius);\n}\n\n// the ground's own brightness at a point, from the picture of the level that serves it, 1 where it is the middle\nfloat albedoAt(vec2 p, float dist) {\n if (uPicture < 0.5) return 1.0;\n vec4 l;\n if (holds(p, uL0, dist)) { l = uL0; return 2.0 * texture2D(uA0, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n if (holds(p, uL1, dist)) { l = uL1; return 2.0 * texture2D(uA1, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n if (holds(p, uL2, dist)) { l = uL2; return 2.0 * texture2D(uA2, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n return 1.0;\n}\n\n// the measured ground's shadows, baked (scripts/make-moon-terrain.py): for a point, the elevation angle in degrees of the horizon toward the Sun, read from the finest of the three horizon maps that holds the point\nuniform sampler2D uZ0;\nuniform sampler2D uZ1;\nuniform sampler2D uZ2;\nuniform float uHzOn; // 1 where the maps are there\nuniform vec3 uHzSun; // the two directions (of 18) the Sun's azimuth lies between, and the share of the second\nuniform vec2 uHzRange; // the degrees the codes 0 and 255 stand for\n\nfloat hzSector(sampler2D s, vec2 cell, float k) {\n float slab = floor(k / 3.0);\n float ch = k - slab * 3.0;\n vec3 v = texture2D(s, vec2((cell.x + slab) / 6.0, cell.y)).rgb;\n return ch < 0.5 ? v.r : (ch < 1.5 ? v.g : v.b);\n}\n\nfloat hzFrom(sampler2D s, vec2 p, float reach) {\n vec2 cell = clamp(vec2((p.x + reach) / (2.0 * reach), (reach - p.y) / (2.0 * reach)), vec2(0.5 / 512.0), vec2(1.0 - 0.5 / 512.0));\n float code = mix(hzSector(s, cell, uHzSun.x), hzSector(s, cell, uHzSun.y), uHzSun.z);\n return uHzRange.x + code * (uHzRange.y - uHzRange.x);\n}\n\nfloat horizonAt(vec2 p) {\n if (abs(p.x) < uL0.x && abs(p.y) < uL0.x) return hzFrom(uZ0, p, uL0.x);\n if (abs(p.x) < uL1.x && abs(p.y) < uL1.x) return hzFrom(uZ1, p, uL1.x);\n if (abs(p.x) < uL2.x && abs(p.y) < uL2.x) return hzFrom(uZ2, p, uL2.x);\n return -90.0;\n}\n\n// the spacing of the level that serves a point, for the step of a slope\nfloat spacing(vec2 p, float dist) {\n if (holds(p, uL0, dist)) return uL0.y;\n if (holds(p, uL1, dist)) return uL1.y;\n if (holds(p, uL2, dist)) return uL2.y;\n return uL3.y;\n}\n\n\nuniform float uPixel; // the angle one pixel takes, radians\nuniform float uDetail; // 1 for the made detail, 0 for none\n\nuvec2 pcg2d(uvec2 v) {\n v = v * 1664525u + 1013904223u;\n v.x += v.y * 1664525u;\n v.y += v.x * 1664525u;\n v = v ^ (v >> 16u);\n v.x += v.y * 1664525u;\n v.y += v.x * 1664525u;\n v = v ^ (v >> 16u);\n return v;\n}\nfloat u24(uint h) { return float(h >> 8u) * (1.0 / 16777216.0); }\n\nuniform vec4 uKeep[6]; // the objects the made ground keeps away from: east, north, the distance inside which nothing is made, the distance outside which it all is\nuniform float uKeepCount;\nfloat keepMask(vec2 p) {\n float keep = 1.0;\n for (int i = 0; i < 6; i += 1) {\n if (float(i) >= uKeepCount) break;\n vec4 k = uKeep[i];\n float t = clamp((distance(p, k.xy) - k.z) / (k.w - k.z), 0.0, 1.0);\n keep = min(keep, t * t * (3.0 - 2.0 * t));\n }\n return keep;\n}\n\n// the made ground at a point: x the height in metres, yz the slope east and north, from every crater of every octave whose nominal diameter is over `fromD`\nvec3 madeGround(vec2 p, float fromD) {\n vec3 sum = vec3(0.0);\n for (int octave = 5; octave >= 0; octave -= 1) {\n float nominal = 0.5 * exp2(float(octave));\n float fade = clamp(nominal / fromD - 1.0, 0.0, 1.0);\n if (fade <= 0.0) break;\n float cell = 3.0 * nominal;\n ivec2 base = ivec2(floor(p / cell));\n vec2 fr = p / cell - vec2(base);\n float occ = (octave >= 3 ? 0.5 : 1.0) * 0.36 * exp2(-0.5 * float(octave));\n for (int j = -1; j <= 1; j += 1) {\n for (int i = -1; i <= 1; i += 1) {\n // a crater is kept to the middle of its cell, so a neighbour's reaches this cell only within a fifth of the edge\n if ((i == -1 && fr.x > 0.2) || (i == 1 && fr.x < 0.8) || (j == -1 && fr.y > 0.2) || (j == 1 && fr.y < 0.8)) continue;\n ivec2 c = base + ivec2(i, j);\n uvec2 ab = pcg2d(uvec2(uint(c.x), uint(c.y + octave * 7919)));\n if (u24(ab.x) >= occ) continue;\n uvec2 cd = pcg2d(uvec2(uint(c.x + 104729), uint(c.y + octave * 7919 + 15485863)));\n float diameter = nominal * (1.0 + (octave == 5 ? 0.25 : 1.0) * u24(cd.y));\n float r4 = float(ab.x & 255u) / 255.0;\n float age = 1.0 - r4 * r4 * r4 * r4;\n float radius = 0.5 * diameter;\n float vary = 0.6 + 0.4 * (float(cd.x & 255u) / 255.0);\n float depth = diameter * (0.2 - 0.17 * age) * vary;\n float rim = 0.045 * diameter * pow(1.0 - age, 1.5);\n float rimWidth = 0.22 + 0.5 * age;\n vec2 centre = vec2(float(c.x) + 0.25 + 0.5 * u24(ab.y), float(c.y) + 0.25 + 0.5 * u24(cd.x)) * cell;\n vec2 d = p - centre;\n float r = length(d);\n float x = r / radius;\n float h = 0.0;\n float dh = 0.0;\n if (x < 1.0) { float bowl = 1.0 - x * x; float pw = 1.0 + age; h = -depth * pow(bowl, pw); dh = 2.0 * depth * pw * x * pow(bowl, age); }\n float e = (x - 1.0) / rimWidth;\n float ex = exp(-e * e);\n h += rim * ex;\n dh += -2.0 * rim * e * ex / rimWidth;\n if (x > 1.0) { float t = 1.0 / x; h += 0.25 * rim * t * t * t; dh += -0.75 * rim * t * t * t * t; }\n float k = r > 1e-6 ? dh / (radius * r) : 0.0;\n sum += fade * vec3(h, k * d.x, k * d.y);\n }\n }\n }\n return sum * keepMask(p);\n}\n\nfloat vnoise(vec2 p) {\n vec2 i = floor(p);\n vec2 f = p - i;\n vec2 w = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);\n uvec2 c = uvec2(ivec2(i));\n float a = u24(pcg2d(c).x);\n float b = u24(pcg2d(c + uvec2(1u, 0u)).x);\n float cc = u24(pcg2d(c + uvec2(0u, 1u)).x);\n float d = u24(pcg2d(c + uvec2(1u, 1u)).x);\n return mix(mix(a, b, w.x), mix(cc, d, w.x), w.y);\n}\n\n// a fine roughness of the dust: two scales, as a slope (east, north), faded out where a pixel covers more than a few of its grains\nvec2 roughness(vec2 p, float footprint) {\n vec2 g = vec2(0.0);\n for (int k = 0; k < 2; k += 1) {\n float s = k == 0 ? 0.07 : 0.3;\n float amp = k == 0 ? 0.3 : 0.28;\n float fade = smoothstep(footprint * 2.0, footprint * 7.0, s);\n if (fade <= 0.0) continue;\n float d = s * 0.25;\n vec2 q = (k == 0 ? vec2(p.x * 0.629 + p.y * 0.777, p.y * 0.629 - p.x * 0.777) : vec2(p.x * 0.857 - p.y * 0.515, p.x * 0.515 + p.y * 0.857)) / s;\n float dx = vnoise(q + vec2(0.25, 0.0)) - vnoise(q - vec2(0.25, 0.0));\n float dy = vnoise(q + vec2(0.0, 0.25)) - vnoise(q - vec2(0.0, 0.25));\n g += fade * amp * vec2(dx, dy) / (0.5 * s) * 0.012;\n }\n return g;\n}\n\n\n// the ground's height at a point: the measured heights and, near the eyes, the made craters (kept to the ones a pixel here can show)\nfloat groundY(vec2 p, float dist, bool fine, float fromD) {\n float y = terrainY(p, dist, fine);\n if (uDetail > 0.5 && fromD < 24.0) y += madeGround(p, fromD).x;\n return y;\n}\n\n// 1 where the Sun reaches a point, 0 where the ground is in its way. The measured ground's shadow is read from the baked horizon; the march toward the Sun over the heights (and the made craters) is the near\n// field's only, a few tens of metres with a fixed number of steps, as sharp as the Sun's edge. Where there is no baked horizon the march goes all the way, as it did before the maps.\nfloat lit(vec3 P, float dist0) {\n vec2 dir = normalize(uSun.xz);\n float slope = uSun.y / max(length(uSun.xz), 1e-4);\n if (uHzOn > 0.5 && horizonAt(P.xz) - 0.3 > uSunDegrees) return 0.0;\n // the ground at the point from the heights themselves, not the mesh's slope between its corners, which can be a long way off on a far mountain\n // the made craters are in the ground at the point only where they are in the march too (uNear.z is 0 in the quality of motion, which leaves them out of the march): a point set down in a made crater's floor and a ray over the ground without the crater put the whole floor under the ground's height, black\n P.y = groundY(P.xz, dist0, true, uNear.z > 0.0 ? 2.5 * dist0 * uPixel : 99.0);\n float t = 0.5 * spacing(P.xz, dist0) + 0.25;\n if (uDetail > 0.5) t = min(t, 0.2 + 0.02 * dist0);\n // a pixel's own start along the ray: the edge of a rim's shadow is a line of steps, and a line of steps is jagged; with a start of its own each pixel it becomes a fine grain instead\n float jitter = fract(sin(dot(P.xz, vec2(12.9898, 78.233))) * 43758.5453);\n float range = uHzOn > 0.5 ? uNear.y : 80000.0;\n for (int i = 0; i < 260; i += 1) {\n if (float(i) >= uNear.x) break;\n vec2 q = P.xz + dir * t;\n float y = P.y + slope * t;\n float dist = max(t, distance(q, uEyeEN));\n float res = spacing(q, dist);\n float h = groundY(q, dist, t < 600.0, t < uNear.z ? max(0.2 * t, 2.5 * dist * uPixel) : 99.0);\n float bias = (t < 40.0 ? 0.01 : 0.3 * res) + 0.002 * t;\n if (h > y + bias) return 0.0;\n if (y > uMaxY || t > range) break;\n float step = t < 30.0 ? t * 0.045 + 0.04 : t * 0.06 + 0.5;\n t += step * (0.65 + 0.7 * jitter);\n }\n return 1.0;\n}\n\nvarying vec3 vP;\nvarying vec3 vN;\nvarying float vTone;\nvoid main() {\n vec3 n = normalize(vN);\n float mu0 = dot(n, uSun);\n float mu = max(dot(n, normalize(uEye - vP)), 0.03);\n float dist = distance(vP.xz, uEyeEN);\n float shine = 0.0;\n if (mu0 > 0.0 && uSun.y > -0.01) shine = (uShadows > 0.5 ? lit(vP + n * 0.02, dist) : 1.0) * 2.0 * mu0 / (mu0 + mu);\n float light = uAlbedo * 1.1 * vTone * (shine + 0.12 * (n.y * 0.5 + 0.5)) * uExposure; // the shade of a stone is lit by the ground round it\n gl_FragColor = vec4(vec3(pow(clamp(light, 0.0, 1.0), 1.0 / 2.2)), 1.0);\n}\n";
|
|
@@ -17,7 +17,7 @@ export declare const SHADOW_FRAGMENT = "\nprecision highp float;\nvarying vec2 v
|
|
|
17
17
|
/** A flat disc that always faces the viewer, set at a direction and a size: the Sun, and the Earth with its lit side toward the Sun. */
|
|
18
18
|
export declare const DISC_VERTEX = "\nprecision highp float;\n// position (declared by three.js) holds the corners of a square, -1 to 1\nuniform mat4 uVP;\nuniform vec3 uEyeWorld;\nuniform vec3 uDirWorld; // unit, scene frame\nuniform vec3 uRightWorld;\nuniform vec3 uUpWorld;\nuniform float uHalf; // half the square's side as a share of the distance\nvarying vec2 vUv;\nvoid main() {\n vUv = position.xy;\n float d = 400000.0;\n vec3 w = uEyeWorld + uDirWorld * d + (uRightWorld * position.x + uUpWorld * position.y) * uHalf * d;\n gl_Position = uVP * vec4(w, 1.0);\n}\n";
|
|
19
19
|
/** The Sun as a disc, or the Earth as a lit sphere: the same shader, `uKind` 0 for the Sun and 1 for the Earth. */
|
|
20
|
-
export declare const DISC_FRAGMENT = "\nprecision highp float;\nuniform float uKind;\nuniform vec3 uSunEnu; // the Sun's direction in the sky's own frame (east, north, up)\nuniform vec3 uDirEnu; // the disc's direction in the same frame\nuniform vec3 uRightEnu;\nuniform vec3 uUpEnu;\nuniform float uExposure;\nvarying vec2 vUv;\nvoid main() {\n float r2 = dot(vUv, vUv);\n if (r2 > 1.0) discard;\n if (uKind < 0.5) { gl_FragColor = vec4(vec3(1.0), 1.0); return; }\n // the sphere's normal toward the viewer, in the sky's frame: the viewer looks along uDirEnu, so the face toward it points the other way\n vec3 nrm = normalize(-uDirEnu * sqrt(1.0 - r2) + uRightEnu * vUv.x + uUpEnu * vUv.y);\n float d = dot(nrm, uSunEnu);\n float day = smoothstep(-0.02, 0.06, d);\n vec3 ocean = vec3(0.10, 0.27, 0.62);\n vec3 cloud = vec3(0.85, 0.88, 0.92);\n
|
|
20
|
+
export declare const DISC_FRAGMENT = "\nprecision highp float;\nuniform float uKind;\nuniform vec3 uSunEnu; // the Sun's direction in the sky's own frame (east, north, up)\nuniform vec3 uDirEnu; // the disc's direction in the same frame\nuniform vec3 uRightEnu;\nuniform vec3 uUpEnu;\nuniform float uExposure;\nvarying vec2 vUv;\nfloat hash3(vec3 p) { return fract(sin(dot(p, vec3(127.1, 311.7, 74.7))) * 43758.5453); }\nfloat vnoise3(vec3 p) {\n vec3 i = floor(p);\n vec3 f = fract(p);\n f = f * f * (3.0 - 2.0 * f);\n return mix(\n mix(mix(hash3(i), hash3(i + vec3(1.0, 0.0, 0.0)), f.x), mix(hash3(i + vec3(0.0, 1.0, 0.0)), hash3(i + vec3(1.0, 1.0, 0.0)), f.x), f.y),\n mix(mix(hash3(i + vec3(0.0, 0.0, 1.0)), hash3(i + vec3(1.0, 0.0, 1.0)), f.x), mix(hash3(i + vec3(0.0, 1.0, 1.0)), hash3(i + vec3(1.0, 1.0, 1.0)), f.x), f.y),\n f.z);\n}\nvoid main() {\n float r2 = dot(vUv, vUv);\n if (r2 > 1.0) discard;\n if (uKind < 0.5) { gl_FragColor = vec4(vec3(1.0), 1.0); return; }\n // the sphere's normal toward the viewer, in the sky's frame: the viewer looks along uDirEnu, so the face toward it points the other way\n vec3 nrm = normalize(-uDirEnu * sqrt(1.0 - r2) + uRightEnu * vUv.x + uUpEnu * vUv.y);\n float d = dot(nrm, uSunEnu);\n float day = smoothstep(-0.02, 0.06, d);\n vec3 ocean = vec3(0.10, 0.27, 0.62);\n vec3 cloud = vec3(0.85, 0.88, 0.92);\n // clouds as noise in all three directions: a sine along one axis is a band, and with the sky's vertical as that axis it reads as a gas giant's\n float blotch = 0.65 * vnoise3(nrm * 4.0) + 0.35 * vnoise3(nrm * 9.0);\n vec3 c = mix(ocean, cloud, smoothstep(0.5, 0.8, blotch) * 0.6);\n float limb = 1.0 - 0.35 * r2;\n vec3 colour = c * (0.04 + 0.96 * max(d, 0.0)) * day * limb;\n colour += c * 0.012; // the night side's own faint light\n gl_FragColor = vec4(pow(clamp(colour, 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);\n}\n";
|
|
21
21
|
/** The rover's traverse as a faint pair of tracks on the ground: a strip along the published line, its heights read from the same pyramid and made craters as the ground, drawn a hair over it. */
|
|
22
22
|
export declare const TRACK_VERTEX = "\nprecision highp float;\nprecision highp sampler2D;\nuniform mat4 uVP;\nuniform vec2 uEyeEN;\n\nuniform sampler2D uH0;\nuniform sampler2D uH1;\nuniform sampler2D uH2;\nuniform sampler2D uH3;\nuniform sampler2D uA0; // the ground picture on the first three levels, 0 to 1 with the middle at 0.5\nuniform sampler2D uA1;\nuniform sampler2D uA2;\nuniform float uPicture; // 1 where the picture is there\nuniform vec4 uL0; // half width, metres a sample, samples across, the distance out to which this level is used\nuniform vec4 uL1;\nuniform vec4 uL2;\nuniform vec4 uL3;\nuniform float uHmin;\nuniform float uHrange;\nuniform float uGround;\nuniform float uRadius;\n\nuniform vec2 uFarHeight; // the range the coarse level is encoded over: its minimum and its span\nfloat dec(vec4 t, vec2 hr) { return hr.x + (t.r * 255.0 * 256.0 + t.g * 255.0) / 65535.0 * hr.y; }\n\nfloat lin(sampler2D s, vec2 p, vec4 l, vec2 hr) {\n vec2 f = vec2((p.x + l.x) / l.y - 0.5, (l.x - p.y) / l.y - 0.5);\n vec2 i = floor(f);\n vec2 t = f - i;\n float st = 1.0 / l.z;\n vec2 uv = (i + 0.5) * st;\n float a = dec(texture2D(s, uv), hr);\n float b = dec(texture2D(s, uv + vec2(st, 0.0)), hr);\n float c = dec(texture2D(s, uv + vec2(0.0, st)), hr);\n float d = dec(texture2D(s, uv + vec2(st, st)), hr);\n return mix(mix(a, b, t.x), mix(c, d, t.x), t.y);\n}\n\nfloat nearest(sampler2D s, vec2 p, vec4 l, vec2 hr) {\n vec2 uv = vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z));\n return dec(texture2D(s, uv), hr);\n}\n\nbool holds(vec2 p, vec4 l, float dist) { return dist < l.w && abs(p.x) < l.x - 2.0 * l.y && abs(p.y) < l.x - 2.0 * l.y; }\n\n// the ground's height over the site's, the sphere's fall taken off; `fine` reads four samples, otherwise one\nfloat terrainY(vec2 p, float dist, bool fine) {\n float h;\n if (holds(p, uL0, dist)) h = fine ? lin(uH0, p, uL0, vec2(uHmin, uHrange)) : nearest(uH0, p, uL0, vec2(uHmin, uHrange));\n else if (holds(p, uL1, dist)) h = fine ? lin(uH1, p, uL1, vec2(uHmin, uHrange)) : nearest(uH1, p, uL1, vec2(uHmin, uHrange));\n else if (holds(p, uL2, dist)) h = fine ? lin(uH2, p, uL2, vec2(uHmin, uHrange)) : nearest(uH2, p, uL2, vec2(uHmin, uHrange));\n else h = fine ? lin(uH3, p, uL3, uFarHeight) : nearest(uH3, p, uL3, uFarHeight);\n return h - uGround - dot(p, p) / (2.0 * uRadius);\n}\n\n// the ground's own brightness at a point, from the picture of the level that serves it, 1 where it is the middle\nfloat albedoAt(vec2 p, float dist) {\n if (uPicture < 0.5) return 1.0;\n vec4 l;\n if (holds(p, uL0, dist)) { l = uL0; return 2.0 * texture2D(uA0, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n if (holds(p, uL1, dist)) { l = uL1; return 2.0 * texture2D(uA1, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n if (holds(p, uL2, dist)) { l = uL2; return 2.0 * texture2D(uA2, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n return 1.0;\n}\n\n// the measured ground's shadows, baked (scripts/make-moon-terrain.py): for a point, the elevation angle in degrees of the horizon toward the Sun, read from the finest of the three horizon maps that holds the point\nuniform sampler2D uZ0;\nuniform sampler2D uZ1;\nuniform sampler2D uZ2;\nuniform float uHzOn; // 1 where the maps are there\nuniform vec3 uHzSun; // the two directions (of 18) the Sun's azimuth lies between, and the share of the second\nuniform vec2 uHzRange; // the degrees the codes 0 and 255 stand for\n\nfloat hzSector(sampler2D s, vec2 cell, float k) {\n float slab = floor(k / 3.0);\n float ch = k - slab * 3.0;\n vec3 v = texture2D(s, vec2((cell.x + slab) / 6.0, cell.y)).rgb;\n return ch < 0.5 ? v.r : (ch < 1.5 ? v.g : v.b);\n}\n\nfloat hzFrom(sampler2D s, vec2 p, float reach) {\n vec2 cell = clamp(vec2((p.x + reach) / (2.0 * reach), (reach - p.y) / (2.0 * reach)), vec2(0.5 / 512.0), vec2(1.0 - 0.5 / 512.0));\n float code = mix(hzSector(s, cell, uHzSun.x), hzSector(s, cell, uHzSun.y), uHzSun.z);\n return uHzRange.x + code * (uHzRange.y - uHzRange.x);\n}\n\nfloat horizonAt(vec2 p) {\n if (abs(p.x) < uL0.x && abs(p.y) < uL0.x) return hzFrom(uZ0, p, uL0.x);\n if (abs(p.x) < uL1.x && abs(p.y) < uL1.x) return hzFrom(uZ1, p, uL1.x);\n if (abs(p.x) < uL2.x && abs(p.y) < uL2.x) return hzFrom(uZ2, p, uL2.x);\n return -90.0;\n}\n\n// the spacing of the level that serves a point, for the step of a slope\nfloat spacing(vec2 p, float dist) {\n if (holds(p, uL0, dist)) return uL0.y;\n if (holds(p, uL1, dist)) return uL1.y;\n if (holds(p, uL2, dist)) return uL2.y;\n return uL3.y;\n}\n\n\nuniform float uPixel; // the angle one pixel takes, radians\nuniform float uDetail; // 1 for the made detail, 0 for none\n\nuvec2 pcg2d(uvec2 v) {\n v = v * 1664525u + 1013904223u;\n v.x += v.y * 1664525u;\n v.y += v.x * 1664525u;\n v = v ^ (v >> 16u);\n v.x += v.y * 1664525u;\n v.y += v.x * 1664525u;\n v = v ^ (v >> 16u);\n return v;\n}\nfloat u24(uint h) { return float(h >> 8u) * (1.0 / 16777216.0); }\n\nuniform vec4 uKeep[6]; // the objects the made ground keeps away from: east, north, the distance inside which nothing is made, the distance outside which it all is\nuniform float uKeepCount;\nfloat keepMask(vec2 p) {\n float keep = 1.0;\n for (int i = 0; i < 6; i += 1) {\n if (float(i) >= uKeepCount) break;\n vec4 k = uKeep[i];\n float t = clamp((distance(p, k.xy) - k.z) / (k.w - k.z), 0.0, 1.0);\n keep = min(keep, t * t * (3.0 - 2.0 * t));\n }\n return keep;\n}\n\n// the made ground at a point: x the height in metres, yz the slope east and north, from every crater of every octave whose nominal diameter is over `fromD`\nvec3 madeGround(vec2 p, float fromD) {\n vec3 sum = vec3(0.0);\n for (int octave = 5; octave >= 0; octave -= 1) {\n float nominal = 0.5 * exp2(float(octave));\n float fade = clamp(nominal / fromD - 1.0, 0.0, 1.0);\n if (fade <= 0.0) break;\n float cell = 3.0 * nominal;\n ivec2 base = ivec2(floor(p / cell));\n vec2 fr = p / cell - vec2(base);\n float occ = (octave >= 3 ? 0.5 : 1.0) * 0.36 * exp2(-0.5 * float(octave));\n for (int j = -1; j <= 1; j += 1) {\n for (int i = -1; i <= 1; i += 1) {\n // a crater is kept to the middle of its cell, so a neighbour's reaches this cell only within a fifth of the edge\n if ((i == -1 && fr.x > 0.2) || (i == 1 && fr.x < 0.8) || (j == -1 && fr.y > 0.2) || (j == 1 && fr.y < 0.8)) continue;\n ivec2 c = base + ivec2(i, j);\n uvec2 ab = pcg2d(uvec2(uint(c.x), uint(c.y + octave * 7919)));\n if (u24(ab.x) >= occ) continue;\n uvec2 cd = pcg2d(uvec2(uint(c.x + 104729), uint(c.y + octave * 7919 + 15485863)));\n float diameter = nominal * (1.0 + (octave == 5 ? 0.25 : 1.0) * u24(cd.y));\n float r4 = float(ab.x & 255u) / 255.0;\n float age = 1.0 - r4 * r4 * r4 * r4;\n float radius = 0.5 * diameter;\n float vary = 0.6 + 0.4 * (float(cd.x & 255u) / 255.0);\n float depth = diameter * (0.2 - 0.17 * age) * vary;\n float rim = 0.045 * diameter * pow(1.0 - age, 1.5);\n float rimWidth = 0.22 + 0.5 * age;\n vec2 centre = vec2(float(c.x) + 0.25 + 0.5 * u24(ab.y), float(c.y) + 0.25 + 0.5 * u24(cd.x)) * cell;\n vec2 d = p - centre;\n float r = length(d);\n float x = r / radius;\n float h = 0.0;\n float dh = 0.0;\n if (x < 1.0) { float bowl = 1.0 - x * x; float pw = 1.0 + age; h = -depth * pow(bowl, pw); dh = 2.0 * depth * pw * x * pow(bowl, age); }\n float e = (x - 1.0) / rimWidth;\n float ex = exp(-e * e);\n h += rim * ex;\n dh += -2.0 * rim * e * ex / rimWidth;\n if (x > 1.0) { float t = 1.0 / x; h += 0.25 * rim * t * t * t; dh += -0.75 * rim * t * t * t * t; }\n float k = r > 1e-6 ? dh / (radius * r) : 0.0;\n sum += fade * vec3(h, k * d.x, k * d.y);\n }\n }\n }\n return sum * keepMask(p);\n}\n\nfloat vnoise(vec2 p) {\n vec2 i = floor(p);\n vec2 f = p - i;\n vec2 w = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);\n uvec2 c = uvec2(ivec2(i));\n float a = u24(pcg2d(c).x);\n float b = u24(pcg2d(c + uvec2(1u, 0u)).x);\n float cc = u24(pcg2d(c + uvec2(0u, 1u)).x);\n float d = u24(pcg2d(c + uvec2(1u, 1u)).x);\n return mix(mix(a, b, w.x), mix(cc, d, w.x), w.y);\n}\n\n// a fine roughness of the dust: two scales, as a slope (east, north), faded out where a pixel covers more than a few of its grains\nvec2 roughness(vec2 p, float footprint) {\n vec2 g = vec2(0.0);\n for (int k = 0; k < 2; k += 1) {\n float s = k == 0 ? 0.07 : 0.3;\n float amp = k == 0 ? 0.3 : 0.28;\n float fade = smoothstep(footprint * 2.0, footprint * 7.0, s);\n if (fade <= 0.0) continue;\n float d = s * 0.25;\n vec2 q = (k == 0 ? vec2(p.x * 0.629 + p.y * 0.777, p.y * 0.629 - p.x * 0.777) : vec2(p.x * 0.857 - p.y * 0.515, p.x * 0.515 + p.y * 0.857)) / s;\n float dx = vnoise(q + vec2(0.25, 0.0)) - vnoise(q - vec2(0.25, 0.0));\n float dy = vnoise(q + vec2(0.0, 0.25)) - vnoise(q - vec2(0.0, 0.25));\n g += fade * amp * vec2(dx, dy) / (0.5 * s) * 0.012;\n }\n return g;\n}\n\nvarying vec2 vUv;\nvarying float vDist;\nvoid main() {\n vec2 p = position.xy;\n float dist = distance(p, uEyeEN);\n vUv = uv;\n vDist = dist;\n if (dist > 600.0) {\n gl_Position = vec4(2.0, 2.0, 2.0, 1.0);\n return;\n }\n float y = terrainY(p, dist, true);\n if (uDetail > 0.5) y += madeGround(p, max(2.5 * dist * uPixel, 0.06 * dist)).x;\n y += 0.03 + 0.0007 * dist;\n gl_Position = uVP * vec4(p.x, y, -p.y, 1.0);\n}\n";
|
|
23
23
|
export declare const TRACK_FRAGMENT = "\nprecision highp float;\nvarying vec2 vUv;\nvarying float vDist;\nvoid main() {\n // two bands, a wheel's width each, a gauge apart, broken a little along the way, fading out with the distance: faint on purpose\n float band = smoothstep(0.11, 0.0, abs(abs(vUv.y) - 0.64));\n float broken = 0.65 + 0.35 * fract(sin(floor(vUv.x * 3.0) * 12.9898) * 43758.5453);\n float a = band * broken * 0.14 * (1.0 - smoothstep(250.0, 600.0, vDist));\n if (a < 0.004) discard;\n gl_FragColor = vec4(0.0, 0.0, 0.0, a);\n}\n";
|
package/dist/surface/glsl.js
CHANGED
|
@@ -303,7 +303,8 @@ void main() {
|
|
|
303
303
|
vec2 slope = vec2((hE - hW) / (2.0 * e), (hN - hS) / (2.0 * e));
|
|
304
304
|
if (uDetail > 0.5) {
|
|
305
305
|
if (fromD < 24.0) slope += madeGround(vP.xz, fromD).yz;
|
|
306
|
-
|
|
306
|
+
// the dust's grain only where the Sun is well on the ground: where it grazes, a grain a degree off lights or darkens each cell and the grain reads as blocks
|
|
307
|
+
slope += roughness(vP.xz, dist * uPixel) * smoothstep(0.0, 0.12, dot(normalize(vec3(-slope.x, 1.0, -slope.y)), uSun));
|
|
307
308
|
}
|
|
308
309
|
vec3 n = normalize(vec3(-slope.x, 1.0, -slope.y));
|
|
309
310
|
float mu0 = dot(n, uSun);
|
|
@@ -398,6 +399,16 @@ uniform vec3 uRightEnu;
|
|
|
398
399
|
uniform vec3 uUpEnu;
|
|
399
400
|
uniform float uExposure;
|
|
400
401
|
varying vec2 vUv;
|
|
402
|
+
float hash3(vec3 p) { return fract(sin(dot(p, vec3(127.1, 311.7, 74.7))) * 43758.5453); }
|
|
403
|
+
float vnoise3(vec3 p) {
|
|
404
|
+
vec3 i = floor(p);
|
|
405
|
+
vec3 f = fract(p);
|
|
406
|
+
f = f * f * (3.0 - 2.0 * f);
|
|
407
|
+
return mix(
|
|
408
|
+
mix(mix(hash3(i), hash3(i + vec3(1.0, 0.0, 0.0)), f.x), mix(hash3(i + vec3(0.0, 1.0, 0.0)), hash3(i + vec3(1.0, 1.0, 0.0)), f.x), f.y),
|
|
409
|
+
mix(mix(hash3(i + vec3(0.0, 0.0, 1.0)), hash3(i + vec3(1.0, 0.0, 1.0)), f.x), mix(hash3(i + vec3(0.0, 1.0, 1.0)), hash3(i + vec3(1.0, 1.0, 1.0)), f.x), f.y),
|
|
410
|
+
f.z);
|
|
411
|
+
}
|
|
401
412
|
void main() {
|
|
402
413
|
float r2 = dot(vUv, vUv);
|
|
403
414
|
if (r2 > 1.0) discard;
|
|
@@ -408,8 +419,9 @@ void main() {
|
|
|
408
419
|
float day = smoothstep(-0.02, 0.06, d);
|
|
409
420
|
vec3 ocean = vec3(0.10, 0.27, 0.62);
|
|
410
421
|
vec3 cloud = vec3(0.85, 0.88, 0.92);
|
|
411
|
-
|
|
412
|
-
|
|
422
|
+
// clouds as noise in all three directions: a sine along one axis is a band, and with the sky's vertical as that axis it reads as a gas giant's
|
|
423
|
+
float blotch = 0.65 * vnoise3(nrm * 4.0) + 0.35 * vnoise3(nrm * 9.0);
|
|
424
|
+
vec3 c = mix(ocean, cloud, smoothstep(0.5, 0.8, blotch) * 0.6);
|
|
413
425
|
float limb = 1.0 - 0.35 * r2;
|
|
414
426
|
vec3 colour = c * (0.04 + 0.96 * max(d, 0.0)) * day * limb;
|
|
415
427
|
colour += c * 0.012; // the night side's own faint light
|
package/dist/surface/height.d.ts
CHANGED
|
@@ -124,6 +124,13 @@ export interface HeightLevel extends HeightLevelInfo {
|
|
|
124
124
|
* ```
|
|
125
125
|
*/
|
|
126
126
|
export declare function tileAddress(base: string, manifest: Pick<TerrainManifest, "body" | "site" | "format">, level: string, column: number, row: number): string;
|
|
127
|
+
/**
|
|
128
|
+
* Credits joined into one line, each name once: a credit is a list of names, and the heights and the ground picture of a site often name the same one.
|
|
129
|
+
*
|
|
130
|
+
* @param credits - The credits, each a list of names split by commas (a comma inside brackets stays in its name); `undefined` is skipped.
|
|
131
|
+
* @returns The names in the order first met, split by commas.
|
|
132
|
+
*/
|
|
133
|
+
export declare function joinCredits(...credits: readonly (string | undefined)[]): string;
|
|
127
134
|
/**
|
|
128
135
|
* An empty level, ready to be filled tile by tile: every height the lowest the encoding holds until a tile says otherwise.
|
|
129
136
|
*
|
package/dist/surface/height.js
CHANGED
|
@@ -21,6 +21,16 @@
|
|
|
21
21
|
export function tileAddress(base, manifest, level, column, row) {
|
|
22
22
|
return `${base.endsWith("/") ? base : `${base}/`}${manifest.body}/${manifest.site}/terrain/${level}/${column}/${row}.${manifest.format ?? "png"}`;
|
|
23
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Credits joined into one line, each name once: a credit is a list of names, and the heights and the ground picture of a site often name the same one.
|
|
26
|
+
*
|
|
27
|
+
* @param credits - The credits, each a list of names split by commas (a comma inside brackets stays in its name); `undefined` is skipped.
|
|
28
|
+
* @returns The names in the order first met, split by commas.
|
|
29
|
+
*/
|
|
30
|
+
export function joinCredits(...credits) {
|
|
31
|
+
const names = credits.flatMap((credit) => (credit ?? "").split(/,\s*(?![^(]*\))/).map((name) => name.trim()));
|
|
32
|
+
return [...new Set(names.filter((name) => name !== ""))].join(", ");
|
|
33
|
+
}
|
|
24
34
|
/**
|
|
25
35
|
* An empty level, ready to be filled tile by tile: every height the lowest the encoding holds until a tile says otherwise.
|
|
26
36
|
*
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnmorrisdotca/wakusei-planets",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.70.0",
|
|
4
4
|
"description": "Wakusei Planets 惑星 — The Sun, planets and moons for the web: each as a clean line drawing, a shaded realistic drawing or a painted surface map, with real sizes, axial tilt and rotation as data, and positions of the moons for any date and time. SVG for the lines, three.js (optional) for the rest.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"planets",
|