@johnmorrisdotca/wakusei-planets 0.46.0 → 0.47.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 +5 -0
- package/NOTICE.md +1 -0
- package/README.md +3 -3
- package/dist/scene/body.d.ts +1 -1
- package/dist/scene/textures.d.ts +2 -2
- package/dist/surface/detail.d.ts +17 -0
- package/dist/surface/detail.js +25 -1
- package/dist/surface/element.d.ts +13 -0
- package/dist/surface/element.js +218 -15
- package/dist/surface/glsl.d.ts +11 -5
- package/dist/surface/glsl.js +55 -1
- package/dist/surface/index.d.ts +3 -1
- package/dist/surface/index.js +3 -1
- package/dist/surface/objects-apollo-17.d.ts +4 -0
- package/dist/surface/objects-apollo-17.js +19 -0
- package/dist/surface/objects.d.ts +127 -0
- package/dist/surface/objects.js +179 -0
- package/dist/surface/scene.d.ts +8 -0
- package/dist/surface/scene.js +169 -4
- package/dist/surface/shapes.d.ts +62 -0
- package/dist/surface/shapes.js +247 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/surface/glsl.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
/** The uniforms of the pyramid every shader reads, and the one function that reads it: `terrainY(point, distance)`, metres over the site's ground, the Moon's curve taken off. */
|
|
2
2
|
export declare const HEIGHTS = "\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";
|
|
3
3
|
/** The made detail, in GLSL: the same formulas as `detail.ts` (craters on a seeded grid, by octave), and a fine roughness for the normals. */
|
|
4
|
-
export declare const DETAIL = "\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\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;\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";
|
|
4
|
+
export declare const DETAIL = "\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";
|
|
5
5
|
/** The ground's vertices: a ring index and an angle across the view, laid out as the viewer's own polar grid, then raised to the measured heights. */
|
|
6
|
-
export declare const GROUND_VERTEX = "\nprecision highp float;\nprecision highp sampler2D;\n// position (declared by three.js) holds x: 0 to 1 out along the rays (ring spacing grows with the distance), y: -1 to 1 across the view\nuniform mat4 uVP;\nuniform vec2 uEyeEN; // the eyes' place in the site's plane: east, north\nuniform float uYaw; // radians, clockwise from north\nuniform float uSpan; // half the angle drawn across the view, radians\nuniform float uRMin;\nuniform float uRMax;\n\nuniform sampler2D uH0;\nuniform sampler2D uH1;\nuniform sampler2D uH2;\nuniform sampler2D uH3;\nuniform sampler2D uA0; // the ground picture on the first three levels, 0 to 1 with the middle at 0.5\nuniform sampler2D uA1;\nuniform sampler2D uA2;\nuniform float uPicture; // 1 where the picture is there\nuniform vec4 uL0; // half width, metres a sample, samples across, the distance out to which this level is used\nuniform vec4 uL1;\nuniform vec4 uL2;\nuniform vec4 uL3;\nuniform float uHmin;\nuniform float uHrange;\nuniform float uGround;\nuniform float uRadius;\n\nuniform vec2 uFarHeight; // the range the coarse level is encoded over: its minimum and its span\nfloat dec(vec4 t, vec2 hr) { return hr.x + (t.r * 255.0 * 256.0 + t.g * 255.0) / 65535.0 * hr.y; }\n\nfloat lin(sampler2D s, vec2 p, vec4 l, vec2 hr) {\n vec2 f = vec2((p.x + l.x) / l.y - 0.5, (l.x - p.y) / l.y - 0.5);\n vec2 i = floor(f);\n vec2 t = f - i;\n float st = 1.0 / l.z;\n vec2 uv = (i + 0.5) * st;\n float a = dec(texture2D(s, uv), hr);\n float b = dec(texture2D(s, uv + vec2(st, 0.0)), hr);\n float c = dec(texture2D(s, uv + vec2(0.0, st)), hr);\n float d = dec(texture2D(s, uv + vec2(st, st)), hr);\n return mix(mix(a, b, t.x), mix(c, d, t.x), t.y);\n}\n\nfloat nearest(sampler2D s, vec2 p, vec4 l, vec2 hr) {\n vec2 uv = vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z));\n return dec(texture2D(s, uv), hr);\n}\n\nbool holds(vec2 p, vec4 l, float dist) { return dist < l.w && abs(p.x) < l.x - 2.0 * l.y && abs(p.y) < l.x - 2.0 * l.y; }\n\n// the ground's height over the site's, the sphere's fall taken off; `fine` reads four samples, otherwise one\nfloat terrainY(vec2 p, float dist, bool fine) {\n float h;\n if (holds(p, uL0, dist)) h = fine ? lin(uH0, p, uL0, vec2(uHmin, uHrange)) : nearest(uH0, p, uL0, vec2(uHmin, uHrange));\n else if (holds(p, uL1, dist)) h = fine ? lin(uH1, p, uL1, vec2(uHmin, uHrange)) : nearest(uH1, p, uL1, vec2(uHmin, uHrange));\n else if (holds(p, uL2, dist)) h = fine ? lin(uH2, p, uL2, vec2(uHmin, uHrange)) : nearest(uH2, p, uL2, vec2(uHmin, uHrange));\n else h = fine ? lin(uH3, p, uL3, uFarHeight) : nearest(uH3, p, uL3, uFarHeight);\n return h - uGround - dot(p, p) / (2.0 * uRadius);\n}\n\n// the ground's own brightness at a point, from the picture of the level that serves it, 1 where it is the middle\nfloat albedoAt(vec2 p, float dist) {\n if (uPicture < 0.5) return 1.0;\n vec4 l;\n if (holds(p, uL0, dist)) { l = uL0; return 2.0 * texture2D(uA0, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n if (holds(p, uL1, dist)) { l = uL1; return 2.0 * texture2D(uA1, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n if (holds(p, uL2, dist)) { l = uL2; return 2.0 * texture2D(uA2, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n return 1.0;\n}\n\n// the measured ground's shadows, baked (scripts/make-moon-terrain.py): for a point, the elevation angle in degrees of the horizon toward the Sun, read from the finest of the three horizon maps that holds the point\nuniform sampler2D uZ0;\nuniform sampler2D uZ1;\nuniform sampler2D uZ2;\nuniform float uHzOn; // 1 where the maps are there\nuniform vec3 uHzSun; // the two directions (of 18) the Sun's azimuth lies between, and the share of the second\nuniform vec2 uHzRange; // the degrees the codes 0 and 255 stand for\n\nfloat hzSector(sampler2D s, vec2 cell, float k) {\n float slab = floor(k / 3.0);\n float ch = k - slab * 3.0;\n vec3 v = texture2D(s, vec2((cell.x + slab) / 6.0, cell.y)).rgb;\n return ch < 0.5 ? v.r : (ch < 1.5 ? v.g : v.b);\n}\n\nfloat hzFrom(sampler2D s, vec2 p, float reach) {\n vec2 cell = clamp(vec2((p.x + reach) / (2.0 * reach), (reach - p.y) / (2.0 * reach)), vec2(0.5 / 512.0), vec2(1.0 - 0.5 / 512.0));\n float code = mix(hzSector(s, cell, uHzSun.x), hzSector(s, cell, uHzSun.y), uHzSun.z);\n return uHzRange.x + code * (uHzRange.y - uHzRange.x);\n}\n\nfloat horizonAt(vec2 p) {\n if (abs(p.x) < uL0.x && abs(p.y) < uL0.x) return hzFrom(uZ0, p, uL0.x);\n if (abs(p.x) < uL1.x && abs(p.y) < uL1.x) return hzFrom(uZ1, p, uL1.x);\n if (abs(p.x) < uL2.x && abs(p.y) < uL2.x) return hzFrom(uZ2, p, uL2.x);\n return -90.0;\n}\n\n// the spacing of the level that serves a point, for the step of a slope\nfloat spacing(vec2 p, float dist) {\n if (holds(p, uL0, dist)) return uL0.y;\n if (holds(p, uL1, dist)) return uL1.y;\n if (holds(p, uL2, dist)) return uL2.y;\n return uL3.y;\n}\n\n\nuniform float uPixel; // the angle one pixel takes, radians\nuniform float uDetail; // 1 for the made detail, 0 for none\n\nuvec2 pcg2d(uvec2 v) {\n v = v * 1664525u + 1013904223u;\n v.x += v.y * 1664525u;\n v.y += v.x * 1664525u;\n v = v ^ (v >> 16u);\n v.x += v.y * 1664525u;\n v.y += v.x * 1664525u;\n v = v ^ (v >> 16u);\n return v;\n}\nfloat u24(uint h) { return float(h >> 8u) * (1.0 / 16777216.0); }\n\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;\n}\n\nfloat vnoise(vec2 p) {\n vec2 i = floor(p);\n vec2 f = p - i;\n vec2 w = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);\n uvec2 c = uvec2(ivec2(i));\n float a = u24(pcg2d(c).x);\n float b = u24(pcg2d(c + uvec2(1u, 0u)).x);\n float cc = u24(pcg2d(c + uvec2(0u, 1u)).x);\n float d = u24(pcg2d(c + uvec2(1u, 1u)).x);\n return mix(mix(a, b, w.x), mix(cc, d, w.x), w.y);\n}\n\n// a fine roughness of the dust: two scales, as a slope (east, north), faded out where a pixel covers more than a few of its grains\nvec2 roughness(vec2 p, float footprint) {\n vec2 g = vec2(0.0);\n for (int k = 0; k < 2; k += 1) {\n float s = k == 0 ? 0.07 : 0.3;\n float amp = k == 0 ? 0.3 : 0.28;\n float fade = smoothstep(footprint * 2.0, footprint * 7.0, s);\n if (fade <= 0.0) continue;\n float d = s * 0.25;\n vec2 q = (k == 0 ? vec2(p.x * 0.629 + p.y * 0.777, p.y * 0.629 - p.x * 0.777) : vec2(p.x * 0.857 - p.y * 0.515, p.x * 0.515 + p.y * 0.857)) / s;\n float dx = vnoise(q + vec2(0.25, 0.0)) - vnoise(q - vec2(0.25, 0.0));\n float dy = vnoise(q + vec2(0.0, 0.25)) - vnoise(q - vec2(0.0, 0.25));\n g += fade * amp * vec2(dx, dy) / (0.5 * s) * 0.012;\n }\n return g;\n}\n\nvarying vec3 vP;\nvoid main() {\n float r = uRMin * pow(uRMax / uRMin, position.x);\n float a = uYaw + position.y * uSpan;\n vec2 p = uEyeEN + r * vec2(sin(a), cos(a));\n float y = terrainY(p, r, true);\n // the made craters, those the mesh can hold here: bigger than a few of its steps\n if (uDetail > 0.5 && r < 3000.0) y += madeGround(p, max(2.5 * r * uPixel, 0.06 * r)).x;\n vP = vec3(p.x, y, p.y);\n gl_Position = uVP * vec4(p.x, y, -p.y, 1.0);\n}\n";
|
|
6
|
+
export declare const GROUND_VERTEX = "\nprecision highp float;\nprecision highp sampler2D;\n// position (declared by three.js) holds x: 0 to 1 out along the rays (ring spacing grows with the distance), y: -1 to 1 across the view\nuniform mat4 uVP;\nuniform vec2 uEyeEN; // the eyes' place in the site's plane: east, north\nuniform float uYaw; // radians, clockwise from north\nuniform float uSpan; // half the angle drawn across the view, radians\nuniform float uRMin;\nuniform float uRMax;\n\nuniform sampler2D uH0;\nuniform sampler2D uH1;\nuniform sampler2D uH2;\nuniform sampler2D uH3;\nuniform sampler2D uA0; // the ground picture on the first three levels, 0 to 1 with the middle at 0.5\nuniform sampler2D uA1;\nuniform sampler2D uA2;\nuniform float uPicture; // 1 where the picture is there\nuniform vec4 uL0; // half width, metres a sample, samples across, the distance out to which this level is used\nuniform vec4 uL1;\nuniform vec4 uL2;\nuniform vec4 uL3;\nuniform float uHmin;\nuniform float uHrange;\nuniform float uGround;\nuniform float uRadius;\n\nuniform vec2 uFarHeight; // the range the coarse level is encoded over: its minimum and its span\nfloat dec(vec4 t, vec2 hr) { return hr.x + (t.r * 255.0 * 256.0 + t.g * 255.0) / 65535.0 * hr.y; }\n\nfloat lin(sampler2D s, vec2 p, vec4 l, vec2 hr) {\n vec2 f = vec2((p.x + l.x) / l.y - 0.5, (l.x - p.y) / l.y - 0.5);\n vec2 i = floor(f);\n vec2 t = f - i;\n float st = 1.0 / l.z;\n vec2 uv = (i + 0.5) * st;\n float a = dec(texture2D(s, uv), hr);\n float b = dec(texture2D(s, uv + vec2(st, 0.0)), hr);\n float c = dec(texture2D(s, uv + vec2(0.0, st)), hr);\n float d = dec(texture2D(s, uv + vec2(st, st)), hr);\n return mix(mix(a, b, t.x), mix(c, d, t.x), t.y);\n}\n\nfloat nearest(sampler2D s, vec2 p, vec4 l, vec2 hr) {\n vec2 uv = vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z));\n return dec(texture2D(s, uv), hr);\n}\n\nbool holds(vec2 p, vec4 l, float dist) { return dist < l.w && abs(p.x) < l.x - 2.0 * l.y && abs(p.y) < l.x - 2.0 * l.y; }\n\n// the ground's height over the site's, the sphere's fall taken off; `fine` reads four samples, otherwise one\nfloat terrainY(vec2 p, float dist, bool fine) {\n float h;\n if (holds(p, uL0, dist)) h = fine ? lin(uH0, p, uL0, vec2(uHmin, uHrange)) : nearest(uH0, p, uL0, vec2(uHmin, uHrange));\n else if (holds(p, uL1, dist)) h = fine ? lin(uH1, p, uL1, vec2(uHmin, uHrange)) : nearest(uH1, p, uL1, vec2(uHmin, uHrange));\n else if (holds(p, uL2, dist)) h = fine ? lin(uH2, p, uL2, vec2(uHmin, uHrange)) : nearest(uH2, p, uL2, vec2(uHmin, uHrange));\n else h = fine ? lin(uH3, p, uL3, uFarHeight) : nearest(uH3, p, uL3, uFarHeight);\n return h - uGround - dot(p, p) / (2.0 * uRadius);\n}\n\n// the ground's own brightness at a point, from the picture of the level that serves it, 1 where it is the middle\nfloat albedoAt(vec2 p, float dist) {\n if (uPicture < 0.5) return 1.0;\n vec4 l;\n if (holds(p, uL0, dist)) { l = uL0; return 2.0 * texture2D(uA0, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n if (holds(p, uL1, dist)) { l = uL1; return 2.0 * texture2D(uA1, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n if (holds(p, uL2, dist)) { l = uL2; return 2.0 * texture2D(uA2, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n return 1.0;\n}\n\n// the measured ground's shadows, baked (scripts/make-moon-terrain.py): for a point, the elevation angle in degrees of the horizon toward the Sun, read from the finest of the three horizon maps that holds the point\nuniform sampler2D uZ0;\nuniform sampler2D uZ1;\nuniform sampler2D uZ2;\nuniform float uHzOn; // 1 where the maps are there\nuniform vec3 uHzSun; // the two directions (of 18) the Sun's azimuth lies between, and the share of the second\nuniform vec2 uHzRange; // the degrees the codes 0 and 255 stand for\n\nfloat hzSector(sampler2D s, vec2 cell, float k) {\n float slab = floor(k / 3.0);\n float ch = k - slab * 3.0;\n vec3 v = texture2D(s, vec2((cell.x + slab) / 6.0, cell.y)).rgb;\n return ch < 0.5 ? v.r : (ch < 1.5 ? v.g : v.b);\n}\n\nfloat hzFrom(sampler2D s, vec2 p, float reach) {\n vec2 cell = clamp(vec2((p.x + reach) / (2.0 * reach), (reach - p.y) / (2.0 * reach)), vec2(0.5 / 512.0), vec2(1.0 - 0.5 / 512.0));\n float code = mix(hzSector(s, cell, uHzSun.x), hzSector(s, cell, uHzSun.y), uHzSun.z);\n return uHzRange.x + code * (uHzRange.y - uHzRange.x);\n}\n\nfloat horizonAt(vec2 p) {\n if (abs(p.x) < uL0.x && abs(p.y) < uL0.x) return hzFrom(uZ0, p, uL0.x);\n if (abs(p.x) < uL1.x && abs(p.y) < uL1.x) return hzFrom(uZ1, p, uL1.x);\n if (abs(p.x) < uL2.x && abs(p.y) < uL2.x) return hzFrom(uZ2, p, uL2.x);\n return -90.0;\n}\n\n// the spacing of the level that serves a point, for the step of a slope\nfloat spacing(vec2 p, float dist) {\n if (holds(p, uL0, dist)) return uL0.y;\n if (holds(p, uL1, dist)) return uL1.y;\n if (holds(p, uL2, dist)) return uL2.y;\n return uL3.y;\n}\n\n\nuniform float uPixel; // the angle one pixel takes, radians\nuniform float uDetail; // 1 for the made detail, 0 for none\n\nuvec2 pcg2d(uvec2 v) {\n v = v * 1664525u + 1013904223u;\n v.x += v.y * 1664525u;\n v.y += v.x * 1664525u;\n v = v ^ (v >> 16u);\n v.x += v.y * 1664525u;\n v.y += v.x * 1664525u;\n v = v ^ (v >> 16u);\n return v;\n}\nfloat u24(uint h) { return float(h >> 8u) * (1.0 / 16777216.0); }\n\nuniform vec4 uKeep[6]; // the objects the made ground keeps away from: east, north, the distance inside which nothing is made, the distance outside which it all is\nuniform float uKeepCount;\nfloat keepMask(vec2 p) {\n float keep = 1.0;\n for (int i = 0; i < 6; i += 1) {\n if (float(i) >= uKeepCount) break;\n vec4 k = uKeep[i];\n float t = clamp((distance(p, k.xy) - k.z) / (k.w - k.z), 0.0, 1.0);\n keep = min(keep, t * t * (3.0 - 2.0 * t));\n }\n return keep;\n}\n\n// the made ground at a point: x the height in metres, yz the slope east and north, from every crater of every octave whose nominal diameter is over `fromD`\nvec3 madeGround(vec2 p, float fromD) {\n vec3 sum = vec3(0.0);\n for (int octave = 5; octave >= 0; octave -= 1) {\n float nominal = 0.5 * exp2(float(octave));\n float fade = clamp(nominal / fromD - 1.0, 0.0, 1.0);\n if (fade <= 0.0) break;\n float cell = 3.0 * nominal;\n ivec2 base = ivec2(floor(p / cell));\n vec2 fr = p / cell - vec2(base);\n float occ = (octave >= 3 ? 0.5 : 1.0) * 0.36 * exp2(-0.5 * float(octave));\n for (int j = -1; j <= 1; j += 1) {\n for (int i = -1; i <= 1; i += 1) {\n // a crater is kept to the middle of its cell, so a neighbour's reaches this cell only within a fifth of the edge\n if ((i == -1 && fr.x > 0.2) || (i == 1 && fr.x < 0.8) || (j == -1 && fr.y > 0.2) || (j == 1 && fr.y < 0.8)) continue;\n ivec2 c = base + ivec2(i, j);\n uvec2 ab = pcg2d(uvec2(uint(c.x), uint(c.y + octave * 7919)));\n if (u24(ab.x) >= occ) continue;\n uvec2 cd = pcg2d(uvec2(uint(c.x + 104729), uint(c.y + octave * 7919 + 15485863)));\n float diameter = nominal * (1.0 + (octave == 5 ? 0.25 : 1.0) * u24(cd.y));\n float r4 = float(ab.x & 255u) / 255.0;\n float age = 1.0 - r4 * r4 * r4 * r4;\n float radius = 0.5 * diameter;\n float vary = 0.6 + 0.4 * (float(cd.x & 255u) / 255.0);\n float depth = diameter * (0.2 - 0.17 * age) * vary;\n float rim = 0.045 * diameter * pow(1.0 - age, 1.5);\n float rimWidth = 0.22 + 0.5 * age;\n vec2 centre = vec2(float(c.x) + 0.25 + 0.5 * u24(ab.y), float(c.y) + 0.25 + 0.5 * u24(cd.x)) * cell;\n vec2 d = p - centre;\n float r = length(d);\n float x = r / radius;\n float h = 0.0;\n float dh = 0.0;\n if (x < 1.0) { float bowl = 1.0 - x * x; float pw = 1.0 + age; h = -depth * pow(bowl, pw); dh = 2.0 * depth * pw * x * pow(bowl, age); }\n float e = (x - 1.0) / rimWidth;\n float ex = exp(-e * e);\n h += rim * ex;\n dh += -2.0 * rim * e * ex / rimWidth;\n if (x > 1.0) { float t = 1.0 / x; h += 0.25 * rim * t * t * t; dh += -0.75 * rim * t * t * t * t; }\n float k = r > 1e-6 ? dh / (radius * r) : 0.0;\n sum += fade * vec3(h, k * d.x, k * d.y);\n }\n }\n }\n return sum * keepMask(p);\n}\n\nfloat vnoise(vec2 p) {\n vec2 i = floor(p);\n vec2 f = p - i;\n vec2 w = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);\n uvec2 c = uvec2(ivec2(i));\n float a = u24(pcg2d(c).x);\n float b = u24(pcg2d(c + uvec2(1u, 0u)).x);\n float cc = u24(pcg2d(c + uvec2(0u, 1u)).x);\n float d = u24(pcg2d(c + uvec2(1u, 1u)).x);\n return mix(mix(a, b, w.x), mix(cc, d, w.x), w.y);\n}\n\n// a fine roughness of the dust: two scales, as a slope (east, north), faded out where a pixel covers more than a few of its grains\nvec2 roughness(vec2 p, float footprint) {\n vec2 g = vec2(0.0);\n for (int k = 0; k < 2; k += 1) {\n float s = k == 0 ? 0.07 : 0.3;\n float amp = k == 0 ? 0.3 : 0.28;\n float fade = smoothstep(footprint * 2.0, footprint * 7.0, s);\n if (fade <= 0.0) continue;\n float d = s * 0.25;\n vec2 q = (k == 0 ? vec2(p.x * 0.629 + p.y * 0.777, p.y * 0.629 - p.x * 0.777) : vec2(p.x * 0.857 - p.y * 0.515, p.x * 0.515 + p.y * 0.857)) / s;\n float dx = vnoise(q + vec2(0.25, 0.0)) - vnoise(q - vec2(0.25, 0.0));\n float dy = vnoise(q + vec2(0.0, 0.25)) - vnoise(q - vec2(0.0, 0.25));\n g += fade * amp * vec2(dx, dy) / (0.5 * s) * 0.012;\n }\n return g;\n}\n\nvarying vec3 vP;\nvoid main() {\n float r = uRMin * pow(uRMax / uRMin, position.x);\n float a = uYaw + position.y * uSpan;\n vec2 p = uEyeEN + r * vec2(sin(a), cos(a));\n float y = terrainY(p, r, true);\n // the made craters, those the mesh can hold here: bigger than a few of its steps\n if (uDetail > 0.5 && r < 3000.0) y += madeGround(p, max(2.5 * r * uPixel, 0.06 * r)).x;\n vP = vec3(p.x, y, p.y);\n gl_Position = uVP * vec4(p.x, y, -p.y, 1.0);\n}\n";
|
|
7
7
|
/** What the ground, the rocks and their shadows all need to be lit: the Sun, the eyes, the heights and the made detail, the ground's height with the craters on it, and a point's light (a hard shadow by a march toward the Sun). */
|
|
8
|
-
export declare const LIGHT = "\nuniform vec3 uSun;\nuniform vec3 uEye;\nuniform vec2 uEyeEN;\nuniform float uExposure;\nuniform float uAlbedo;\nuniform float uMaxY; // the highest ground over the site's, for the end of a shadow's march\nuniform float uEarthshine; // the light of the sunlit ground round the shade, a small share of a lit slope's\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\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;\n}\n\nfloat vnoise(vec2 p) {\n vec2 i = floor(p);\n vec2 f = p - i;\n vec2 w = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);\n uvec2 c = uvec2(ivec2(i));\n float a = u24(pcg2d(c).x);\n float b = u24(pcg2d(c + uvec2(1u, 0u)).x);\n float cc = u24(pcg2d(c + uvec2(0u, 1u)).x);\n float d = u24(pcg2d(c + uvec2(1u, 1u)).x);\n return mix(mix(a, b, w.x), mix(cc, d, w.x), w.y);\n}\n\n// a fine roughness of the dust: two scales, as a slope (east, north), faded out where a pixel covers more than a few of its grains\nvec2 roughness(vec2 p, float footprint) {\n vec2 g = vec2(0.0);\n for (int k = 0; k < 2; k += 1) {\n float s = k == 0 ? 0.07 : 0.3;\n float amp = k == 0 ? 0.3 : 0.28;\n float fade = smoothstep(footprint * 2.0, footprint * 7.0, s);\n if (fade <= 0.0) continue;\n float d = s * 0.25;\n vec2 q = (k == 0 ? vec2(p.x * 0.629 + p.y * 0.777, p.y * 0.629 - p.x * 0.777) : vec2(p.x * 0.857 - p.y * 0.515, p.x * 0.515 + p.y * 0.857)) / s;\n float dx = vnoise(q + vec2(0.25, 0.0)) - vnoise(q - vec2(0.25, 0.0));\n float dy = vnoise(q + vec2(0.0, 0.25)) - vnoise(q - vec2(0.0, 0.25));\n g += fade * amp * vec2(dx, dy) / (0.5 * s) * 0.012;\n }\n return g;\n}\n\n\n// the ground's height at a point: the measured heights and, near the eyes, the made craters (kept to the ones a pixel here can show)\nfloat groundY(vec2 p, float dist, bool fine, float fromD) {\n float y = terrainY(p, dist, fine);\n if (uDetail > 0.5 && fromD < 24.0) y += madeGround(p, fromD).x;\n return y;\n}\n\n// 1 where the Sun reaches a point, 0 where the ground is in its way. The measured ground's shadow is read from the baked horizon; the march toward the Sun over the heights (and the made craters) is the near\n// field's only, a few tens of metres with a fixed number of steps, as sharp as the Sun's edge. Where there is no baked horizon the march goes all the way, as it did before the maps.\nfloat lit(vec3 P, float dist0) {\n vec2 dir = normalize(uSun.xz);\n float slope = uSun.y / max(length(uSun.xz), 1e-4);\n if (uHzOn > 0.5 && horizonAt(P.xz) - 0.3 > uSunDegrees) return 0.0;\n // the ground at the point from the heights themselves, not the mesh's slope between its corners, which can be a long way off on a far mountain\n P.y = groundY(P.xz, dist0, true, 2.5 * dist0 * uPixel);\n float t = 0.5 * spacing(P.xz, dist0) + 0.25;\n if (uDetail > 0.5) t = min(t, 0.2 + 0.02 * dist0);\n // a pixel's own start along the ray: the edge of a rim's shadow is a line of steps, and a line of steps is jagged; with a start of its own each pixel it becomes a fine grain instead\n float jitter = fract(sin(dot(P.xz, vec2(12.9898, 78.233))) * 43758.5453);\n float range = uHzOn > 0.5 ? uNear.y : 80000.0;\n for (int i = 0; i < 260; i += 1) {\n if (float(i) >= uNear.x) break;\n vec2 q = P.xz + dir * t;\n float y = P.y + slope * t;\n float dist = max(t, distance(q, uEyeEN));\n float res = spacing(q, dist);\n float h = groundY(q, dist, t < 600.0, t < uNear.z ? max(0.2 * t, 2.5 * dist * uPixel) : 99.0);\n float bias = (t < 40.0 ? 0.01 : 0.3 * res) + 0.002 * t;\n if (h > y + bias) return 0.0;\n if (y > uMaxY || t > range) break;\n float step = t < 30.0 ? t * 0.045 + 0.04 : t * 0.06 + 0.5;\n t += step * (0.65 + 0.7 * jitter);\n }\n return 1.0;\n}\n";
|
|
8
|
+
export declare const LIGHT = "\nuniform vec3 uSun;\nuniform vec3 uEye;\nuniform vec2 uEyeEN;\nuniform float uExposure;\nuniform float uAlbedo;\nuniform float uMaxY; // the highest ground over the site's, for the end of a shadow's march\nuniform float uEarthshine; // the light of the sunlit ground round the shade, a small share of a lit slope's\nuniform float uShadows; // 1 for the ground to shadow itself (the default), 0 for none (a try-out)\nuniform float uSunDegrees; // the Sun's elevation in degrees\nuniform vec3 uNear; // the near march: steps, the distance it reaches in metres, the distance out to which the made craters are in it (the quality of the draw)\n\nuniform sampler2D uH0;\nuniform sampler2D uH1;\nuniform sampler2D uH2;\nuniform sampler2D uH3;\nuniform sampler2D uA0; // the ground picture on the first three levels, 0 to 1 with the middle at 0.5\nuniform sampler2D uA1;\nuniform sampler2D uA2;\nuniform float uPicture; // 1 where the picture is there\nuniform vec4 uL0; // half width, metres a sample, samples across, the distance out to which this level is used\nuniform vec4 uL1;\nuniform vec4 uL2;\nuniform vec4 uL3;\nuniform float uHmin;\nuniform float uHrange;\nuniform float uGround;\nuniform float uRadius;\n\nuniform vec2 uFarHeight; // the range the coarse level is encoded over: its minimum and its span\nfloat dec(vec4 t, vec2 hr) { return hr.x + (t.r * 255.0 * 256.0 + t.g * 255.0) / 65535.0 * hr.y; }\n\nfloat lin(sampler2D s, vec2 p, vec4 l, vec2 hr) {\n vec2 f = vec2((p.x + l.x) / l.y - 0.5, (l.x - p.y) / l.y - 0.5);\n vec2 i = floor(f);\n vec2 t = f - i;\n float st = 1.0 / l.z;\n vec2 uv = (i + 0.5) * st;\n float a = dec(texture2D(s, uv), hr);\n float b = dec(texture2D(s, uv + vec2(st, 0.0)), hr);\n float c = dec(texture2D(s, uv + vec2(0.0, st)), hr);\n float d = dec(texture2D(s, uv + vec2(st, st)), hr);\n return mix(mix(a, b, t.x), mix(c, d, t.x), t.y);\n}\n\nfloat nearest(sampler2D s, vec2 p, vec4 l, vec2 hr) {\n vec2 uv = vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z));\n return dec(texture2D(s, uv), hr);\n}\n\nbool holds(vec2 p, vec4 l, float dist) { return dist < l.w && abs(p.x) < l.x - 2.0 * l.y && abs(p.y) < l.x - 2.0 * l.y; }\n\n// the ground's height over the site's, the sphere's fall taken off; `fine` reads four samples, otherwise one\nfloat terrainY(vec2 p, float dist, bool fine) {\n float h;\n if (holds(p, uL0, dist)) h = fine ? lin(uH0, p, uL0, vec2(uHmin, uHrange)) : nearest(uH0, p, uL0, vec2(uHmin, uHrange));\n else if (holds(p, uL1, dist)) h = fine ? lin(uH1, p, uL1, vec2(uHmin, uHrange)) : nearest(uH1, p, uL1, vec2(uHmin, uHrange));\n else if (holds(p, uL2, dist)) h = fine ? lin(uH2, p, uL2, vec2(uHmin, uHrange)) : nearest(uH2, p, uL2, vec2(uHmin, uHrange));\n else h = fine ? lin(uH3, p, uL3, uFarHeight) : nearest(uH3, p, uL3, uFarHeight);\n return h - uGround - dot(p, p) / (2.0 * uRadius);\n}\n\n// the ground's own brightness at a point, from the picture of the level that serves it, 1 where it is the middle\nfloat albedoAt(vec2 p, float dist) {\n if (uPicture < 0.5) return 1.0;\n vec4 l;\n if (holds(p, uL0, dist)) { l = uL0; return 2.0 * texture2D(uA0, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n if (holds(p, uL1, dist)) { l = uL1; return 2.0 * texture2D(uA1, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n if (holds(p, uL2, dist)) { l = uL2; return 2.0 * texture2D(uA2, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n return 1.0;\n}\n\n// the measured ground's shadows, baked (scripts/make-moon-terrain.py): for a point, the elevation angle in degrees of the horizon toward the Sun, read from the finest of the three horizon maps that holds the point\nuniform sampler2D uZ0;\nuniform sampler2D uZ1;\nuniform sampler2D uZ2;\nuniform float uHzOn; // 1 where the maps are there\nuniform vec3 uHzSun; // the two directions (of 18) the Sun's azimuth lies between, and the share of the second\nuniform vec2 uHzRange; // the degrees the codes 0 and 255 stand for\n\nfloat hzSector(sampler2D s, vec2 cell, float k) {\n float slab = floor(k / 3.0);\n float ch = k - slab * 3.0;\n vec3 v = texture2D(s, vec2((cell.x + slab) / 6.0, cell.y)).rgb;\n return ch < 0.5 ? v.r : (ch < 1.5 ? v.g : v.b);\n}\n\nfloat hzFrom(sampler2D s, vec2 p, float reach) {\n vec2 cell = clamp(vec2((p.x + reach) / (2.0 * reach), (reach - p.y) / (2.0 * reach)), vec2(0.5 / 512.0), vec2(1.0 - 0.5 / 512.0));\n float code = mix(hzSector(s, cell, uHzSun.x), hzSector(s, cell, uHzSun.y), uHzSun.z);\n return uHzRange.x + code * (uHzRange.y - uHzRange.x);\n}\n\nfloat horizonAt(vec2 p) {\n if (abs(p.x) < uL0.x && abs(p.y) < uL0.x) return hzFrom(uZ0, p, uL0.x);\n if (abs(p.x) < uL1.x && abs(p.y) < uL1.x) return hzFrom(uZ1, p, uL1.x);\n if (abs(p.x) < uL2.x && abs(p.y) < uL2.x) return hzFrom(uZ2, p, uL2.x);\n return -90.0;\n}\n\n// the spacing of the level that serves a point, for the step of a slope\nfloat spacing(vec2 p, float dist) {\n if (holds(p, uL0, dist)) return uL0.y;\n if (holds(p, uL1, dist)) return uL1.y;\n if (holds(p, uL2, dist)) return uL2.y;\n return uL3.y;\n}\n\n\nuniform float uPixel; // the angle one pixel takes, radians\nuniform float uDetail; // 1 for the made detail, 0 for none\n\nuvec2 pcg2d(uvec2 v) {\n v = v * 1664525u + 1013904223u;\n v.x += v.y * 1664525u;\n v.y += v.x * 1664525u;\n v = v ^ (v >> 16u);\n v.x += v.y * 1664525u;\n v.y += v.x * 1664525u;\n v = v ^ (v >> 16u);\n return v;\n}\nfloat u24(uint h) { return float(h >> 8u) * (1.0 / 16777216.0); }\n\nuniform vec4 uKeep[6]; // the objects the made ground keeps away from: east, north, the distance inside which nothing is made, the distance outside which it all is\nuniform float uKeepCount;\nfloat keepMask(vec2 p) {\n float keep = 1.0;\n for (int i = 0; i < 6; i += 1) {\n if (float(i) >= uKeepCount) break;\n vec4 k = uKeep[i];\n float t = clamp((distance(p, k.xy) - k.z) / (k.w - k.z), 0.0, 1.0);\n keep = min(keep, t * t * (3.0 - 2.0 * t));\n }\n return keep;\n}\n\n// the made ground at a point: x the height in metres, yz the slope east and north, from every crater of every octave whose nominal diameter is over `fromD`\nvec3 madeGround(vec2 p, float fromD) {\n vec3 sum = vec3(0.0);\n for (int octave = 5; octave >= 0; octave -= 1) {\n float nominal = 0.5 * exp2(float(octave));\n float fade = clamp(nominal / fromD - 1.0, 0.0, 1.0);\n if (fade <= 0.0) break;\n float cell = 3.0 * nominal;\n ivec2 base = ivec2(floor(p / cell));\n vec2 fr = p / cell - vec2(base);\n float occ = (octave >= 3 ? 0.5 : 1.0) * 0.36 * exp2(-0.5 * float(octave));\n for (int j = -1; j <= 1; j += 1) {\n for (int i = -1; i <= 1; i += 1) {\n // a crater is kept to the middle of its cell, so a neighbour's reaches this cell only within a fifth of the edge\n if ((i == -1 && fr.x > 0.2) || (i == 1 && fr.x < 0.8) || (j == -1 && fr.y > 0.2) || (j == 1 && fr.y < 0.8)) continue;\n ivec2 c = base + ivec2(i, j);\n uvec2 ab = pcg2d(uvec2(uint(c.x), uint(c.y + octave * 7919)));\n if (u24(ab.x) >= occ) continue;\n uvec2 cd = pcg2d(uvec2(uint(c.x + 104729), uint(c.y + octave * 7919 + 15485863)));\n float diameter = nominal * (1.0 + (octave == 5 ? 0.25 : 1.0) * u24(cd.y));\n float r4 = float(ab.x & 255u) / 255.0;\n float age = 1.0 - r4 * r4 * r4 * r4;\n float radius = 0.5 * diameter;\n float vary = 0.6 + 0.4 * (float(cd.x & 255u) / 255.0);\n float depth = diameter * (0.2 - 0.17 * age) * vary;\n float rim = 0.045 * diameter * pow(1.0 - age, 1.5);\n float rimWidth = 0.22 + 0.5 * age;\n vec2 centre = vec2(float(c.x) + 0.25 + 0.5 * u24(ab.y), float(c.y) + 0.25 + 0.5 * u24(cd.x)) * cell;\n vec2 d = p - centre;\n float r = length(d);\n float x = r / radius;\n float h = 0.0;\n float dh = 0.0;\n if (x < 1.0) { float bowl = 1.0 - x * x; float pw = 1.0 + age; h = -depth * pow(bowl, pw); dh = 2.0 * depth * pw * x * pow(bowl, age); }\n float e = (x - 1.0) / rimWidth;\n float ex = exp(-e * e);\n h += rim * ex;\n dh += -2.0 * rim * e * ex / rimWidth;\n if (x > 1.0) { float t = 1.0 / x; h += 0.25 * rim * t * t * t; dh += -0.75 * rim * t * t * t * t; }\n float k = r > 1e-6 ? dh / (radius * r) : 0.0;\n sum += fade * vec3(h, k * d.x, k * d.y);\n }\n }\n }\n return sum * keepMask(p);\n}\n\nfloat vnoise(vec2 p) {\n vec2 i = floor(p);\n vec2 f = p - i;\n vec2 w = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);\n uvec2 c = uvec2(ivec2(i));\n float a = u24(pcg2d(c).x);\n float b = u24(pcg2d(c + uvec2(1u, 0u)).x);\n float cc = u24(pcg2d(c + uvec2(0u, 1u)).x);\n float d = u24(pcg2d(c + uvec2(1u, 1u)).x);\n return mix(mix(a, b, w.x), mix(cc, d, w.x), w.y);\n}\n\n// a fine roughness of the dust: two scales, as a slope (east, north), faded out where a pixel covers more than a few of its grains\nvec2 roughness(vec2 p, float footprint) {\n vec2 g = vec2(0.0);\n for (int k = 0; k < 2; k += 1) {\n float s = k == 0 ? 0.07 : 0.3;\n float amp = k == 0 ? 0.3 : 0.28;\n float fade = smoothstep(footprint * 2.0, footprint * 7.0, s);\n if (fade <= 0.0) continue;\n float d = s * 0.25;\n vec2 q = (k == 0 ? vec2(p.x * 0.629 + p.y * 0.777, p.y * 0.629 - p.x * 0.777) : vec2(p.x * 0.857 - p.y * 0.515, p.x * 0.515 + p.y * 0.857)) / s;\n float dx = vnoise(q + vec2(0.25, 0.0)) - vnoise(q - vec2(0.25, 0.0));\n float dy = vnoise(q + vec2(0.0, 0.25)) - vnoise(q - vec2(0.0, 0.25));\n g += fade * amp * vec2(dx, dy) / (0.5 * s) * 0.012;\n }\n return g;\n}\n\n\n// the ground's height at a point: the measured heights and, near the eyes, the made craters (kept to the ones a pixel here can show)\nfloat groundY(vec2 p, float dist, bool fine, float fromD) {\n float y = terrainY(p, dist, fine);\n if (uDetail > 0.5 && fromD < 24.0) y += madeGround(p, fromD).x;\n return y;\n}\n\n// 1 where the Sun reaches a point, 0 where the ground is in its way. The measured ground's shadow is read from the baked horizon; the march toward the Sun over the heights (and the made craters) is the near\n// field's only, a few tens of metres with a fixed number of steps, as sharp as the Sun's edge. Where there is no baked horizon the march goes all the way, as it did before the maps.\nfloat lit(vec3 P, float dist0) {\n vec2 dir = normalize(uSun.xz);\n float slope = uSun.y / max(length(uSun.xz), 1e-4);\n if (uHzOn > 0.5 && horizonAt(P.xz) - 0.3 > uSunDegrees) return 0.0;\n // the ground at the point from the heights themselves, not the mesh's slope between its corners, which can be a long way off on a far mountain\n P.y = groundY(P.xz, dist0, true, 2.5 * dist0 * uPixel);\n float t = 0.5 * spacing(P.xz, dist0) + 0.25;\n if (uDetail > 0.5) t = min(t, 0.2 + 0.02 * dist0);\n // a pixel's own start along the ray: the edge of a rim's shadow is a line of steps, and a line of steps is jagged; with a start of its own each pixel it becomes a fine grain instead\n float jitter = fract(sin(dot(P.xz, vec2(12.9898, 78.233))) * 43758.5453);\n float range = uHzOn > 0.5 ? uNear.y : 80000.0;\n for (int i = 0; i < 260; i += 1) {\n if (float(i) >= uNear.x) break;\n vec2 q = P.xz + dir * t;\n float y = P.y + slope * t;\n float dist = max(t, distance(q, uEyeEN));\n float res = spacing(q, dist);\n float h = groundY(q, dist, t < 600.0, t < uNear.z ? max(0.2 * t, 2.5 * dist * uPixel) : 99.0);\n float bias = (t < 40.0 ? 0.01 : 0.3 * res) + 0.002 * t;\n if (h > y + bias) return 0.0;\n if (y > uMaxY || t > range) break;\n float step = t < 30.0 ? t * 0.045 + 0.04 : t * 0.06 + 0.5;\n t += step * (0.65 + 0.7 * jitter);\n }\n return 1.0;\n}\n";
|
|
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\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\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;\n}\n\nfloat vnoise(vec2 p) {\n vec2 i = floor(p);\n vec2 f = p - i;\n vec2 w = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);\n uvec2 c = uvec2(ivec2(i));\n float a = u24(pcg2d(c).x);\n float b = u24(pcg2d(c + uvec2(1u, 0u)).x);\n float cc = u24(pcg2d(c + uvec2(0u, 1u)).x);\n float d = u24(pcg2d(c + uvec2(1u, 1u)).x);\n return mix(mix(a, b, w.x), mix(cc, d, w.x), w.y);\n}\n\n// a fine roughness of the dust: two scales, as a slope (east, north), faded out where a pixel covers more than a few of its grains\nvec2 roughness(vec2 p, float footprint) {\n vec2 g = vec2(0.0);\n for (int k = 0; k < 2; k += 1) {\n float s = k == 0 ? 0.07 : 0.3;\n float amp = k == 0 ? 0.3 : 0.28;\n float fade = smoothstep(footprint * 2.0, footprint * 7.0, s);\n if (fade <= 0.0) continue;\n float d = s * 0.25;\n vec2 q = (k == 0 ? vec2(p.x * 0.629 + p.y * 0.777, p.y * 0.629 - p.x * 0.777) : vec2(p.x * 0.857 - p.y * 0.515, p.x * 0.515 + p.y * 0.857)) / s;\n float dx = vnoise(q + vec2(0.25, 0.0)) - vnoise(q - vec2(0.25, 0.0));\n float dy = vnoise(q + vec2(0.0, 0.25)) - vnoise(q - vec2(0.0, 0.25));\n g += fade * amp * vec2(dx, dy) / (0.5 * s) * 0.012;\n }\n return g;\n}\n\n\n// the ground's height at a point: the measured heights and, near the eyes, the made craters (kept to the ones a pixel here can show)\nfloat groundY(vec2 p, float dist, bool fine, float fromD) {\n float y = terrainY(p, dist, fine);\n if (uDetail > 0.5 && fromD < 24.0) y += madeGround(p, fromD).x;\n return y;\n}\n\n// 1 where the Sun reaches a point, 0 where the ground is in its way. The measured ground's shadow is read from the baked horizon; the march toward the Sun over the heights (and the made craters) is the near\n// field's only, a few tens of metres with a fixed number of steps, as sharp as the Sun's edge. Where there is no baked horizon the march goes all the way, as it did before the maps.\nfloat lit(vec3 P, float dist0) {\n vec2 dir = normalize(uSun.xz);\n float slope = uSun.y / max(length(uSun.xz), 1e-4);\n if (uHzOn > 0.5 && horizonAt(P.xz) - 0.3 > uSunDegrees) return 0.0;\n // the ground at the point from the heights themselves, not the mesh's slope between its corners, which can be a long way off on a far mountain\n P.y = groundY(P.xz, dist0, true, 2.5 * dist0 * uPixel);\n float t = 0.5 * spacing(P.xz, dist0) + 0.25;\n if (uDetail > 0.5) t = min(t, 0.2 + 0.02 * dist0);\n // a pixel's own start along the ray: the edge of a rim's shadow is a line of steps, and a line of steps is jagged; with a start of its own each pixel it becomes a fine grain instead\n float jitter = fract(sin(dot(P.xz, vec2(12.9898, 78.233))) * 43758.5453);\n float range = uHzOn > 0.5 ? uNear.y : 80000.0;\n for (int i = 0; i < 260; i += 1) {\n if (float(i) >= uNear.x) break;\n vec2 q = P.xz + dir * t;\n float y = P.y + slope * t;\n float dist = max(t, distance(q, uEyeEN));\n float res = spacing(q, dist);\n float h = groundY(q, dist, t < 600.0, t < uNear.z ? max(0.2 * t, 2.5 * dist * uPixel) : 99.0);\n float bias = (t < 40.0 ? 0.01 : 0.3 * res) + 0.002 * t;\n if (h > y + bias) return 0.0;\n if (y > uMaxY || t > range) break;\n float step = t < 30.0 ? t * 0.045 + 0.04 : t * 0.06 + 0.5;\n t += step * (0.65 + 0.7 * jitter);\n }\n return 1.0;\n}\n\nvarying vec3 vP;\n\nvoid main() {\n float dist = distance(vP.xz, uEyeEN);\n float fromD = 2.5 * dist * uPixel;\n float e = max(spacing(vP.xz, dist), dist * 0.001);\n float hE = terrainY(vP.xz + vec2(e, 0.0), dist, true);\n float hW = terrainY(vP.xz - vec2(e, 0.0), dist, true);\n float hN = terrainY(vP.xz + vec2(0.0, e), dist, true);\n float hS = terrainY(vP.xz - vec2(0.0, e), dist, true);\n vec2 slope = vec2((hE - hW) / (2.0 * e), (hN - hS) / (2.0 * e));\n if (uDetail > 0.5) {\n if (fromD < 24.0) slope += madeGround(vP.xz, fromD).yz;\n slope += roughness(vP.xz, dist * uPixel);\n }\n vec3 n = normalize(vec3(-slope.x, 1.0, -slope.y));\n float mu0 = dot(n, uSun);\n float mu = max(dot(n, normalize(uEye - vP)), 0.03);\n float shine = 0.0;\n if (mu0 > 0.0 && uSun.y > -0.01) shine = (uShadows > 0.5 ? lit(vP, dist) : 1.0) * 2.0 * mu0 / (mu0 + mu);\n float light = uAlbedo * albedoAt(vP.xz, dist) * (shine + uEarthshine * max(n.y, 0.0)) * uExposure;\n gl_FragColor = vec4(vec3(pow(clamp(light, 0.0, 1.0), 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\nuniform float uShadows; // 1 for the ground to shadow itself (the default), 0 for none (a try-out)\nuniform float uSunDegrees; // the Sun's elevation in degrees\nuniform vec3 uNear; // the near march: steps, the distance it reaches in metres, the distance out to which the made craters are in it (the quality of the draw)\n\nuniform sampler2D uH0;\nuniform sampler2D uH1;\nuniform sampler2D uH2;\nuniform sampler2D uH3;\nuniform sampler2D uA0; // the ground picture on the first three levels, 0 to 1 with the middle at 0.5\nuniform sampler2D uA1;\nuniform sampler2D uA2;\nuniform float uPicture; // 1 where the picture is there\nuniform vec4 uL0; // half width, metres a sample, samples across, the distance out to which this level is used\nuniform vec4 uL1;\nuniform vec4 uL2;\nuniform vec4 uL3;\nuniform float uHmin;\nuniform float uHrange;\nuniform float uGround;\nuniform float uRadius;\n\nuniform vec2 uFarHeight; // the range the coarse level is encoded over: its minimum and its span\nfloat dec(vec4 t, vec2 hr) { return hr.x + (t.r * 255.0 * 256.0 + t.g * 255.0) / 65535.0 * hr.y; }\n\nfloat lin(sampler2D s, vec2 p, vec4 l, vec2 hr) {\n vec2 f = vec2((p.x + l.x) / l.y - 0.5, (l.x - p.y) / l.y - 0.5);\n vec2 i = floor(f);\n vec2 t = f - i;\n float st = 1.0 / l.z;\n vec2 uv = (i + 0.5) * st;\n float a = dec(texture2D(s, uv), hr);\n float b = dec(texture2D(s, uv + vec2(st, 0.0)), hr);\n float c = dec(texture2D(s, uv + vec2(0.0, st)), hr);\n float d = dec(texture2D(s, uv + vec2(st, st)), hr);\n return mix(mix(a, b, t.x), mix(c, d, t.x), t.y);\n}\n\nfloat nearest(sampler2D s, vec2 p, vec4 l, vec2 hr) {\n vec2 uv = vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z));\n return dec(texture2D(s, uv), hr);\n}\n\nbool holds(vec2 p, vec4 l, float dist) { return dist < l.w && abs(p.x) < l.x - 2.0 * l.y && abs(p.y) < l.x - 2.0 * l.y; }\n\n// the ground's height over the site's, the sphere's fall taken off; `fine` reads four samples, otherwise one\nfloat terrainY(vec2 p, float dist, bool fine) {\n float h;\n if (holds(p, uL0, dist)) h = fine ? lin(uH0, p, uL0, vec2(uHmin, uHrange)) : nearest(uH0, p, uL0, vec2(uHmin, uHrange));\n else if (holds(p, uL1, dist)) h = fine ? lin(uH1, p, uL1, vec2(uHmin, uHrange)) : nearest(uH1, p, uL1, vec2(uHmin, uHrange));\n else if (holds(p, uL2, dist)) h = fine ? lin(uH2, p, uL2, vec2(uHmin, uHrange)) : nearest(uH2, p, uL2, vec2(uHmin, uHrange));\n else h = fine ? lin(uH3, p, uL3, uFarHeight) : nearest(uH3, p, uL3, uFarHeight);\n return h - uGround - dot(p, p) / (2.0 * uRadius);\n}\n\n// the ground's own brightness at a point, from the picture of the level that serves it, 1 where it is the middle\nfloat albedoAt(vec2 p, float dist) {\n if (uPicture < 0.5) return 1.0;\n vec4 l;\n if (holds(p, uL0, dist)) { l = uL0; return 2.0 * texture2D(uA0, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n if (holds(p, uL1, dist)) { l = uL1; return 2.0 * texture2D(uA1, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n if (holds(p, uL2, dist)) { l = uL2; return 2.0 * texture2D(uA2, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n return 1.0;\n}\n\n// the measured ground's shadows, baked (scripts/make-moon-terrain.py): for a point, the elevation angle in degrees of the horizon toward the Sun, read from the finest of the three horizon maps that holds the point\nuniform sampler2D uZ0;\nuniform sampler2D uZ1;\nuniform sampler2D uZ2;\nuniform float uHzOn; // 1 where the maps are there\nuniform vec3 uHzSun; // the two directions (of 18) the Sun's azimuth lies between, and the share of the second\nuniform vec2 uHzRange; // the degrees the codes 0 and 255 stand for\n\nfloat hzSector(sampler2D s, vec2 cell, float k) {\n float slab = floor(k / 3.0);\n float ch = k - slab * 3.0;\n vec3 v = texture2D(s, vec2((cell.x + slab) / 6.0, cell.y)).rgb;\n return ch < 0.5 ? v.r : (ch < 1.5 ? v.g : v.b);\n}\n\nfloat hzFrom(sampler2D s, vec2 p, float reach) {\n vec2 cell = clamp(vec2((p.x + reach) / (2.0 * reach), (reach - p.y) / (2.0 * reach)), vec2(0.5 / 512.0), vec2(1.0 - 0.5 / 512.0));\n float code = mix(hzSector(s, cell, uHzSun.x), hzSector(s, cell, uHzSun.y), uHzSun.z);\n return uHzRange.x + code * (uHzRange.y - uHzRange.x);\n}\n\nfloat horizonAt(vec2 p) {\n if (abs(p.x) < uL0.x && abs(p.y) < uL0.x) return hzFrom(uZ0, p, uL0.x);\n if (abs(p.x) < uL1.x && abs(p.y) < uL1.x) return hzFrom(uZ1, p, uL1.x);\n if (abs(p.x) < uL2.x && abs(p.y) < uL2.x) return hzFrom(uZ2, p, uL2.x);\n return -90.0;\n}\n\n// the spacing of the level that serves a point, for the step of a slope\nfloat spacing(vec2 p, float dist) {\n if (holds(p, uL0, dist)) return uL0.y;\n if (holds(p, uL1, dist)) return uL1.y;\n if (holds(p, uL2, dist)) return uL2.y;\n return uL3.y;\n}\n\n\nuniform float uPixel; // the angle one pixel takes, radians\nuniform float uDetail; // 1 for the made detail, 0 for none\n\nuvec2 pcg2d(uvec2 v) {\n v = v * 1664525u + 1013904223u;\n v.x += v.y * 1664525u;\n v.y += v.x * 1664525u;\n v = v ^ (v >> 16u);\n v.x += v.y * 1664525u;\n v.y += v.x * 1664525u;\n v = v ^ (v >> 16u);\n return v;\n}\nfloat u24(uint h) { return float(h >> 8u) * (1.0 / 16777216.0); }\n\nuniform vec4 uKeep[6]; // the objects the made ground keeps away from: east, north, the distance inside which nothing is made, the distance outside which it all is\nuniform float uKeepCount;\nfloat keepMask(vec2 p) {\n float keep = 1.0;\n for (int i = 0; i < 6; i += 1) {\n if (float(i) >= uKeepCount) break;\n vec4 k = uKeep[i];\n float t = clamp((distance(p, k.xy) - k.z) / (k.w - k.z), 0.0, 1.0);\n keep = min(keep, t * t * (3.0 - 2.0 * t));\n }\n return keep;\n}\n\n// the made ground at a point: x the height in metres, yz the slope east and north, from every crater of every octave whose nominal diameter is over `fromD`\nvec3 madeGround(vec2 p, float fromD) {\n vec3 sum = vec3(0.0);\n for (int octave = 5; octave >= 0; octave -= 1) {\n float nominal = 0.5 * exp2(float(octave));\n float fade = clamp(nominal / fromD - 1.0, 0.0, 1.0);\n if (fade <= 0.0) break;\n float cell = 3.0 * nominal;\n ivec2 base = ivec2(floor(p / cell));\n vec2 fr = p / cell - vec2(base);\n float occ = (octave >= 3 ? 0.5 : 1.0) * 0.36 * exp2(-0.5 * float(octave));\n for (int j = -1; j <= 1; j += 1) {\n for (int i = -1; i <= 1; i += 1) {\n // a crater is kept to the middle of its cell, so a neighbour's reaches this cell only within a fifth of the edge\n if ((i == -1 && fr.x > 0.2) || (i == 1 && fr.x < 0.8) || (j == -1 && fr.y > 0.2) || (j == 1 && fr.y < 0.8)) continue;\n ivec2 c = base + ivec2(i, j);\n uvec2 ab = pcg2d(uvec2(uint(c.x), uint(c.y + octave * 7919)));\n if (u24(ab.x) >= occ) continue;\n uvec2 cd = pcg2d(uvec2(uint(c.x + 104729), uint(c.y + octave * 7919 + 15485863)));\n float diameter = nominal * (1.0 + (octave == 5 ? 0.25 : 1.0) * u24(cd.y));\n float r4 = float(ab.x & 255u) / 255.0;\n float age = 1.0 - r4 * r4 * r4 * r4;\n float radius = 0.5 * diameter;\n float vary = 0.6 + 0.4 * (float(cd.x & 255u) / 255.0);\n float depth = diameter * (0.2 - 0.17 * age) * vary;\n float rim = 0.045 * diameter * pow(1.0 - age, 1.5);\n float rimWidth = 0.22 + 0.5 * age;\n vec2 centre = vec2(float(c.x) + 0.25 + 0.5 * u24(ab.y), float(c.y) + 0.25 + 0.5 * u24(cd.x)) * cell;\n vec2 d = p - centre;\n float r = length(d);\n float x = r / radius;\n float h = 0.0;\n float dh = 0.0;\n if (x < 1.0) { float bowl = 1.0 - x * x; float pw = 1.0 + age; h = -depth * pow(bowl, pw); dh = 2.0 * depth * pw * x * pow(bowl, age); }\n float e = (x - 1.0) / rimWidth;\n float ex = exp(-e * e);\n h += rim * ex;\n dh += -2.0 * rim * e * ex / rimWidth;\n if (x > 1.0) { float t = 1.0 / x; h += 0.25 * rim * t * t * t; dh += -0.75 * rim * t * t * t * t; }\n float k = r > 1e-6 ? dh / (radius * r) : 0.0;\n sum += fade * vec3(h, k * d.x, k * d.y);\n }\n }\n }\n return sum * keepMask(p);\n}\n\nfloat vnoise(vec2 p) {\n vec2 i = floor(p);\n vec2 f = p - i;\n vec2 w = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);\n uvec2 c = uvec2(ivec2(i));\n float a = u24(pcg2d(c).x);\n float b = u24(pcg2d(c + uvec2(1u, 0u)).x);\n float cc = u24(pcg2d(c + uvec2(0u, 1u)).x);\n float d = u24(pcg2d(c + uvec2(1u, 1u)).x);\n return mix(mix(a, b, w.x), mix(cc, d, w.x), w.y);\n}\n\n// a fine roughness of the dust: two scales, as a slope (east, north), faded out where a pixel covers more than a few of its grains\nvec2 roughness(vec2 p, float footprint) {\n vec2 g = vec2(0.0);\n for (int k = 0; k < 2; k += 1) {\n float s = k == 0 ? 0.07 : 0.3;\n float amp = k == 0 ? 0.3 : 0.28;\n float fade = smoothstep(footprint * 2.0, footprint * 7.0, s);\n if (fade <= 0.0) continue;\n float d = s * 0.25;\n vec2 q = (k == 0 ? vec2(p.x * 0.629 + p.y * 0.777, p.y * 0.629 - p.x * 0.777) : vec2(p.x * 0.857 - p.y * 0.515, p.x * 0.515 + p.y * 0.857)) / s;\n float dx = vnoise(q + vec2(0.25, 0.0)) - vnoise(q - vec2(0.25, 0.0));\n float dy = vnoise(q + vec2(0.0, 0.25)) - vnoise(q - vec2(0.0, 0.25));\n g += fade * amp * vec2(dx, dy) / (0.5 * s) * 0.012;\n }\n return g;\n}\n\n\n// the ground's height at a point: the measured heights and, near the eyes, the made craters (kept to the ones a pixel here can show)\nfloat groundY(vec2 p, float dist, bool fine, float fromD) {\n float y = terrainY(p, dist, fine);\n if (uDetail > 0.5 && fromD < 24.0) y += madeGround(p, fromD).x;\n return y;\n}\n\n// 1 where the Sun reaches a point, 0 where the ground is in its way. The measured ground's shadow is read from the baked horizon; the march toward the Sun over the heights (and the made craters) is the near\n// field's only, a few tens of metres with a fixed number of steps, as sharp as the Sun's edge. Where there is no baked horizon the march goes all the way, as it did before the maps.\nfloat lit(vec3 P, float dist0) {\n vec2 dir = normalize(uSun.xz);\n float slope = uSun.y / max(length(uSun.xz), 1e-4);\n if (uHzOn > 0.5 && horizonAt(P.xz) - 0.3 > uSunDegrees) return 0.0;\n // the ground at the point from the heights themselves, not the mesh's slope between its corners, which can be a long way off on a far mountain\n P.y = groundY(P.xz, dist0, true, 2.5 * dist0 * uPixel);\n float t = 0.5 * spacing(P.xz, dist0) + 0.25;\n if (uDetail > 0.5) t = min(t, 0.2 + 0.02 * dist0);\n // a pixel's own start along the ray: the edge of a rim's shadow is a line of steps, and a line of steps is jagged; with a start of its own each pixel it becomes a fine grain instead\n float jitter = fract(sin(dot(P.xz, vec2(12.9898, 78.233))) * 43758.5453);\n float range = uHzOn > 0.5 ? uNear.y : 80000.0;\n for (int i = 0; i < 260; i += 1) {\n if (float(i) >= uNear.x) break;\n vec2 q = P.xz + dir * t;\n float y = P.y + slope * t;\n float dist = max(t, distance(q, uEyeEN));\n float res = spacing(q, dist);\n float h = groundY(q, dist, t < 600.0, t < uNear.z ? max(0.2 * t, 2.5 * dist * uPixel) : 99.0);\n float bias = (t < 40.0 ? 0.01 : 0.3 * res) + 0.002 * t;\n if (h > y + bias) return 0.0;\n if (y > uMaxY || t > range) break;\n float step = t < 30.0 ? t * 0.045 + 0.04 : t * 0.06 + 0.5;\n t += step * (0.65 + 0.7 * jitter);\n }\n return 1.0;\n}\n\nvarying vec3 vP;\n\nvoid main() {\n float dist = distance(vP.xz, uEyeEN);\n float fromD = 2.5 * dist * uPixel;\n float e = max(spacing(vP.xz, dist), dist * 0.001);\n float hE = terrainY(vP.xz + vec2(e, 0.0), dist, true);\n float hW = terrainY(vP.xz - vec2(e, 0.0), dist, true);\n float hN = terrainY(vP.xz + vec2(0.0, e), dist, true);\n float hS = terrainY(vP.xz - vec2(0.0, e), dist, true);\n vec2 slope = vec2((hE - hW) / (2.0 * e), (hN - hS) / (2.0 * e));\n if (uDetail > 0.5) {\n if (fromD < 24.0) slope += madeGround(vP.xz, fromD).yz;\n slope += roughness(vP.xz, dist * uPixel);\n }\n vec3 n = normalize(vec3(-slope.x, 1.0, -slope.y));\n float mu0 = dot(n, uSun);\n float mu = max(dot(n, normalize(uEye - vP)), 0.03);\n float shine = 0.0;\n if (mu0 > 0.0 && uSun.y > -0.01) shine = (uShadows > 0.5 ? lit(vP, dist) : 1.0) * 2.0 * mu0 / (mu0 + mu);\n float light = uAlbedo * albedoAt(vP.xz, dist) * (shine + uEarthshine * max(n.y, 0.0)) * uExposure;\n gl_FragColor = vec4(vec3(pow(clamp(light, 0.0, 1.0), 1.0 / 2.2)), 1.0);\n}\n";
|
|
11
11
|
/** The rocks: pieces of ground standing on it. Their corners come from the page already in the site's plane (east, up, north). */
|
|
12
12
|
export declare const ROCK_VERTEX = "\nprecision highp float;\n// position, normal and uv are declared by three.js\nattribute float tone;\nuniform mat4 uVP;\nvarying vec3 vP;\nvarying vec3 vN;\nvarying float vTone;\nvoid main() {\n vP = position;\n vN = normal;\n vTone = tone;\n gl_Position = uVP * vec4(position.x, position.y, -position.z, 1.0);\n}\n";
|
|
13
|
-
export declare const ROCK_FRAGMENT = "\nprecision highp float;\nprecision highp sampler2D;\n\nuniform vec3 uSun;\nuniform vec3 uEye;\nuniform vec2 uEyeEN;\nuniform float uExposure;\nuniform float uAlbedo;\nuniform float uMaxY; // the highest ground over the site's, for the end of a shadow's march\nuniform float uEarthshine; // the light of the sunlit ground round the shade, a small share of a lit slope's\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\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;\n}\n\nfloat vnoise(vec2 p) {\n vec2 i = floor(p);\n vec2 f = p - i;\n vec2 w = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);\n uvec2 c = uvec2(ivec2(i));\n float a = u24(pcg2d(c).x);\n float b = u24(pcg2d(c + uvec2(1u, 0u)).x);\n float cc = u24(pcg2d(c + uvec2(0u, 1u)).x);\n float d = u24(pcg2d(c + uvec2(1u, 1u)).x);\n return mix(mix(a, b, w.x), mix(cc, d, w.x), w.y);\n}\n\n// a fine roughness of the dust: two scales, as a slope (east, north), faded out where a pixel covers more than a few of its grains\nvec2 roughness(vec2 p, float footprint) {\n vec2 g = vec2(0.0);\n for (int k = 0; k < 2; k += 1) {\n float s = k == 0 ? 0.07 : 0.3;\n float amp = k == 0 ? 0.3 : 0.28;\n float fade = smoothstep(footprint * 2.0, footprint * 7.0, s);\n if (fade <= 0.0) continue;\n float d = s * 0.25;\n vec2 q = (k == 0 ? vec2(p.x * 0.629 + p.y * 0.777, p.y * 0.629 - p.x * 0.777) : vec2(p.x * 0.857 - p.y * 0.515, p.x * 0.515 + p.y * 0.857)) / s;\n float dx = vnoise(q + vec2(0.25, 0.0)) - vnoise(q - vec2(0.25, 0.0));\n float dy = vnoise(q + vec2(0.0, 0.25)) - vnoise(q - vec2(0.0, 0.25));\n g += fade * amp * vec2(dx, dy) / (0.5 * s) * 0.012;\n }\n return g;\n}\n\n\n// the ground's height at a point: the measured heights and, near the eyes, the made craters (kept to the ones a pixel here can show)\nfloat groundY(vec2 p, float dist, bool fine, float fromD) {\n float y = terrainY(p, dist, fine);\n if (uDetail > 0.5 && fromD < 24.0) y += madeGround(p, fromD).x;\n return y;\n}\n\n// 1 where the Sun reaches a point, 0 where the ground is in its way. The measured ground's shadow is read from the baked horizon; the march toward the Sun over the heights (and the made craters) is the near\n// field's only, a few tens of metres with a fixed number of steps, as sharp as the Sun's edge. Where there is no baked horizon the march goes all the way, as it did before the maps.\nfloat lit(vec3 P, float dist0) {\n vec2 dir = normalize(uSun.xz);\n float slope = uSun.y / max(length(uSun.xz), 1e-4);\n if (uHzOn > 0.5 && horizonAt(P.xz) - 0.3 > uSunDegrees) return 0.0;\n // the ground at the point from the heights themselves, not the mesh's slope between its corners, which can be a long way off on a far mountain\n P.y = groundY(P.xz, dist0, true, 2.5 * dist0 * uPixel);\n float t = 0.5 * spacing(P.xz, dist0) + 0.25;\n if (uDetail > 0.5) t = min(t, 0.2 + 0.02 * dist0);\n // a pixel's own start along the ray: the edge of a rim's shadow is a line of steps, and a line of steps is jagged; with a start of its own each pixel it becomes a fine grain instead\n float jitter = fract(sin(dot(P.xz, vec2(12.9898, 78.233))) * 43758.5453);\n float range = uHzOn > 0.5 ? uNear.y : 80000.0;\n for (int i = 0; i < 260; i += 1) {\n if (float(i) >= uNear.x) break;\n vec2 q = P.xz + dir * t;\n float y = P.y + slope * t;\n float dist = max(t, distance(q, uEyeEN));\n float res = spacing(q, dist);\n float h = groundY(q, dist, t < 600.0, t < uNear.z ? max(0.2 * t, 2.5 * dist * uPixel) : 99.0);\n float bias = (t < 40.0 ? 0.01 : 0.3 * res) + 0.002 * t;\n if (h > y + bias) return 0.0;\n if (y > uMaxY || t > range) break;\n float step = t < 30.0 ? t * 0.045 + 0.04 : t * 0.06 + 0.5;\n t += step * (0.65 + 0.7 * jitter);\n }\n return 1.0;\n}\n\nvarying vec3 vP;\nvarying vec3 vN;\nvarying float vTone;\nvoid main() {\n vec3 n = normalize(vN);\n float mu0 = dot(n, uSun);\n float mu = max(dot(n, normalize(uEye - vP)), 0.03);\n float dist = distance(vP.xz, uEyeEN);\n float shine = 0.0;\n if (mu0 > 0.0 && uSun.y > -0.01) shine = (uShadows > 0.5 ? lit(vP + n * 0.02, dist) : 1.0) * 2.0 * mu0 / (mu0 + mu);\n float light = uAlbedo * 1.1 * vTone * (shine + 0.12 * (n.y * 0.5 + 0.5)) * uExposure; // the shade of a stone is lit by the ground round it\n gl_FragColor = vec4(vec3(pow(clamp(light, 0.0, 1.0), 1.0 / 2.2)), 1.0);\n}\n";
|
|
13
|
+
export declare const ROCK_FRAGMENT = "\nprecision highp float;\nprecision highp sampler2D;\n\nuniform vec3 uSun;\nuniform vec3 uEye;\nuniform vec2 uEyeEN;\nuniform float uExposure;\nuniform float uAlbedo;\nuniform float uMaxY; // the highest ground over the site's, for the end of a shadow's march\nuniform float uEarthshine; // the light of the sunlit ground round the shade, a small share of a lit slope's\nuniform float uShadows; // 1 for the ground to shadow itself (the default), 0 for none (a try-out)\nuniform float uSunDegrees; // the Sun's elevation in degrees\nuniform vec3 uNear; // the near march: steps, the distance it reaches in metres, the distance out to which the made craters are in it (the quality of the draw)\n\nuniform sampler2D uH0;\nuniform sampler2D uH1;\nuniform sampler2D uH2;\nuniform sampler2D uH3;\nuniform sampler2D uA0; // the ground picture on the first three levels, 0 to 1 with the middle at 0.5\nuniform sampler2D uA1;\nuniform sampler2D uA2;\nuniform float uPicture; // 1 where the picture is there\nuniform vec4 uL0; // half width, metres a sample, samples across, the distance out to which this level is used\nuniform vec4 uL1;\nuniform vec4 uL2;\nuniform vec4 uL3;\nuniform float uHmin;\nuniform float uHrange;\nuniform float uGround;\nuniform float uRadius;\n\nuniform vec2 uFarHeight; // the range the coarse level is encoded over: its minimum and its span\nfloat dec(vec4 t, vec2 hr) { return hr.x + (t.r * 255.0 * 256.0 + t.g * 255.0) / 65535.0 * hr.y; }\n\nfloat lin(sampler2D s, vec2 p, vec4 l, vec2 hr) {\n vec2 f = vec2((p.x + l.x) / l.y - 0.5, (l.x - p.y) / l.y - 0.5);\n vec2 i = floor(f);\n vec2 t = f - i;\n float st = 1.0 / l.z;\n vec2 uv = (i + 0.5) * st;\n float a = dec(texture2D(s, uv), hr);\n float b = dec(texture2D(s, uv + vec2(st, 0.0)), hr);\n float c = dec(texture2D(s, uv + vec2(0.0, st)), hr);\n float d = dec(texture2D(s, uv + vec2(st, st)), hr);\n return mix(mix(a, b, t.x), mix(c, d, t.x), t.y);\n}\n\nfloat nearest(sampler2D s, vec2 p, vec4 l, vec2 hr) {\n vec2 uv = vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z));\n return dec(texture2D(s, uv), hr);\n}\n\nbool holds(vec2 p, vec4 l, float dist) { return dist < l.w && abs(p.x) < l.x - 2.0 * l.y && abs(p.y) < l.x - 2.0 * l.y; }\n\n// the ground's height over the site's, the sphere's fall taken off; `fine` reads four samples, otherwise one\nfloat terrainY(vec2 p, float dist, bool fine) {\n float h;\n if (holds(p, uL0, dist)) h = fine ? lin(uH0, p, uL0, vec2(uHmin, uHrange)) : nearest(uH0, p, uL0, vec2(uHmin, uHrange));\n else if (holds(p, uL1, dist)) h = fine ? lin(uH1, p, uL1, vec2(uHmin, uHrange)) : nearest(uH1, p, uL1, vec2(uHmin, uHrange));\n else if (holds(p, uL2, dist)) h = fine ? lin(uH2, p, uL2, vec2(uHmin, uHrange)) : nearest(uH2, p, uL2, vec2(uHmin, uHrange));\n else h = fine ? lin(uH3, p, uL3, uFarHeight) : nearest(uH3, p, uL3, uFarHeight);\n return h - uGround - dot(p, p) / (2.0 * uRadius);\n}\n\n// the ground's own brightness at a point, from the picture of the level that serves it, 1 where it is the middle\nfloat albedoAt(vec2 p, float dist) {\n if (uPicture < 0.5) return 1.0;\n vec4 l;\n if (holds(p, uL0, dist)) { l = uL0; return 2.0 * texture2D(uA0, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n if (holds(p, uL1, dist)) { l = uL1; return 2.0 * texture2D(uA1, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n if (holds(p, uL2, dist)) { l = uL2; return 2.0 * texture2D(uA2, vec2((p.x + l.x) / (l.y * l.z), (l.x - p.y) / (l.y * l.z))).r; }\n return 1.0;\n}\n\n// the measured ground's shadows, baked (scripts/make-moon-terrain.py): for a point, the elevation angle in degrees of the horizon toward the Sun, read from the finest of the three horizon maps that holds the point\nuniform sampler2D uZ0;\nuniform sampler2D uZ1;\nuniform sampler2D uZ2;\nuniform float uHzOn; // 1 where the maps are there\nuniform vec3 uHzSun; // the two directions (of 18) the Sun's azimuth lies between, and the share of the second\nuniform vec2 uHzRange; // the degrees the codes 0 and 255 stand for\n\nfloat hzSector(sampler2D s, vec2 cell, float k) {\n float slab = floor(k / 3.0);\n float ch = k - slab * 3.0;\n vec3 v = texture2D(s, vec2((cell.x + slab) / 6.0, cell.y)).rgb;\n return ch < 0.5 ? v.r : (ch < 1.5 ? v.g : v.b);\n}\n\nfloat hzFrom(sampler2D s, vec2 p, float reach) {\n vec2 cell = clamp(vec2((p.x + reach) / (2.0 * reach), (reach - p.y) / (2.0 * reach)), vec2(0.5 / 512.0), vec2(1.0 - 0.5 / 512.0));\n float code = mix(hzSector(s, cell, uHzSun.x), hzSector(s, cell, uHzSun.y), uHzSun.z);\n return uHzRange.x + code * (uHzRange.y - uHzRange.x);\n}\n\nfloat horizonAt(vec2 p) {\n if (abs(p.x) < uL0.x && abs(p.y) < uL0.x) return hzFrom(uZ0, p, uL0.x);\n if (abs(p.x) < uL1.x && abs(p.y) < uL1.x) return hzFrom(uZ1, p, uL1.x);\n if (abs(p.x) < uL2.x && abs(p.y) < uL2.x) return hzFrom(uZ2, p, uL2.x);\n return -90.0;\n}\n\n// the spacing of the level that serves a point, for the step of a slope\nfloat spacing(vec2 p, float dist) {\n if (holds(p, uL0, dist)) return uL0.y;\n if (holds(p, uL1, dist)) return uL1.y;\n if (holds(p, uL2, dist)) return uL2.y;\n return uL3.y;\n}\n\n\nuniform float uPixel; // the angle one pixel takes, radians\nuniform float uDetail; // 1 for the made detail, 0 for none\n\nuvec2 pcg2d(uvec2 v) {\n v = v * 1664525u + 1013904223u;\n v.x += v.y * 1664525u;\n v.y += v.x * 1664525u;\n v = v ^ (v >> 16u);\n v.x += v.y * 1664525u;\n v.y += v.x * 1664525u;\n v = v ^ (v >> 16u);\n return v;\n}\nfloat u24(uint h) { return float(h >> 8u) * (1.0 / 16777216.0); }\n\nuniform vec4 uKeep[6]; // the objects the made ground keeps away from: east, north, the distance inside which nothing is made, the distance outside which it all is\nuniform float uKeepCount;\nfloat keepMask(vec2 p) {\n float keep = 1.0;\n for (int i = 0; i < 6; i += 1) {\n if (float(i) >= uKeepCount) break;\n vec4 k = uKeep[i];\n float t = clamp((distance(p, k.xy) - k.z) / (k.w - k.z), 0.0, 1.0);\n keep = min(keep, t * t * (3.0 - 2.0 * t));\n }\n return keep;\n}\n\n// the made ground at a point: x the height in metres, yz the slope east and north, from every crater of every octave whose nominal diameter is over `fromD`\nvec3 madeGround(vec2 p, float fromD) {\n vec3 sum = vec3(0.0);\n for (int octave = 5; octave >= 0; octave -= 1) {\n float nominal = 0.5 * exp2(float(octave));\n float fade = clamp(nominal / fromD - 1.0, 0.0, 1.0);\n if (fade <= 0.0) break;\n float cell = 3.0 * nominal;\n ivec2 base = ivec2(floor(p / cell));\n vec2 fr = p / cell - vec2(base);\n float occ = (octave >= 3 ? 0.5 : 1.0) * 0.36 * exp2(-0.5 * float(octave));\n for (int j = -1; j <= 1; j += 1) {\n for (int i = -1; i <= 1; i += 1) {\n // a crater is kept to the middle of its cell, so a neighbour's reaches this cell only within a fifth of the edge\n if ((i == -1 && fr.x > 0.2) || (i == 1 && fr.x < 0.8) || (j == -1 && fr.y > 0.2) || (j == 1 && fr.y < 0.8)) continue;\n ivec2 c = base + ivec2(i, j);\n uvec2 ab = pcg2d(uvec2(uint(c.x), uint(c.y + octave * 7919)));\n if (u24(ab.x) >= occ) continue;\n uvec2 cd = pcg2d(uvec2(uint(c.x + 104729), uint(c.y + octave * 7919 + 15485863)));\n float diameter = nominal * (1.0 + (octave == 5 ? 0.25 : 1.0) * u24(cd.y));\n float r4 = float(ab.x & 255u) / 255.0;\n float age = 1.0 - r4 * r4 * r4 * r4;\n float radius = 0.5 * diameter;\n float vary = 0.6 + 0.4 * (float(cd.x & 255u) / 255.0);\n float depth = diameter * (0.2 - 0.17 * age) * vary;\n float rim = 0.045 * diameter * pow(1.0 - age, 1.5);\n float rimWidth = 0.22 + 0.5 * age;\n vec2 centre = vec2(float(c.x) + 0.25 + 0.5 * u24(ab.y), float(c.y) + 0.25 + 0.5 * u24(cd.x)) * cell;\n vec2 d = p - centre;\n float r = length(d);\n float x = r / radius;\n float h = 0.0;\n float dh = 0.0;\n if (x < 1.0) { float bowl = 1.0 - x * x; float pw = 1.0 + age; h = -depth * pow(bowl, pw); dh = 2.0 * depth * pw * x * pow(bowl, age); }\n float e = (x - 1.0) / rimWidth;\n float ex = exp(-e * e);\n h += rim * ex;\n dh += -2.0 * rim * e * ex / rimWidth;\n if (x > 1.0) { float t = 1.0 / x; h += 0.25 * rim * t * t * t; dh += -0.75 * rim * t * t * t * t; }\n float k = r > 1e-6 ? dh / (radius * r) : 0.0;\n sum += fade * vec3(h, k * d.x, k * d.y);\n }\n }\n }\n return sum * keepMask(p);\n}\n\nfloat vnoise(vec2 p) {\n vec2 i = floor(p);\n vec2 f = p - i;\n vec2 w = f * f * f * (f * (f * 6.0 - 15.0) + 10.0);\n uvec2 c = uvec2(ivec2(i));\n float a = u24(pcg2d(c).x);\n float b = u24(pcg2d(c + uvec2(1u, 0u)).x);\n float cc = u24(pcg2d(c + uvec2(0u, 1u)).x);\n float d = u24(pcg2d(c + uvec2(1u, 1u)).x);\n return mix(mix(a, b, w.x), mix(cc, d, w.x), w.y);\n}\n\n// a fine roughness of the dust: two scales, as a slope (east, north), faded out where a pixel covers more than a few of its grains\nvec2 roughness(vec2 p, float footprint) {\n vec2 g = vec2(0.0);\n for (int k = 0; k < 2; k += 1) {\n float s = k == 0 ? 0.07 : 0.3;\n float amp = k == 0 ? 0.3 : 0.28;\n float fade = smoothstep(footprint * 2.0, footprint * 7.0, s);\n if (fade <= 0.0) continue;\n float d = s * 0.25;\n vec2 q = (k == 0 ? vec2(p.x * 0.629 + p.y * 0.777, p.y * 0.629 - p.x * 0.777) : vec2(p.x * 0.857 - p.y * 0.515, p.x * 0.515 + p.y * 0.857)) / s;\n float dx = vnoise(q + vec2(0.25, 0.0)) - vnoise(q - vec2(0.25, 0.0));\n float dy = vnoise(q + vec2(0.0, 0.25)) - vnoise(q - vec2(0.0, 0.25));\n g += fade * amp * vec2(dx, dy) / (0.5 * s) * 0.012;\n }\n return g;\n}\n\n\n// the ground's height at a point: the measured heights and, near the eyes, the made craters (kept to the ones a pixel here can show)\nfloat groundY(vec2 p, float dist, bool fine, float fromD) {\n float y = terrainY(p, dist, fine);\n if (uDetail > 0.5 && fromD < 24.0) y += madeGround(p, fromD).x;\n return y;\n}\n\n// 1 where the Sun reaches a point, 0 where the ground is in its way. The measured ground's shadow is read from the baked horizon; the march toward the Sun over the heights (and the made craters) is the near\n// field's only, a few tens of metres with a fixed number of steps, as sharp as the Sun's edge. Where there is no baked horizon the march goes all the way, as it did before the maps.\nfloat lit(vec3 P, float dist0) {\n vec2 dir = normalize(uSun.xz);\n float slope = uSun.y / max(length(uSun.xz), 1e-4);\n if (uHzOn > 0.5 && horizonAt(P.xz) - 0.3 > uSunDegrees) return 0.0;\n // the ground at the point from the heights themselves, not the mesh's slope between its corners, which can be a long way off on a far mountain\n P.y = groundY(P.xz, dist0, true, 2.5 * dist0 * uPixel);\n float t = 0.5 * spacing(P.xz, dist0) + 0.25;\n if (uDetail > 0.5) t = min(t, 0.2 + 0.02 * dist0);\n // a pixel's own start along the ray: the edge of a rim's shadow is a line of steps, and a line of steps is jagged; with a start of its own each pixel it becomes a fine grain instead\n float jitter = fract(sin(dot(P.xz, vec2(12.9898, 78.233))) * 43758.5453);\n float range = uHzOn > 0.5 ? uNear.y : 80000.0;\n for (int i = 0; i < 260; i += 1) {\n if (float(i) >= uNear.x) break;\n vec2 q = P.xz + dir * t;\n float y = P.y + slope * t;\n float dist = max(t, distance(q, uEyeEN));\n float res = spacing(q, dist);\n float h = groundY(q, dist, t < 600.0, t < uNear.z ? max(0.2 * t, 2.5 * dist * uPixel) : 99.0);\n float bias = (t < 40.0 ? 0.01 : 0.3 * res) + 0.002 * t;\n if (h > y + bias) return 0.0;\n if (y > uMaxY || t > range) break;\n float step = t < 30.0 ? t * 0.045 + 0.04 : t * 0.06 + 0.5;\n t += step * (0.65 + 0.7 * jitter);\n }\n return 1.0;\n}\n\nvarying vec3 vP;\nvarying vec3 vN;\nvarying float vTone;\nvoid main() {\n vec3 n = normalize(vN);\n float mu0 = dot(n, uSun);\n float mu = max(dot(n, normalize(uEye - vP)), 0.03);\n float dist = distance(vP.xz, uEyeEN);\n float shine = 0.0;\n if (mu0 > 0.0 && uSun.y > -0.01) shine = (uShadows > 0.5 ? lit(vP + n * 0.02, dist) : 1.0) * 2.0 * mu0 / (mu0 + mu);\n float light = uAlbedo * 1.1 * vTone * (shine + 0.12 * (n.y * 0.5 + 0.5)) * uExposure; // the shade of a stone is lit by the ground round it\n gl_FragColor = vec4(vec3(pow(clamp(light, 0.0, 1.0), 1.0 / 2.2)), 1.0);\n}\n";
|
|
14
14
|
/** A rock's shadow on the ground: a quad laid along the way the Sun's light goes, a soft dark shape, drawn over the ground. */
|
|
15
15
|
export declare const SHADOW_VERTEX = "\nprecision highp float;\nuniform mat4 uVP;\nvarying vec2 vUv;\nvoid main() {\n vUv = uv;\n gl_Position = uVP * vec4(position.x, position.y, -position.z, 1.0);\n}\n";
|
|
16
16
|
export declare const SHADOW_FRAGMENT = "\nprecision highp float;\nvarying vec2 vUv;\nvoid main() {\n float u = vUv.x;\n float across = smoothstep(1.0, 0.5, abs(vUv.y));\n float along = smoothstep(0.0, 0.06, u) * (1.0 - smoothstep(0.78, 1.0, u));\n float a = across * along * 0.85;\n if (a < 0.01) discard;\n gl_FragColor = vec4(0.0, 0.0, 0.0, a);\n}\n";
|
|
@@ -18,3 +18,9 @@ export declare const SHADOW_FRAGMENT = "\nprecision highp float;\nvarying vec2 v
|
|
|
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
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 float band = 0.5 + 0.5 * sin(nrm.z * 9.0 + nrm.x * 5.0);\n vec3 c = mix(ocean, cloud, smoothstep(0.55, 0.95, band) * 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
|
+
/** 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
|
+
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
|
+
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";
|
|
24
|
+
/** The things at a site: the rocks' light, with a flat colour for each corner (the gold of the lunar module's foil, the grey of the rover's frame). */
|
|
25
|
+
export declare const OBJECT_VERTEX: string;
|
|
26
|
+
export declare const OBJECT_FRAGMENT: string;
|
package/dist/surface/glsl.js
CHANGED
|
@@ -118,6 +118,19 @@ uvec2 pcg2d(uvec2 v) {
|
|
|
118
118
|
}
|
|
119
119
|
float u24(uint h) { return float(h >> 8u) * (1.0 / 16777216.0); }
|
|
120
120
|
|
|
121
|
+
uniform 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
|
|
122
|
+
uniform float uKeepCount;
|
|
123
|
+
float keepMask(vec2 p) {
|
|
124
|
+
float keep = 1.0;
|
|
125
|
+
for (int i = 0; i < 6; i += 1) {
|
|
126
|
+
if (float(i) >= uKeepCount) break;
|
|
127
|
+
vec4 k = uKeep[i];
|
|
128
|
+
float t = clamp((distance(p, k.xy) - k.z) / (k.w - k.z), 0.0, 1.0);
|
|
129
|
+
keep = min(keep, t * t * (3.0 - 2.0 * t));
|
|
130
|
+
}
|
|
131
|
+
return keep;
|
|
132
|
+
}
|
|
133
|
+
|
|
121
134
|
// 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\`
|
|
122
135
|
vec3 madeGround(vec2 p, float fromD) {
|
|
123
136
|
vec3 sum = vec3(0.0);
|
|
@@ -162,7 +175,7 @@ vec3 madeGround(vec2 p, float fromD) {
|
|
|
162
175
|
}
|
|
163
176
|
}
|
|
164
177
|
}
|
|
165
|
-
return sum;
|
|
178
|
+
return sum * keepMask(p);
|
|
166
179
|
}
|
|
167
180
|
|
|
168
181
|
float vnoise(vec2 p) {
|
|
@@ -401,3 +414,44 @@ void main() {
|
|
|
401
414
|
gl_FragColor = vec4(pow(clamp(colour, 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);
|
|
402
415
|
}
|
|
403
416
|
`;
|
|
417
|
+
/** 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. */
|
|
418
|
+
export const TRACK_VERTEX = /* glsl */ `
|
|
419
|
+
precision highp float;
|
|
420
|
+
precision highp sampler2D;
|
|
421
|
+
uniform mat4 uVP;
|
|
422
|
+
uniform vec2 uEyeEN;
|
|
423
|
+
${HEIGHTS}
|
|
424
|
+
${DETAIL}
|
|
425
|
+
varying vec2 vUv;
|
|
426
|
+
varying float vDist;
|
|
427
|
+
void main() {
|
|
428
|
+
vec2 p = position.xy;
|
|
429
|
+
float dist = distance(p, uEyeEN);
|
|
430
|
+
vUv = uv;
|
|
431
|
+
vDist = dist;
|
|
432
|
+
if (dist > 600.0) {
|
|
433
|
+
gl_Position = vec4(2.0, 2.0, 2.0, 1.0);
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
float y = terrainY(p, dist, true);
|
|
437
|
+
if (uDetail > 0.5) y += madeGround(p, max(2.5 * dist * uPixel, 0.06 * dist)).x;
|
|
438
|
+
y += 0.03 + 0.0007 * dist;
|
|
439
|
+
gl_Position = uVP * vec4(p.x, y, -p.y, 1.0);
|
|
440
|
+
}
|
|
441
|
+
`;
|
|
442
|
+
export const TRACK_FRAGMENT = /* glsl */ `
|
|
443
|
+
precision highp float;
|
|
444
|
+
varying vec2 vUv;
|
|
445
|
+
varying float vDist;
|
|
446
|
+
void main() {
|
|
447
|
+
// two bands, a wheel's width each, a gauge apart, broken a little along the way, fading out with the distance: faint on purpose
|
|
448
|
+
float band = smoothstep(0.11, 0.0, abs(abs(vUv.y) - 0.64));
|
|
449
|
+
float broken = 0.65 + 0.35 * fract(sin(floor(vUv.x * 3.0) * 12.9898) * 43758.5453);
|
|
450
|
+
float a = band * broken * 0.14 * (1.0 - smoothstep(250.0, 600.0, vDist));
|
|
451
|
+
if (a < 0.004) discard;
|
|
452
|
+
gl_FragColor = vec4(0.0, 0.0, 0.0, a);
|
|
453
|
+
}
|
|
454
|
+
`;
|
|
455
|
+
/** The things at a site: the rocks' light, with a flat colour for each corner (the gold of the lunar module's foil, the grey of the rover's frame). */
|
|
456
|
+
export const OBJECT_VERTEX = ROCK_VERTEX.replace("attribute float tone;", "attribute float tone;\nattribute vec3 tint;").replace("varying float vTone;", "varying float vTone;\nvarying vec3 vTint;").replace("vTone = tone;", "vTone = tone;\n vTint = tint;");
|
|
457
|
+
export const OBJECT_FRAGMENT = ROCK_FRAGMENT.replace("varying float vTone;", "varying float vTone;\nvarying vec3 vTint;").replace("gl_FragColor = vec4(vec3(pow(clamp(light, 0.0, 1.0), 1.0 / 2.2)), 1.0);", "gl_FragColor = vec4(pow(clamp(vec3(light) * vTint, 0.0, 1.0), vec3(1.0 / 2.2)), 1.0);");
|
package/dist/surface/index.d.ts
CHANGED
|
@@ -4,5 +4,7 @@ export { EYE_HEIGHT, FOV_LIMITS, WALK_SPEED, clampLook, forward, stepOver, viewP
|
|
|
4
4
|
export { decodeHeight, drop, emptyLevel, fillFromCoarser, groundAt, sampleLevel, tileAddress, type HeightLevel, type HeightLevelInfo, type TerrainManifest } from "./height.ts";
|
|
5
5
|
export { loadPlan, loadTerrain, type LoadJob, type LoadOptions, type Terrain, type TerrainProgress } from "./load.ts";
|
|
6
6
|
export type { SurfaceState } from "./element.ts";
|
|
7
|
-
export {
|
|
7
|
+
export { landerParts, roverParts } from "./shapes.ts";
|
|
8
|
+
export { keepAway, objectParts, objectsOf, partShadows, traverseOf, KEEP_OUT, type Part, type SiteObject } from "./objects.ts";
|
|
9
|
+
export { craterIn, craterProfile, madeGround, setKeepOut, rimBoost, rocksAround, standingPlace, type Crater, type Rock } from "./detail.ts";
|
|
8
10
|
export { rockMesh, type RockMesh } from "./rocks.ts";
|
package/dist/surface/index.js
CHANGED
|
@@ -4,5 +4,7 @@ export { SURFACE_SITES, siteById } from "./site.js";
|
|
|
4
4
|
export { EYE_HEIGHT, FOV_LIMITS, WALK_SPEED, clampLook, forward, stepOver, viewProjection } from "./view.js";
|
|
5
5
|
export { decodeHeight, drop, emptyLevel, fillFromCoarser, groundAt, sampleLevel, tileAddress } from "./height.js";
|
|
6
6
|
export { loadPlan, loadTerrain } from "./load.js";
|
|
7
|
-
export {
|
|
7
|
+
export { landerParts, roverParts } from "./shapes.js";
|
|
8
|
+
export { keepAway, objectParts, objectsOf, partShadows, traverseOf, KEEP_OUT } from "./objects.js";
|
|
9
|
+
export { craterIn, craterProfile, madeGround, setKeepOut, rimBoost, rocksAround, standingPlace } from "./detail.js";
|
|
8
10
|
export { rockMesh } from "./rocks.js";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { SiteObject } from "./objects.ts";
|
|
2
|
+
export declare const APOLLO_17_OBJECTS: readonly SiteObject[];
|
|
3
|
+
/** The rover's nine traverses, each as east, north, east, north, ... in metres from the site point. */
|
|
4
|
+
export declare const APOLLO_17_TRAVERSE: readonly (readonly number[])[];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export const APOLLO_17_OBJECTS = [
|
|
2
|
+
{ id: "lm", kind: "lander", name: { en: "Lunar module Challenger, descent stage", ja: "月着陸船チャレンジャー(降下段)" }, east: -17.6, north: -5.8, lat: 20.1909, lon: 30.7717 },
|
|
3
|
+
{ id: "flag", kind: "flag", name: { en: "The flag", ja: "旗" }, east: -23.1, north: 12.6, lat: 20.1915, lon: 30.7715 },
|
|
4
|
+
{ id: "alsep", kind: "station", name: { en: "ALSEP central station", ja: "ALSEP 中央局" }, east: -210, north: 30, lat: 20.1921, lon: 30.7649 },
|
|
5
|
+
{ id: "sep", kind: "instrument", name: { en: "Surface electrical properties transmitter", ja: "表面電気特性の送信機" }, east: 110.9, north: 21, lat: 20.1918, lon: 30.7762 },
|
|
6
|
+
{ id: "rover", kind: "rover", name: { en: "Lunar rover, where its last traverse ends", ja: "月面車(最後の走行の終点)" }, east: 76.9, north: 11.1, heading: 264 },
|
|
7
|
+
];
|
|
8
|
+
/** The rover's nine traverses, each as east, north, east, north, ... in metres from the site point. */
|
|
9
|
+
export const APOLLO_17_TRAVERSE = [
|
|
10
|
+
[-6888.5, -2788.4, -6843.5, -2762.6, -6772.1, -2715.6, -6714.6, -2671.8, -6680.2, -2642, -6647.8, -2611.6, -6614.8, -2579.8, -6583, -2548, -6552, -2514.9, -6521.6, -2479.8, -6495.1, -2444.8, -6468, -2407.7, -6454.8, -2386.5, -6446.9, -2368, -6440.2, -2350.1, -6439.6, -2332.9, -6437.6, -2323.7, -6433.6, -2301.8, -6429, -2281.3, -6417.1, -2257.5, -6409.2, -2238.3, -6389.4, -2197.3, -6371.5, -2156.9, -6335.2, -2072.9, -6300.8, -1990.2, -6280.3, -1949.1, -6269.7, -1926.6, -6259.8, -1908.8, -6238.7, -1867.7, -6226.1, -1849.2, -6214.2, -1830, -6200.3, -1811.5, -6184.4, -1796.2, -6165.3, -1775.1, -6152.7, -1765.1, -6119, -1739.3, -6080.6, -1710.8, -6061.5, -1696.9, -6042.9, -1683.7, -6006.6, -1659.2, -5967.6, -1632.7, -5929.2, -1606.9, -5893.5, -1582.4, -5855.8, -1555.2, -5818.1, -1530.7, -5739.4, -1482.4, -5665.4, -1434, -5588.6, -1383.7, -5514.6, -1332.7, -5478.2, -1304.9, -5443.8, -1277.7, -5410.1, -1248.6, -5375.7, -1216.2, -5344, -1183.7, -5310.9, -1150.6, -5283.1, -1116.9, -5253.4, -1082.5, -5234.9, -1062.6, -5224.9, -1048.1, -5195.2, -1013, -5166.1, -979.2, -5134.3, -946.1, -5100.6, -917.7, -5064.9, -889.2, -5027.9, -861.4, -4990.8, -833.6, -4956.4, -807.8, -4917.4, -780, -4881.7, -754.8, -4844, -726.4, -4808.3, -701.2, -4771.9, -673.4, -4736.9, -645.6, -4703.1, -615.1, -4674, -583.4, -4652.2, -563.5, -4637.7, -551.6, -4601.9, -523.2, -4567.5, -498, -4525.9, -473.5, -4486.2, -453, -4407.5, -409.3, -4331.4, -361.6, -4256, -309.3, -4218.3, -285.5, -4199.1, -272.9, -4179.3, -263, -4158.1, -253.7, -4136.3, -248.4, -4111.8, -245.8, -4090, -246.4, -4045.7, -250.4, -3999.4, -253.7, -3955.7, -256.3, -3910.1, -255.6, -3865.8, -256.9, -3819.5, -256.9, -3728.9, -258.2, -3668, -259.5, -3638.9, -262.1, -3595.2, -267.4, -3547.6, -277.3, -3530.4, -281.9, -3504, -283.9, -3459.6, -283.9, -3414, -284.5, -3367.7, -284.5, -3275.8, -289.1, -3232.8, -290.4, -3188.5, -293.1, -3143.5, -297.7, -3095.9, -303.6, -3052.9, -310.9, -3007.9, -318.2, -2963.6, -324.8, -2917.3, -331.4, -2874.9, -345.3, -2832.6, -363.8, -2794.9, -383, -2753.9, -406.8, -2712.9, -425.9, -2671.9, -445.1, -2630.2, -459.7, -2583.3, -466.9, -2559.5, -470.9, -2539.7, -469.5],
|
|
11
|
+
[-6888.3, -2788.4, -6855.8, -2789.4, -6840.1, -2788.7, -6825.8, -2786.4, -6809.4, -2781.5, -6790.1, -2773.6, -6762.8, -2759.4, -6723.2, -2739.5, -6694.1, -2724.3, -6663, -2707.7, -6638.5, -2690.5, -6617.4, -2666.7, -6599.5, -2636.9, -6580.4, -2617, -6550.6, -2590.5, -6528.8, -2571.3, -6506.3, -2553.5, -6474.6, -2532.9, -6446.2, -2515.7, -6417.1, -2497.2, -6394.6, -2481.9, -6374.1, -2460.1, -6355.6, -2440.2, -6331.1, -2412.4, -6310, -2385.9, -6288.8, -2354.8, -6262.4, -2318.4, -6229.3, -2270.1, -6200.9, -2227.1, -6167.8, -2186.7, -6137.4, -2152.3, -6108.3, -2119.8, -6083.2, -2097.3, -6060.1, -2080.1, -6031, -2065.5, -5998.6, -2051, -5970.1, -2037.7, -5939.7, -2021.1, -5920.5, -2008.6, -5900, -1991.3, -5879.5, -1968.8, -5856.4, -1940.4, -5836.6, -1913.2, -5804.2, -1870.2, -5768.5, -1821.3, -5746.6, -1788.8, -5730.1, -1756.4, -5718.2, -1720, -5691.8, -1642.6, -5679.2, -1623.4, -5659.4, -1603.5, -5619, -1573.8, -5586.6, -1551.2, -5554.2, -1526.1, -5526.5, -1492.3, -5507.3, -1464.5, -5491.4, -1431.4, -5485.5, -1410.3, -5484.1, -1386.5, -5484.2, -1360, -5486.1, -1332.2, -5492.8, -1301.1, -5502.7, -1270.1, -5513.9, -1248.9, -5530.5, -1231.7, -5552.3, -1207.9, -5563.5, -1189.4, -5574.8, -1165.6, -5584.7, -1143.1, -5592, -1118, -5599.9, -1085.6, -5609.9, -1056.5, -5619.1, -1034, -5640.3, -1004.9, -5669.4, -967.2, -5694.5, -932.2, -5713.1, -901.1, -5725, -868.1, -5756.1, -811.9, -5792.5, -743.1, -5813.6, -702.8, -5825.5, -673.7, -5828.9, -645.2, -5830.2, -615.5, -5836.8, -589.7, -5844.1, -565.2, -5849.7, -555.4, -5855, -546.6, -5861.6, -538.7, -5866.4, -533.6, -5882.5, -516.6, -5866.2, -516.7, -5839.5, -516.9, -5818.2, -517.9, -5804.5, -517.4, -5793.2, -516.9, -5768.7, -513.5, -5739.6, -506.2, -5693.9, -491, -5656.3, -473.8, -5614.6, -455.2, -5582.2, -440.6, -5535.9, -419.4, -5418.2, -363.1, -5353.3, -325.4, -5322.9, -307.5, -5276, -278.4, -5248.2, -261.2, -5236.3, -244.6, -5219.1, -236.7, -5193.9, -222.8, -5169.5, -200.2, -5156.2, -179.1, -5136.4, -134.7, -5115.9, -81.8, -5103.3, -43.4, -5090.8, -5.1, -5082.8, 12.8, -5063.7, 34.6, -5022.7, 71, -4982.3, 110.8, -4936.7, 155.1, -4892.4, 199.4, -4860.6, 236.5, -4796.5, 309.3, -4735.6, 382.1, -4630.4, 509.8, -4566.3, 587.9, -4546.4, 604.5, -4520.6, 617.7, -4494.2, 625.7, -4467.7, 625.7, -4430.7, 624.4, -4403.5, 623.7, -4375.8, 627.7, -4350, 637, -4318.2, 651.5, -4291.1, 667.4, -4256.7, 693.2, -4237.5, 707.1, -4228.9, 715.8, -4223.1, 722, -4218.2, 727.9, -4212.9, 734.6, -4208.4, 732.4, -4198.7, 728.2, -4193, 725.6, -4187.4, 723.6, -4176.1, 720.3, -4157.1, 717.4, -4131, 715.1, -4109.2, 715.8, -4073.5, 717.8, -4024.5, 717.8, -3986.8, 717.2, -3974.2, 712.5, -3946.4, 696.7, -3931.2, 686.8, -3910.7, 682.8, -3884.9, 678.2, -3855.2, 676.2, -3812.2, 674.9, -3759.9, 676.9, -3721.5, 677.6, -3682.5, 678.9, -3646.8, 675, -3605.1, 664.4, -3561.4, 652.5, -3510.5, 644.6, -3457.6, 640, -3410.6, 638, -3376.1, 638.1, -3323.2, 639.7, -3294.6, 641.9, -3247, 647.2, -3208.9, 655.6, -3158.6, 666.8, -3092.4, 681.1, -3076.1, 686.4, -3062.9, 692.2, -3050.2, 697.9, -3037.7, 704.7, -3026.3, 711.1, -3015.8, 718.4, -2994, 736.8, -2977.4, 751.5, -2971.3, 756, -2965.9, 759.3, -2960.1, 760.4, -2954.7, 759.3, -2942.8, 753, -2928.2, 743.1, -2887.7, 709.4, -2853.8, 679, -2821, 657.3],
|
|
12
|
+
[-2821.1, 657.3, -2782.9, 635.4, -2742.4, 615.1, -2703.9, 596.5, -2662.6, 579.4, -2621.9, 566.4, -2579, 553.7, -2537.3, 540.6, -2493.7, 527.9, -2452.4, 515.6, -2409.5, 506.1, -2367.9, 497.3, -2322.2, 491.8, -2279, 486.6, -2256.7, 483.8, -2234.9, 478.3, -2211.1, 468, -2198.8, 457.2, -2164.3, 429.5, -2130.5, 401.7, -2096.4, 372.7, -2063.5, 344.5, -2027, 316.4, -1993.6, 290.2, -1972.2, 271.9, -1959.5, 260.4, -1942.8, 246.5, -1923, 237.4, -1900, 229, -1880.9, 223.9, -1858.7, 217.9, -1838.9, 214.4, -1814.3, 210.8, -1794, 208.8, -1771.4, 206.4, -1750.8, 204.8, -1725.4, 203.6, -1706.3, 203.2, -1684.5, 202, -1665.4, 197.7, -1643.2, 186.6, -1625.4, 174.7, -1607.5, 160.8, -1594.8, 142.1, -1584.9, 125, -1574.6, 103.2, -1568.6, 84.6, -1558.3, 63.5, -1548.4, 42.9, -1533.7, 27.4, -1515.5, 16.3, -1496.4, 4.4, -1478.2, -8.7, -1462.7, -24.2, -1448, -43.6, -1438.9, -61.1, -1427.4, -81.4, -1415.5, -96.4, -1399.6, -114.7, -1383.7, -126.6, -1359.7, -140.3, -1341.6, -150, -1330.4, -156, -1323.9, -159, -1314.3, -163.5, -1304.4, -168.9, -1293.7, -174.4, -1282.2, -180.5, -1274.1, -184.4, -1262, -189.8, -1243.8, -196.3, -1197.2, -200.1, -1152.8, -199.7, -1128.6, -198.1, -1106.4, -193.7, -1086.5, -189.4, -1062.3, -181.8, -1044.4, -175.9, -1017.8, -167.9, -994.8, -162, -972.2, -158.4, -947.6, -154.9, -927, -153.7, -903.5, -152.1, -883.7, -152.1, -851.9, -151.3, -835.3, -150.1, -814.6, -147.4, -796.8, -140.2, -791.6, -137, -754.3, -110.9, -741.6, -104.1, -719.4, -92.2, -705.9, -88.2, -683.3, -85.1, -667.4, -84.7, -636.4, -84.7, -621.3, -84.7, -574.1, -84.3, -528.9, -83.5, -480.8, -85.1, -434.8, -84.4, -388.4, -84.8, -361.6, -84.3, -342.2, -83.4, -323.6, -82.5, -309.4, -81, -292, -79.6, -281.4, -78.8, -270.5, -77.7, -260.6, -76.6, -248.9, -75.5, -233, -73.6, -220.9, -71.5, -207.7, -68.6, -197.1, -65.8, -180.8, -60.3, -163.3, -53.5, -118.9, -39.2, -95.5, -34.5, -75.2, -28.5, -30.4, -18.6, 2.6, -11.5, 18.1, -9.5, 45, -4, 58.5, 0.8],
|
|
13
|
+
[58.5, 0.8, 36.3, -19.9, 14.5, -34.9, -9, -46.4, -37.5, -56.7, -74, -71.8, -98.3, -78.1, -116.9, -81.3, -129, -82, -143.5, -82.9, -154.7, -82.7, -167, -81.4, -177, -79.3, -189.1, -75.3, -202.3, -68.4, -212.3, -61.9, -224.9, -54.3, -231.4, -50.3, -240.3, -46.3, -249.8, -44.4, -257.4, -43.9, -274.3, -45, -290.9, -46.1, -307.4, -47.7, -328.1, -50.7, -342.3, -52.1, -359.8, -54.3, -374.2, -56.2, -383.6, -57.3, -390.7, -59.2, -398.4, -61.9, -406.7, -66.9, -415.4, -74.2, -432.1, -87.8, -442.9, -95.1, -460.5, -104, -478.7, -109.9, -498, -112.6, -518, -114.5, -536.2, -115.2, -557.1, -116.1, -576.1, -117.3, -603.5, -117.6, -637.6, -118.8, -690.8, -118.4, -742.8, -116, -780.9, -112.8, -821.4, -110.4, -851.5, -112.4, -878.9, -119.2, -904.3, -130.3, -928.5, -145.3, -953.2, -163.2, -975.4, -179.5, -998.4, -191.8, -1026.2, -204.8, -1048.8, -211.2, -1080.2, -217.1, -1119.5, -221.9, -1148.4, -225.5, -1174.2, -230.2, -1197.6, -237.8, -1214.3, -245.7, -1235.4, -258.4, -1265.9, -278.2, -1289.7, -292.5, -1313.9, -305.6, -1337, -315.5, -1362, -326.2, -1386.2, -332.6, -1408, -334.6, -1431.4, -336.5, -1455.2, -339.3, -1475.1, -343.3, -1494.1, -348.4, -1510, -356.4, -1529.9, -366.3, -1550.1, -377.8, -1568, -388.5, -1583.4, -398.4, -1608.4, -410.7, -1628.7, -418.7, -1645.8, -422.6, -1671.6, -427.8, -1687, -429.4, -1711.6, -433, -1735.8, -436.5, -1803.7, -443.7, -1856.5, -447.6, -1901.3, -451.2, -1937.1, -453.6, -1969.2, -456, -1993, -459.1, -2006.1, -463.1, -2014.8, -468.3, -2024.4, -478.2, -2035.5, -490.1, -2048.6, -500.4, -2061.3, -506, -2079.1, -508.3, -2132.7, -513.1, -2166.1, -515.9, -2193, -517.1, -2226, -517.1, -2267.7, -516.7, -2303.8, -513.9, -2329.2, -509.9, -2352.2, -504.4, -2375.2, -495.7, -2395.8, -484.9, -2418.8, -476.2, -2448.6, -469.9, -2474.8, -468.3, -2504.2, -468.3, -2539.7, -469.5],
|
|
14
|
+
[-210.8, 30.7, -203.8, 34, -196.5, 36.7, -184, 32, -145.6, 23.8, -122.1, 19.1, -72.8, 8.5, -29.2, 0.6, -17.9, -0.1, -2.7, -0.8, 25.4, -3.1, 58.5, 0.8, 76, 3.8, 97.1, 5.8, 124.9, 0.2, 146.4, -9.8, 172.2, -28.6, 196, -47.8, 230.7, -78.9, 244.6, -95.1, 251.8, -107.4, 258.7, -120.4, 264.9, -139.5, 268.9, -160.3, 270.2, -176.2, 270.2, -199, 268.5, -226.1, 267.2, -249.9, 266.8, -269.8, 269.1, -283.3, 274.7, -297.9, 284, -315.1, 292.3, -328, 300.5, -344.9, 305.8, -360.4, 307.8, -377.3, 310.7, -394.2, 315, -413.7, 320.3, -435.8, 326.6, -459, 329.6, -473.9, 335.5, -498.5, 341.9, -523.5, 347.4, -545.7, 350.6, -566.8, 353.5, -584.9, 354.9, -592.9, 357.3, -601.4],
|
|
15
|
+
[356.9, -600.7, 361.1, -610.7, 363.7, -616.1, 369.3, -628.8, 375.2, -647, 379.9, -669.2, 381.9, -689.4, 383.4, -712.4, 384.3, -755.4, 386.6, -797.4, 388.6, -816.5, 394.2, -840.7, 399.5, -859.4, 405.1, -873.4, 407.7, -880.4, 411, -898.2, 411.7, -915.1, 411.4, -923.7, 407.4, -946.5, 404.4, -960.4, 402.4, -965.4, 398.8, -986.9, 398.4, -994.1, 399.7, -1004.1, 406.7, -1039.1],
|
|
16
|
+
[406.7, -1039.1, 396.4, -1027.9, 388.8, -1014.6, 379.9, -1000.8, 374.6, -984.9, 376, -970.7, 380.9, -956.8, 384.2, -942.9, 386.6, -927.3, 386.2, -904.5, 384.3, -889.6, 376.7, -871.4, 370.4, -858.9, 356.8, -834.4, 347.9, -818.5, 335.7, -799.6, 330.7, -789.1, 327.4, -778.5, 325.8, -760.6, 325.8, -726.2, 323.8, -674.6, 321.5, -643.2, 316.3, -625, 305.4, -592.9, 293.5, -562.2, 286.2, -546.9, 272.6, -527.8, 255.1, -496, 245.2, -475.2, 239, -453.3, 235.7, -432.2, 233.9, -414.5, 234.4, -383.5, 235.2, -339.9, 236, -306.1, 237.2, -277.6, 241.2, -235.1, 244.8, -197.4, 244, -164.9, 237.2, -131.9, 227.7, -112.9, 203.1, -82.3, 182.5, -62.8, 148.8, -27.5, 133.3, -12.4, 121, -3.3, 97.1, 5.8],
|
|
17
|
+
[-17.9, -0.1, 23.7, 0.2, 61.5, 4.4, 89.6, 16.6, 107.3, 35.1, 121.9, 52.8, 134.8, 62.9, 147.5, 67.9, 162.1, 68.9, 179, 69.5, 191.5, 70, 205.5, 73.7, 223.8, 84, 244.7, 100.1, 264.8, 121.3, 276.4, 135, 287.6, 150.6, 295, 167.6, 298.2, 182.1, 299.7, 200.6, 300, 221.5, 300.3, 252.5, 299.5, 303.3, 299.6, 360.4, 297.2, 429, 294.6, 474, 289.3, 493.3, 279.3, 521.9, 272.1, 547.5, 269.2, 567.9, 267.1, 591.2, 266.3, 631.7, 265.8, 667.9, 264.8, 699.9, 263.5, 735.1, 261.6, 757.1, 255.8, 783.8, 249.8, 811.6, 242.6, 834.1, 236.5, 852.6, 235.8, 865.3, 236.8, 875.4, 240.8, 888.6, 251.4, 912.7, 260.1, 934.9, 270.5, 960.8, 281.9, 993.1, 291.1, 1027.7, 296.7, 1053.1, 300.4, 1074, 304.4, 1101, 305.7, 1123.5, 306.3, 1159.5, 306.8, 1187, 308.2, 1219.8, 306.6, 1248.1, 303.2, 1270.9, 300.5, 1289.1, 301.3, 1320.6, 304.8, 1344.4, 309, 1368, 316.7, 1390.2, 324.1, 1406.3, 337.1, 1432, 349, 1450.5, 361.2, 1466.1, 376.3, 1489.7, 381.1, 1500.2, 382.1, 1512.4, 382.7, 1527, 383.2, 1545.2, 382.4, 1573, 380.3, 1585.4, 373.7, 1598.9, 366.8, 1612.2, 363.9, 1628.6, 362.6, 1644.4, 362.6, 1661.9, 363.7, 1681.7, 369.3, 1703.7, 386.5, 1736.2, 397.1, 1751.3, 407.7, 1768.8, 417.7, 1783.3, 425.1, 1798.9, 428.3, 1810.8, 430.2, 1834.1, 430.2, 1852.4, 422.3, 1868.8, 408.5, 1883.1, 376.5, 1915.6, 345.8, 1945.8, 308.8, 1980.8, 294, 1996.6, 288.4, 2010.9, 284.5, 2026.5, 283.7, 2086.1, 284.5, 2107.5, 282.1, 2122.3, 275.8, 2137.1, 265.5, 2156.7, 259.9, 2171.5, 257.8, 2181.6, 257, 2205.7, 258.4, 2222.1, 263.9, 2233.7, 271.1, 2243.2, 285.6, 2255.9, 301.2, 2270.2, 328.3, 2295.9, 343.1, 2312, 359.5, 2332.1, 366.1, 2348.5, 372.2, 2370.2, 375.1, 2385.5, 385.7, 2435.3, 392.1, 2467, 399.8, 2512, 409.1, 2556.7, 414.7, 2578.4, 416.3, 2595.6, 415, 2625.2, 413.1, 2640.6, 409.1, 2667.6, 409.4, 2689.8, 411.5, 2703.3, 418.7, 2716, 432.5, 2733.7, 455.5, 2762.5, 471.7, 2780.2, 484.4, 2790.3, 499.5, 2799.8, 514.3, 2807.5, 533.3, 2815.4, 552.4, 2825.2, 579.1, 2843.4, 593.2, 2853.2, 605.9, 2861.7, 625.2, 2872, 653, 2887.8, 671.5, 2898.1, 697.2, 2913.7, 719.2, 2927.5, 740.4, 2942.3, 751.8, 2951.5, 763.1, 2962.4, 772.9, 2975.3, 783.5, 2990.4, 787.8, 2996.8, 805, 2991.5, 820.3, 2987.5, 834.9, 2980.6, 855.8, 2970.8, 871.9, 2967.3, 897.9, 2966, 939.9, 2964.6, 974.1, 2964.6, 996.6, 2965.1, 1018.3, 2969.9, 1034.4, 2973.8, 1050.1, 2976.7, 1063, 2977.8, 1089.8, 2978, 1142.2, 2976.9, 1161, 2977.2, 1174.2, 2978.8, 1190.1, 2984.9, 1207, 2992.2, 1223.7, 3002.3, 1239.3, 3011.3, 1248.6, 3016.3, 1274, 3029.8, 1276.9, 3031.1, 1310.3, 3029.7, 1325.9, 3029.5, 1368, 3029.4, 1390.4, 3029.2, 1407.1, 3029.1, 1414.5, 3027.3, 1421.7, 3020.9, 1432, 3010.6, 1447.6, 2995.5, 1460, 2983.9, 1474.1, 2973.3, 1485.7, 2966.4, 1498.4, 2962.1, 1507.4, 2961.1, 1521.9, 2959.7, 1562.2, 2959.7, 1605.3, 2958.9, 1626, 2957.3, 1637.3, 2952.8, 1663.5, 2939.3, 1719.6, 2912.2, 1773.6, 2890, 1803.2, 2877.4, 1825, 2862.8, 1842.2, 2850.3, 1858.9, 2834.4, 1876.5, 2817.3, 1898.5, 2799.5, 1922.6, 2781.9, 1949.5, 2761.8, 1997.3, 2726.6, 2057, 2684.8, 2080.7, 2668.1, 2098.2, 2658.1, 2119, 2648.2, 2139.7, 2639.9, 2167, 2628.8, 2197.9, 2617, 2218.3, 2610.2, 2230.3, 2605.5, 2248.7, 2595.1, 2270.1, 2581.3, 2297.4, 2560.1, 2328.7, 2537, 2366.8, 2510.3, 2393.1, 2490.8, 2411.7, 2476.6, 2424.8, 2465.2, 2445.5, 2448.9, 2463.3, 2434.7, 2479.4, 2418.8, 2498.6, 2400.1, 2512.8, 2388.9, 2528.5, 2376, 2540.8, 2365.4, 2548.2, 2359.7, 2555.8, 2355.4, 2565.9, 2354.6, 2575.3, 2354.6, 2584.2, 2355.6, 2593, 2359.8, 2601.3, 2365.3, 2609.1, 2368.9, 2617.4, 2370.6, 2627.4, 2372.1, 2644.3, 2372.1, 2660.4, 2371.6, 2674.6, 2371, 2684.7, 2369.9, 2697, 2366.9, 2709.1, 2366.7, 2718.6, 2367.3, 2730.3, 2370.9, 2740.4, 2376.8, 2749.9, 2383.8, 2766.3, 2400.1, 2788.9, 2424.2, 2832.4, 2475.6, 2853.8, 2503.9, 2869, 2521.9, 2884.7, 2540.3, 2903.2, 2559.3, 2917.8, 2572.4, 2930.9, 2581.5, 2944.5, 2589.3, 2958.1, 2595.8, 2968.2, 2599.2, 2972.7, 2599.7, 2976.6, 2600.1, 2980.8, 2599.9, 2984.3, 2599.5, 2986.7, 2598.9, 2989, 2597.7, 2991.3, 2595.9, 2993.9, 2593.5],
|
|
18
|
+
[2993.9, 2593.5, 2995.3, 2592.1, 2996.2, 2590.5, 2997, 2589.1, 2997.9, 2587.3, 2998.5, 2585, 2998.8, 2582.2, 2998.2, 2578.2, 2997.3, 2574.1, 2995.8, 2569.6, 2993.5, 2564.2, 2990.1, 2556.2, 2985.5, 2547.3, 2978.3, 2533.4, 2958.4, 2497.7, 2938.5, 2458.8, 2911.9, 2423.9, 2901.9, 2408, 2886.4, 2388.2, 2868.6, 2365.2, 2860.2, 2350.9, 2849.1, 2336.7, 2846.7, 2328.7, 2846.7, 2318, 2848.6, 2268, 2853.4, 2223.2, 2854.1, 2180.7, 2856.5, 2157.7, 2855.3, 2136.2, 2853.3, 2113.2, 2850.9, 2091.4, 2844.5, 2049.3, 2838.5, 2024.3, 2834.1, 2005.7, 2826.6, 1973.9, 2824.6, 1962.8, 2815, 1920.8, 2810.3, 1902.5, 2807.1, 1885.5, 2804.3, 1872.4, 2799.5, 1848.2, 2793.9, 1834.7, 2784.4, 1811.3, 2773.7, 1799.4, 2759, 1787.9, 2741.1, 1776.4, 2726, 1769.3, 2708.1, 1761.7, 2687.5, 1756.2, 2661.3, 1749.5, 2651, 1748.3, 2626.7, 1743.6, 2609.7, 1740, 2586.6, 1733.3, 2565.6, 1726.6, 2546.1, 1719, 2526.3, 1712.3, 2505.3, 1702.8, 2486.6, 1690.9, 2470.3, 1677.4, 2451.6, 1665.6, 2427, 1649.7, 2412.3, 1640.2, 2394.9, 1630.3, 2381.7, 1627.1, 2372.6, 1626.3, 2348.8, 1624.8, 2327, 1620.8, 2309.9, 1614.1, 2289.2, 1603.4, 2251.5, 1579.6, 2216.6, 1552.7, 2181.6, 1525.7, 2149.1, 1501.5, 2108.9, 1476.6, 2071.2, 1451.2, 2034.3, 1427, 2000.9, 1403.6, 1977.1, 1389.4, 1960, 1380.2, 1942.6, 1370.3, 1925.5, 1357.7, 1906.4, 1341.4, 1892.1, 1325.9, 1876.6, 1309.7, 1861.9, 1295.4, 1845.3, 1280.3, 1828.2, 1267.2, 1810.3, 1255.8, 1788.5, 1246.2, 1766.6, 1238.7, 1745.2, 1231.2, 1728.1, 1225.7, 1717, 1223.3, 1729.7, 1208.6, 1735.7, 1194.7, 1746, 1168.1, 1760.6, 1135.9, 1769.7, 1113.3, 1778.9, 1091.1, 1782.4, 1072, 1785.6, 1051.4, 1787.5, 1027.6, 1789.1, 1004.2, 1789.5, 983.9, 1787.5, 962.9, 1784.3, 938.3, 1779.5, 895.8, 1773.2, 869.6, 1767.6, 851.8, 1759.6, 826.8, 1753.7, 810.5, 1741.4, 787.9, 1730.2, 770, 1719.5, 747.8, 1711.2, 734.3, 1692.5, 705.8, 1674.2, 681.6, 1651.6, 649.5, 1627.7, 616.1, 1599.1, 577.7, 1575.3, 547.9, 1540.3, 504.7, 1496.7, 459.1, 1475.6, 438.5, 1456.6, 415.4, 1445.8, 401.6, 1434.3, 379, 1425.2, 365.5, 1415.2, 352, 1407.3, 344.4, 1389.4, 332.9, 1366.8, 324.6, 1336.6, 313.9, 1324.7, 308.8, 1298.1, 301.3, 1274.7, 292.9, 1241.8, 281.1, 1202.9, 264, 1181.4, 253.3, 1160.4, 239.1, 1137.7, 221.2, 1112.7, 206.5, 1083.8, 189.7, 1054, 175.4, 1027.8, 165.1, 989.7, 149.7, 961.9, 139, 898.8, 118, 882.6, 113.2, 847.2, 105.3, 823.8, 98.2, 752.8, 78.8, 709.1, 64.9, 668.6, 55, 630.1, 45.5, 608.7, 43.5, 576.5, 40, 534.8, 34.5, 510.6, 32.9, 488.8, 31.3, 446.7, 28.1, 419, 26.2, 403.1, 24.6, 374.5, 22.6, 356.2, 22.2, 332, 21.9, 317.4, 21.1, 289.6, 19.5, 261, 19.1, 203.4, 17.6, 183.2, 18.4, 162.6, 17.6, 141.1, 16, 116.9, 15.2, 76.9, 11.1, 76.9, 11.1],
|
|
19
|
+
];
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { type Part } from "./shapes.ts";
|
|
2
|
+
/**
|
|
3
|
+
* One thing at a site: where it stands (metres east and north of the site point), what it is, and for the rover the way it points.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { objectsOf } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
8
|
+
*
|
|
9
|
+
* const lander = objectsOf("apollo-17").find((object) => object.kind === "lander");
|
|
10
|
+
* console.log(lander?.name.en, lander?.east, lander?.north);
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export interface SiteObject {
|
|
14
|
+
id: string;
|
|
15
|
+
kind: "lander" | "rover" | "flag" | "station" | "instrument";
|
|
16
|
+
name: {
|
|
17
|
+
en: string;
|
|
18
|
+
ja: string;
|
|
19
|
+
};
|
|
20
|
+
east: number;
|
|
21
|
+
north: number;
|
|
22
|
+
/** The way a vehicle points, degrees clockwise from north (the rover's, read from the end of its path by this package). */
|
|
23
|
+
heading?: number;
|
|
24
|
+
/** Where the published position is, planetocentric degrees (the rover's is a reading of a line, so it has none). */
|
|
25
|
+
lat?: number;
|
|
26
|
+
lon?: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The things at a site, at their published places; none for a site that has none.
|
|
30
|
+
*
|
|
31
|
+
* @param site - A site's name from `SURFACE_SITES`.
|
|
32
|
+
* @returns The objects.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* import { objectsOf } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
37
|
+
*
|
|
38
|
+
* console.log(objectsOf("apollo-17").map((object) => object.id).join(", "), objectsOf("nowhere").length);
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare function objectsOf(site: string): readonly SiteObject[];
|
|
42
|
+
/**
|
|
43
|
+
* The rover's traverses at a site as lines, each east, north, east, north, ... in metres from the site point (the published path, digitised from the orbiter's images).
|
|
44
|
+
*
|
|
45
|
+
* @param site - A site's name from `SURFACE_SITES`.
|
|
46
|
+
* @returns The lines, or none.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* import { traverseOf } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
51
|
+
*
|
|
52
|
+
* const lines = traverseOf("apollo-17");
|
|
53
|
+
* console.log(lines.length, "traverses,", lines.reduce((n, line) => n + line.length / 2, 0), "points");
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export declare function traverseOf(site: string): readonly (readonly number[])[];
|
|
57
|
+
/**
|
|
58
|
+
* How far round an object the made craters and rocks keep away: nothing is made inside `inner` metres of its place, and the ground is all its own again from `outer` metres.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* import { KEEP_OUT } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
63
|
+
*
|
|
64
|
+
* console.log(KEEP_OUT.lander.inner, KEEP_OUT.lander.outer);
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export declare const KEEP_OUT: Record<SiteObject["kind"], {
|
|
68
|
+
inner: number;
|
|
69
|
+
outer: number;
|
|
70
|
+
}>;
|
|
71
|
+
export type { Part } from "./shapes.ts";
|
|
72
|
+
/**
|
|
73
|
+
* The shape of one object as plain parts placed at its site: the lunar module's descent stage (an octagonal gold body on four splayed legs with braces and footpads, a ladder, a bell under it), the rover (a frame
|
|
74
|
+
* on four wheels with fenders, two seats, a console, the dish and the camera on their masts), the flag, the ALSEP station and the transmitter. `base` is the height of the ground at the object's place in metres over
|
|
75
|
+
* the site's ground; the shapes stand on it. All of it is this package's drawing from published sizes: it is no model of the real thing.
|
|
76
|
+
*
|
|
77
|
+
* @param object - The object.
|
|
78
|
+
* @param base - The ground's height at its place.
|
|
79
|
+
* @returns The parts, in the site's plane (x east, y up, z north).
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```ts
|
|
83
|
+
* import { objectParts, objectsOf } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
84
|
+
*
|
|
85
|
+
* const lander = objectsOf("apollo-17").find((object) => object.kind === "lander")!;
|
|
86
|
+
* const parts = objectParts(lander, 0);
|
|
87
|
+
* console.log(parts.length, "parts,", parts.reduce((n, part) => n + part.position.length / 9, 0), "triangles");
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export declare function objectParts(object: SiteObject, base: number): Part[];
|
|
91
|
+
/**
|
|
92
|
+
* The shadows of an object's parts on the ground for a Sun at an azimuth and an altitude: for each part the convex hull of where its corners fall on the plane of its base, as triangles (x east, y up, z north) lifted a
|
|
93
|
+
* hair off the ground. Flat and hard-edged: the Moon has no air.
|
|
94
|
+
*
|
|
95
|
+
* @param parts - The object's parts, as `objectParts` makes them.
|
|
96
|
+
* @param base - The ground's height under it.
|
|
97
|
+
* @param azimuth - The Sun's azimuth, degrees clockwise from north.
|
|
98
|
+
* @param altitude - The Sun's altitude in degrees.
|
|
99
|
+
* @returns The triangles' corners, three numbers each.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* import { objectParts, objectsOf, partShadows } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
104
|
+
*
|
|
105
|
+
* const flag = objectsOf("apollo-17").find((object) => object.kind === "flag")!;
|
|
106
|
+
* const shadow = partShadows(objectParts(flag, 0), 0, 95, 13);
|
|
107
|
+
* console.log(shadow.length / 9, "triangles of shadow");
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
export declare function partShadows(parts: readonly Part[], base: number, azimuth: number, altitude: number): number[];
|
|
111
|
+
/**
|
|
112
|
+
* How much of the made ground (its craters and rocks) is kept at a point: 0 at an object's place, up to 1 where it is the ground's own again, so that no made crater cuts the lunar module's legs. The smallest over the objects.
|
|
113
|
+
*
|
|
114
|
+
* @param x - Metres east of the site point.
|
|
115
|
+
* @param y - Metres north of the site point.
|
|
116
|
+
* @param objects - The objects of the site.
|
|
117
|
+
* @returns A share from 0 to 1.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```ts
|
|
121
|
+
* import { keepAway, objectsOf } from "@johnmorrisdotca/wakusei-planets/surface";
|
|
122
|
+
*
|
|
123
|
+
* const objects = objectsOf("apollo-17");
|
|
124
|
+
* console.log(keepAway(objects[0]!.east, objects[0]!.north, objects), keepAway(500, 500, objects));
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
export declare function keepAway(x: number, y: number, objects: readonly SiteObject[]): number;
|