@woosh/meep-engine 2.163.2 → 2.163.4

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.
Files changed (47) hide show
  1. package/package.json +1 -1
  2. package/src/core/geom/3d/equirectangular/equirectangular_direction_to_uv.d.ts +12 -0
  3. package/src/core/geom/3d/equirectangular/equirectangular_direction_to_uv.d.ts.map +1 -0
  4. package/src/core/geom/3d/equirectangular/equirectangular_direction_to_uv.js +18 -0
  5. package/src/core/geom/3d/equirectangular/equirectangular_uv_to_direction.d.ts +14 -0
  6. package/src/core/geom/3d/equirectangular/equirectangular_uv_to_direction.d.ts.map +1 -0
  7. package/src/core/geom/3d/equirectangular/equirectangular_uv_to_direction.js +24 -0
  8. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_face_island_erode.d.ts.map +1 -1
  9. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_face_island_erode.js +368 -290
  10. package/src/core/geom/vec3/v3_uniform_sample_cone.d.ts +11 -0
  11. package/src/core/geom/vec3/v3_uniform_sample_cone.d.ts.map +1 -0
  12. package/src/core/geom/vec3/v3_uniform_sample_cone.js +21 -0
  13. package/src/core/math/physics/brdf/cone_cosine_from_roughness.d.ts +13 -0
  14. package/src/core/math/physics/brdf/cone_cosine_from_roughness.d.ts.map +1 -0
  15. package/src/core/math/physics/brdf/cone_cosine_from_roughness.js +28 -0
  16. package/src/core/math/physics/brdf/reflection_sample_weight.d.ts +18 -0
  17. package/src/core/math/physics/brdf/reflection_sample_weight.d.ts.map +1 -0
  18. package/src/core/math/physics/brdf/reflection_sample_weight.js +48 -0
  19. package/src/engine/graphics/GraphicsEngine.d.ts.map +1 -1
  20. package/src/engine/graphics/GraphicsEngine.js +52 -0
  21. package/src/engine/graphics/sh3/sky/hosek/make_environment_sky_hosek.d.ts +26 -0
  22. package/src/engine/graphics/sh3/sky/hosek/make_environment_sky_hosek.d.ts.map +1 -0
  23. package/src/engine/graphics/sh3/sky/hosek/make_environment_sky_hosek.js +49 -0
  24. package/src/engine/graphics/sh3/sky/hosek/render_hosek_sky_to_equirectangular.d.ts +26 -0
  25. package/src/engine/graphics/sh3/sky/hosek/render_hosek_sky_to_equirectangular.d.ts.map +1 -0
  26. package/src/engine/graphics/sh3/sky/hosek/render_hosek_sky_to_equirectangular.js +70 -0
  27. package/src/engine/graphics/sh3/sky/hosek/setup_environment_sky_from_ecd.d.ts +24 -0
  28. package/src/engine/graphics/sh3/sky/hosek/setup_environment_sky_from_ecd.d.ts.map +1 -0
  29. package/src/engine/graphics/sh3/sky/hosek/setup_environment_sky_from_ecd.js +51 -0
  30. package/src/engine/graphics/texture/EnvironmentTextureProjection.d.ts +9 -0
  31. package/src/engine/graphics/texture/EnvironmentTextureProjection.d.ts.map +1 -0
  32. package/src/engine/graphics/texture/EnvironmentTextureProjection.js +15 -0
  33. package/src/engine/graphics/texture/reflection/convolve_equirectangular_reflection.d.ts +44 -0
  34. package/src/engine/graphics/texture/reflection/convolve_equirectangular_reflection.d.ts.map +1 -0
  35. package/src/engine/graphics/texture/reflection/convolve_equirectangular_reflection.js +189 -0
  36. package/src/engine/graphics/texture/reflection/equirectangular_reflection_roughness.d.ts +25 -0
  37. package/src/engine/graphics/texture/reflection/equirectangular_reflection_roughness.d.ts.map +1 -0
  38. package/src/engine/graphics/texture/reflection/equirectangular_reflection_roughness.js +51 -0
  39. package/src/engine/graphics/texture/sampler/sampler2d_sample_equirectangular_direction.d.ts +15 -0
  40. package/src/engine/graphics/texture/sampler/sampler2d_sample_equirectangular_direction.d.ts.map +1 -0
  41. package/src/engine/graphics/texture/sampler/sampler2d_sample_equirectangular_direction.js +63 -0
  42. package/src/engine/navigation/mesh/build/bt_mesh_carve_height_clearance.d.ts +28 -0
  43. package/src/engine/navigation/mesh/build/bt_mesh_carve_height_clearance.d.ts.map +1 -0
  44. package/src/engine/navigation/mesh/build/bt_mesh_carve_height_clearance.js +359 -0
  45. package/src/engine/navigation/mesh/build/navmesh_build_topology.d.ts.map +1 -1
  46. package/src/engine/navigation/mesh/build/navmesh_build_topology.js +224 -226
  47. package/src/engine/.fuse_hidden0000001500000001 +0 -581
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Uniformly sample a direction within a cone around +Z (solid-angle uniform).
3
+ *
4
+ * @param {number[]|Float32Array} out
5
+ * @param {number} out_offset
6
+ * @param {number} u random value in [0, 1] (controls polar angle)
7
+ * @param {number} v random value in [0, 1] (controls azimuth)
8
+ * @param {number} cos_theta_max cosine of the cone half-angle; 1 = a single direction, -1 = full sphere
9
+ */
10
+ export function v3_uniform_sample_cone(out: number[] | Float32Array, out_offset: number, u: number, v: number, cos_theta_max: number): void;
11
+ //# sourceMappingURL=v3_uniform_sample_cone.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"v3_uniform_sample_cone.d.ts","sourceRoot":"","sources":["../../../../../src/core/geom/vec3/v3_uniform_sample_cone.js"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,4CANW,MAAM,EAAE,GAAC,YAAY,cACrB,MAAM,KACN,MAAM,KACN,MAAM,iBACN,MAAM,QAWhB"}
@@ -0,0 +1,21 @@
1
+ const TWO_PI = Math.PI * 2;
2
+
3
+ /**
4
+ * Uniformly sample a direction within a cone around +Z (solid-angle uniform).
5
+ *
6
+ * @param {number[]|Float32Array} out
7
+ * @param {number} out_offset
8
+ * @param {number} u random value in [0, 1] (controls polar angle)
9
+ * @param {number} v random value in [0, 1] (controls azimuth)
10
+ * @param {number} cos_theta_max cosine of the cone half-angle; 1 = a single direction, -1 = full sphere
11
+ */
12
+ export function v3_uniform_sample_cone(out, out_offset, u, v, cos_theta_max) {
13
+ const cos_theta = (1.0 - u) + u * cos_theta_max;
14
+ const sin_theta = Math.sqrt(Math.max(0.0, 1.0 - cos_theta * cos_theta));
15
+
16
+ const phi = v * TWO_PI;
17
+
18
+ out[out_offset] = Math.cos(phi) * sin_theta;
19
+ out[out_offset + 1] = Math.sin(phi) * sin_theta;
20
+ out[out_offset + 2] = cos_theta;
21
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Cosine of the importance-sampling cone aperture (cos of twice the half-angle)
3
+ * for a given perceptual roughness, derived by inverting the spherical-gaussian
4
+ * specular lobe. Roughness 1 maps to roughly a half-pi half-angle.
5
+ *
6
+ * Pairs with {@link reflection_sample_weight}; used to bound the set of sampled
7
+ * directions when convolving an environment map.
8
+ *
9
+ * @param {number} linear_roughness perceptual roughness in [0, 1]
10
+ * @returns {number} cone cosine in [-1, 1]
11
+ */
12
+ export function cone_cosine_from_roughness(linear_roughness: number): number;
13
+ //# sourceMappingURL=cone_cosine_from_roughness.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cone_cosine_from_roughness.d.ts","sourceRoot":"","sources":["../../../../../../src/core/math/physics/brdf/cone_cosine_from_roughness.js"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,6DAHW,MAAM,GACJ,MAAM,CAgBlB"}
@@ -0,0 +1,28 @@
1
+ import { lerp } from "../../lerp.js";
2
+
3
+ /**
4
+ * Cosine of the importance-sampling cone aperture (cos of twice the half-angle)
5
+ * for a given perceptual roughness, derived by inverting the spherical-gaussian
6
+ * specular lobe. Roughness 1 maps to roughly a half-pi half-angle.
7
+ *
8
+ * Pairs with {@link reflection_sample_weight}; used to bound the set of sampled
9
+ * directions when convolving an environment map.
10
+ *
11
+ * @param {number} linear_roughness perceptual roughness in [0, 1]
12
+ * @returns {number} cone cosine in [-1, 1]
13
+ */
14
+ export function cone_cosine_from_roughness(linear_roughness) {
15
+ // From linear roughness to GGX roughness input.
16
+ const m = linear_roughness * linear_roughness;
17
+
18
+ // Chosen so that roughness of 1.0 maps to a half-pi cone aperture.
19
+ const cutoff_value = lerp(0.01, 0.14, m);
20
+
21
+ // Inversion of the spherical gaussian: cutoff for the half angle from N.H.
22
+ const half_angle_cos = Math.log(cutoff_value) * (m * m) * 0.5 + 1.0;
23
+ const half_angle_cos_sqr = half_angle_cos * half_angle_cos;
24
+ const half_angle_sin_sqr = Math.max(0.0, 1.0 - half_angle_cos_sqr);
25
+
26
+ // cos(2 * half_angle) via the cosine double-angle identity.
27
+ return half_angle_cos_sqr - half_angle_sin_sqr;
28
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Spherical-gaussian approximation of the GGX specular weight for a sample,
3
+ * used when convolving an environment map for prefiltered reflections.
4
+ *
5
+ * From "SG Series Part 4: Specular Lighting From an SG Light Source" by MJP.
6
+ * Both directions are assumed unit length.
7
+ *
8
+ * @param {number} out_x reflection (output) direction
9
+ * @param {number} out_y
10
+ * @param {number} out_z
11
+ * @param {number} in_x sampled (input) direction
12
+ * @param {number} in_y
13
+ * @param {number} in_z
14
+ * @param {number} linear_roughness perceptual roughness in [0, 1]
15
+ * @returns {number} non-negative weight
16
+ */
17
+ export function reflection_sample_weight(out_x: number, out_y: number, out_z: number, in_x: number, in_y: number, in_z: number, linear_roughness: number): number;
18
+ //# sourceMappingURL=reflection_sample_weight.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reflection_sample_weight.d.ts","sourceRoot":"","sources":["../../../../../../src/core/math/physics/brdf/reflection_sample_weight.js"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;GAeG;AACH,gDATW,MAAM,SACN,MAAM,SACN,MAAM,QACN,MAAM,QACN,MAAM,QACN,MAAM,oBACN,MAAM,GACJ,MAAM,CA+BlB"}
@@ -0,0 +1,48 @@
1
+ import { clamp01 } from "../../clamp01.js";
2
+
3
+ /**
4
+ * Spherical-gaussian approximation of the GGX specular weight for a sample,
5
+ * used when convolving an environment map for prefiltered reflections.
6
+ *
7
+ * From "SG Series Part 4: Specular Lighting From an SG Light Source" by MJP.
8
+ * Both directions are assumed unit length.
9
+ *
10
+ * @param {number} out_x reflection (output) direction
11
+ * @param {number} out_y
12
+ * @param {number} out_z
13
+ * @param {number} in_x sampled (input) direction
14
+ * @param {number} in_y
15
+ * @param {number} in_z
16
+ * @param {number} linear_roughness perceptual roughness in [0, 1]
17
+ * @returns {number} non-negative weight
18
+ */
19
+ export function reflection_sample_weight(
20
+ out_x, out_y, out_z,
21
+ in_x, in_y, in_z,
22
+ linear_roughness
23
+ ) {
24
+ // From linear roughness to GGX roughness input.
25
+ const m = linear_roughness * linear_roughness;
26
+
27
+ // Half vector H = normalize(out + in)
28
+ let h_x = out_x + in_x;
29
+ let h_y = out_y + in_y;
30
+ let h_z = out_z + in_z;
31
+
32
+ const h_length = Math.sqrt(h_x * h_x + h_y * h_y + h_z * h_z);
33
+
34
+ if (h_length === 0) {
35
+ // out and in are antiparallel; no contribution
36
+ return 0;
37
+ }
38
+
39
+ const inv = 1.0 / h_length;
40
+
41
+ // NH = saturate(dot(N = out, H))
42
+ const NH = clamp01((out_x * h_x + out_y * h_y + out_z * h_z) * inv);
43
+
44
+ const m2 = m * m;
45
+
46
+ // Spherical Gaussian: exp(2 * (NH - 1) / m^2)
47
+ return Math.exp(2.0 * (NH - 1.0) / m2);
48
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"GraphicsEngine.d.ts","sourceRoot":"","sources":["../../../../src/engine/graphics/GraphicsEngine.js"],"names":[],"mappings":"AA4DA;IAOI;;;;;OAKG;IACH,+BAJW,MAAM,EAgLhB;IAtLD,gCAEC;IAgBG;;;;OAIG;IACH,2BAA+C;IAK/C;;;;;QAOI;;WAEG;;QAEH;;WAEG;;;;;MAMN;IAED;;OAEG;IACH,YAFU,OAAO,CAEe;IAEhC;;;;;;OAMG;IACH,4BAFU,OAAO,CAEyB;IAE1C;;;OAGG;IACH,QAFU,kBAAkB,CAEU;IAWtC;;;OAGG;IACH,aAAkB;IAGlB;;;OAGG;IACH,cAFU,KAAK,CAEgB;IAK/B;;;OAGG;IACH,QAFU,MAAM,CAEI;IAEpB;;;OAGG;IACH,UAFU,aAAa,CAEH;IAGpB,+BAA0C;IAU1C;;OAEG;IACH,eAA+B;IAI/B;;;OAGG;IACH,uBAFU,kBAAkB,CAEgB;IAE5C;;;OAGG;IACH,oBAFU,iBAAiB,CAEsB;IAEjD;;;OAGG;IACH,gBAFU,iBAAiB,CAES;IAEpC;;;OAGG;IACH,sBAAoC;IAGpC;;;;OAIG;IACH,UAFU,OAAO,CAEG;IAEpB;;;OAGG;IACH,UAFU,OAAO,CAEG;IAEpB;;;OAGG;IACH,YAFU,MAAM,CAEG;IACnB,kKAcI;IAGR;;;OAGG;IACH,sBAFa,eAAe,CAI3B;IAED;;;OAGG;IACH,eAFa,aAAa,CAIzB;IAED,mBA8BC;IAED;;;;OAIG;IACH,iCAEC;IAED;;;OAGG;IACH,0BAFa,MAAM,CAIlB;IAED,+BAcC;IAED,cAgEC;IAzBsB,8BAA0C;IA2BjE;;;OAGG;IACH,cAFa,MAAM,CAYlB;IAED;;OAEG;IACH,aAQC;IAED;;OAEG;IACH,yBAQC;IAED;;;;;;OAMG;IACH,yBALW,MAAM,KACN,MAAM,6CAMhB;IAED;;;;OAIG;IACH,8BAHW,OAAO,UAAQ,UACf,OAAO,UAAQ,QAczB;IAED;;;;;OAKG;IACH,8BAQC;IAED,0BAEC;IAED;;;OAGG;IACH,4BAFW,cAAc,QA8BxB;IAED;;OAEG;IACH,qBAqBC;IAED;;OAEG;IACH,0BAeC;IAED;;OAEG;IACH,eA8CC;;CACJ;mBA5lBkB,oCAAoC;oBACnC,4BAA4B;wBACxB,4BAA4B;mCAajB,uCAAuC;sBAlBnE,OAAO;uBAaS,wBAAwB;8BAbxC,OAAO;4BAYc,+BAA+B;mCAKxB,uCAAuC;kCAKxC,gCAAgC;kCADhC,oCAAoC;gCAPtC,uCAAuC;+BAKxC,4BAA4B"}
1
+ {"version":3,"file":"GraphicsEngine.d.ts","sourceRoot":"","sources":["../../../../src/engine/graphics/GraphicsEngine.js"],"names":[],"mappings":"AAgEA;IAOI;;;;;OAKG;IACH,+BAJW,MAAM,EAgLhB;IAtLD,gCAEC;IAgBG;;;;OAIG;IACH,2BAA+C;IAK/C;;;;;QAOI;;WAEG;;QAEH;;WAEG;;;;;MAMN;IAED;;OAEG;IACH,YAFU,OAAO,CAEe;IAEhC;;;;;;OAMG;IACH,4BAFU,OAAO,CAEyB;IAE1C;;;OAGG;IACH,QAFU,kBAAkB,CAEU;IAWtC;;;OAGG;IACH,aAAkB;IAGlB;;;OAGG;IACH,cAFU,KAAK,CAEgB;IAK/B;;;OAGG;IACH,QAFU,MAAM,CAEI;IAEpB;;;OAGG;IACH,UAFU,aAAa,CAEH;IAGpB,+BAA0C;IAU1C;;OAEG;IACH,eAA+B;IAI/B;;;OAGG;IACH,uBAFU,kBAAkB,CAEgB;IAE5C;;;OAGG;IACH,oBAFU,iBAAiB,CAEsB;IAEjD;;;OAGG;IACH,gBAFU,iBAAiB,CAES;IAEpC;;;OAGG;IACH,sBAAoC;IAGpC;;;;OAIG;IACH,UAFU,OAAO,CAEG;IAEpB;;;OAGG;IACH,UAFU,OAAO,CAEG;IAEpB;;;OAGG;IACH,YAFU,MAAM,CAEG;IACnB,kKAcI;IAGR;;;OAGG;IACH,sBAFa,eAAe,CAI3B;IAED;;;OAGG;IACH,eAFa,aAAa,CAIzB;IAED;;;;;;;;;;;;;OAaG;IACH,iCAHW,MAAM,OAAO,eACb,4BAA4B,QAkCtC;IAED,mBA8BC;IAED;;;;OAIG;IACH,iCAEC;IAED;;;OAGG;IACH,0BAFa,MAAM,CAIlB;IAED,+BAcC;IAED,cAgEC;IAzBsB,8BAA0C;IA2BjE;;;OAGG;IACH,cAFa,MAAM,CAYlB;IAED;;OAEG;IACH,aAQC;IAED;;OAEG;IACH,yBAQC;IAED;;;;;;OAMG;IACH,yBALW,MAAM,KACN,MAAM,6CAMhB;IAED;;;;OAIG;IACH,8BAHW,OAAO,UAAQ,UACf,OAAO,UAAQ,QAczB;IAED;;;;;OAKG;IACH,8BAQC;IAED,0BAEC;IAED;;;OAGG;IACH,4BAFW,cAAc,QA8BxB;IAED;;OAEG;IACH,qBAqBC;IAED;;OAEG;IACH,0BAeC;IAED;;OAEG;IACH,eA8CC;;CACJ;mBA7oBkB,oCAAoC;oBACnC,4BAA4B;wBACxB,4BAA4B;mCAajB,uCAAuC;sBAlBnE,OAAO;uBAaS,wBAAwB;8BAbxC,OAAO;4BAYc,+BAA+B;mCAKxB,uCAAuC;kCAKxC,gCAAgC;kCADhC,oCAAoC;gCAPtC,uCAAuC;6CAW1B,2CAA2C;+BANzD,4BAA4B"}
@@ -1,7 +1,10 @@
1
1
  import {
2
+ CubeReflectionMapping,
3
+ EquirectangularReflectionMapping,
2
4
  Group,
3
5
  LinearEncoding,
4
6
  NoToneMapping,
7
+ PMREMGenerator,
5
8
  Raycaster as ThreeRaycaster,
6
9
  Scene as ThreeScene,
7
10
  Vector3 as ThreeVector3,
@@ -32,6 +35,7 @@ import { CameraViewManager } from "./render/view/CameraViewManager.js";
32
35
  import { ShadowMapRenderer } from "./shadows/ShadowMapRenderer.js";
33
36
  import { StandardFrameBuffers } from "./StandardFrameBuffers.js";
34
37
  import { three_setSceneAutoUpdate } from "./three/three_setSceneAutoUpdate.js";
38
+ import { EnvironmentTextureProjection } from "./texture/EnvironmentTextureProjection.js";
35
39
 
36
40
  /**
37
41
  *
@@ -261,6 +265,54 @@ export class GraphicsEngine {
261
265
  return this.renderer;
262
266
  }
263
267
 
268
+ /**
269
+ * Set the scene's environment map. The supplied texture is treated as BOTH:
270
+ * - the skybox background (shown directly), and
271
+ * - the image-based-lighting (IBL) source for physically based materials.
272
+ *
273
+ * The texture is run through three.js' PMREMGenerator to produce the
274
+ * prefiltered radiance assigned to `scene.environment`, while the original
275
+ * texture is assigned to `scene.background`.
276
+ *
277
+ * Must be called after the renderer has started up.
278
+ *
279
+ * @param {THREE.Texture} texture environment texture (equirectangular or cube)
280
+ * @param {EnvironmentTextureProjection} [projection=EnvironmentTextureProjection.Equirectangular] how the texture is projected
281
+ */
282
+ set_environment_texture(texture, projection = EnvironmentTextureProjection.Equirectangular) {
283
+ assert.defined(texture, 'texture');
284
+
285
+ const renderer = this.renderer;
286
+
287
+ if (renderer === null || renderer === undefined) {
288
+ throw new Error('GraphicsEngine.set_environment_texture: renderer is not initialized, call after startup');
289
+ }
290
+
291
+ const pmrem = new PMREMGenerator(renderer);
292
+
293
+ let target;
294
+
295
+ if (projection === EnvironmentTextureProjection.Equirectangular) {
296
+ texture.mapping = EquirectangularReflectionMapping;
297
+ target = pmrem.fromEquirectangular(texture);
298
+ } else if (projection === EnvironmentTextureProjection.Cube) {
299
+ texture.mapping = CubeReflectionMapping;
300
+ target = pmrem.fromCubemap(texture);
301
+ } else {
302
+ pmrem.dispose();
303
+ throw new Error(`GraphicsEngine.set_environment_texture: unsupported projection '${projection}'`);
304
+ }
305
+
306
+ pmrem.dispose();
307
+
308
+ const scene = this.scene;
309
+
310
+ // prefiltered radiance used by PBR materials as the IBL source
311
+ scene.environment = target.texture;
312
+ // original texture shown as the skybox
313
+ scene.background = texture;
314
+ }
315
+
264
316
  updateSize() {
265
317
  const size = this.viewport.size;
266
318
 
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Build an environment map from the Hosek sky model as a single equirectangular
3
+ * {@link DataTexture} (three.js' native sky representation,
4
+ * EquirectangularReflectionMapping).
5
+ *
6
+ * This returns the raw (sharp) sky; prefiltering for IBL is done by
7
+ * `GraphicsEngine.set_environment_texture`, which PMREMs it. The texture can be
8
+ * used directly as `scene.background`.
9
+ *
10
+ * @param {object} options
11
+ * @param {number[]|Float32Array} options.sun direction towards the sun (engine frame, +Y up); need not be unit length
12
+ * @param {number} [options.resolution=256] width of the equirectangular map; height is resolution/2
13
+ * @param {number} [options.turbidity=2] atmospheric turbidity, 1..10
14
+ * @param {number} [options.overcast=0] 0 = clear, 1 = fully overcast
15
+ * @param {number[]|Float32Array} [options.albedo=[0,0,0]] linear ground albedo
16
+ * @returns {THREE.DataTexture}
17
+ */
18
+ export function make_environment_sky_hosek({ sun, resolution, turbidity, overcast, albedo }: {
19
+ sun: number[] | Float32Array;
20
+ resolution?: number;
21
+ turbidity?: number;
22
+ overcast?: number;
23
+ albedo?: number[] | Float32Array;
24
+ }): THREE.DataTexture;
25
+ import { DataTexture } from "three";
26
+ //# sourceMappingURL=make_environment_sky_hosek.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"make_environment_sky_hosek.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/sky/hosek/make_environment_sky_hosek.js"],"names":[],"mappings":"AASA;;;;;;;;;;;;;;;;GAgBG;AACH;IAP0C,GAAG,EAAlC,MAAM,EAAE,GAAC,YAAY;IACJ,UAAU,GAA3B,MAAM;IACW,SAAS,GAA1B,MAAM;IACW,QAAQ,GAAzB,MAAM;IAC0B,MAAM,GAAtC,MAAM,EAAE,GAAC,YAAY;IACnB,iBAAiB,CAwB7B;4BA1CM,OAAO"}
@@ -0,0 +1,49 @@
1
+ import {
2
+ DataTexture,
3
+ EquirectangularReflectionMapping,
4
+ FloatType,
5
+ LinearFilter,
6
+ RGBAFormat
7
+ } from "three";
8
+ import { render_hosek_sky_to_equirectangular } from "./render_hosek_sky_to_equirectangular.js";
9
+
10
+ /**
11
+ * Build an environment map from the Hosek sky model as a single equirectangular
12
+ * {@link DataTexture} (three.js' native sky representation,
13
+ * EquirectangularReflectionMapping).
14
+ *
15
+ * This returns the raw (sharp) sky; prefiltering for IBL is done by
16
+ * `GraphicsEngine.set_environment_texture`, which PMREMs it. The texture can be
17
+ * used directly as `scene.background`.
18
+ *
19
+ * @param {object} options
20
+ * @param {number[]|Float32Array} options.sun direction towards the sun (engine frame, +Y up); need not be unit length
21
+ * @param {number} [options.resolution=256] width of the equirectangular map; height is resolution/2
22
+ * @param {number} [options.turbidity=2] atmospheric turbidity, 1..10
23
+ * @param {number} [options.overcast=0] 0 = clear, 1 = fully overcast
24
+ * @param {number[]|Float32Array} [options.albedo=[0,0,0]] linear ground albedo
25
+ * @returns {THREE.DataTexture}
26
+ */
27
+ export function make_environment_sky_hosek(
28
+ {
29
+ sun,
30
+ resolution = 256,
31
+ turbidity = 2,
32
+ overcast = 0,
33
+ albedo = [0, 0, 0]
34
+ }
35
+ ) {
36
+ const width = Math.max(2, resolution | 0);
37
+ const height = Math.max(1, width >> 1);
38
+
39
+ const data = render_hosek_sky_to_equirectangular(sun, width, height, { turbidity, overcast, albedo });
40
+
41
+ const texture = new DataTexture(data, width, height, RGBAFormat, FloatType);
42
+ texture.mapping = EquirectangularReflectionMapping;
43
+ texture.magFilter = LinearFilter;
44
+ texture.minFilter = LinearFilter;
45
+ texture.generateMipmaps = false;
46
+ texture.needsUpdate = true;
47
+
48
+ return texture;
49
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Render the Hosek sky into an equirectangular RGBA float buffer.
3
+ *
4
+ * The layout matches three.js' `equirectUv` (so the result can be used directly
5
+ * as an EquirectangularReflectionMapping texture or fed to PMREMGenerator):
6
+ * u = atan2(z, x) / (2pi) + 0.5
7
+ * v = asin(y) / pi + 0.5
8
+ * with +Y up, matching the engine convention.
9
+ *
10
+ * @param {number[]|Float32Array} sun direction towards the sun (engine frame, +Y up); need not be unit length
11
+ * @param {number} width number of horizontal (longitude) samples
12
+ * @param {number} height number of vertical (latitude) samples
13
+ * @param {object} [options]
14
+ * @param {number} [options.turbidity=2] atmospheric turbidity, 1..10
15
+ * @param {number} [options.overcast=0] 0 = clear, 1 = fully overcast
16
+ * @param {number[]|Float32Array} [options.albedo=[0,0,0]] linear ground albedo
17
+ * @param {Float32Array} [options.target] optional pre-allocated buffer of length width*height*4
18
+ * @returns {Float32Array} RGBA, row 0 = bottom (-Y), length width*height*4
19
+ */
20
+ export function render_hosek_sky_to_equirectangular(sun: number[] | Float32Array, width: number, height: number, options?: {
21
+ turbidity?: number;
22
+ overcast?: number;
23
+ albedo?: number[] | Float32Array;
24
+ target?: Float32Array;
25
+ }): Float32Array;
26
+ //# sourceMappingURL=render_hosek_sky_to_equirectangular.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render_hosek_sky_to_equirectangular.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/sky/hosek/render_hosek_sky_to_equirectangular.js"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;GAkBG;AACH,yDAVW,MAAM,EAAE,GAAC,YAAY,SACrB,MAAM,UACN,MAAM;IAEW,SAAS,GAA1B,MAAM;IACW,QAAQ,GAAzB,MAAM;IAC0B,MAAM,GAAtC,MAAM,EAAE,GAAC,YAAY;IACE,MAAM,GAA7B,YAAY;IACV,YAAY,CAgDxB"}
@@ -0,0 +1,70 @@
1
+ import { make_sky_hosek } from "../../path_tracer/make_sky_hosek.js";
2
+
3
+ const TWO_PI = Math.PI * 2;
4
+
5
+ /**
6
+ * Render the Hosek sky into an equirectangular RGBA float buffer.
7
+ *
8
+ * The layout matches three.js' `equirectUv` (so the result can be used directly
9
+ * as an EquirectangularReflectionMapping texture or fed to PMREMGenerator):
10
+ * u = atan2(z, x) / (2pi) + 0.5
11
+ * v = asin(y) / pi + 0.5
12
+ * with +Y up, matching the engine convention.
13
+ *
14
+ * @param {number[]|Float32Array} sun direction towards the sun (engine frame, +Y up); need not be unit length
15
+ * @param {number} width number of horizontal (longitude) samples
16
+ * @param {number} height number of vertical (latitude) samples
17
+ * @param {object} [options]
18
+ * @param {number} [options.turbidity=2] atmospheric turbidity, 1..10
19
+ * @param {number} [options.overcast=0] 0 = clear, 1 = fully overcast
20
+ * @param {number[]|Float32Array} [options.albedo=[0,0,0]] linear ground albedo
21
+ * @param {Float32Array} [options.target] optional pre-allocated buffer of length width*height*4
22
+ * @returns {Float32Array} RGBA, row 0 = bottom (-Y), length width*height*4
23
+ */
24
+ export function render_hosek_sky_to_equirectangular(sun, width, height, options = {}) {
25
+ const {
26
+ turbidity = 2,
27
+ overcast = 0,
28
+ albedo = [0, 0, 0],
29
+ target
30
+ } = options;
31
+
32
+ const sky = make_sky_hosek(sun, turbidity, overcast, albedo);
33
+
34
+ const data = target !== undefined ? target : new Float32Array(width * height * 4);
35
+
36
+ const direction = [0, 0, 0];
37
+
38
+ let p = 0;
39
+
40
+ for (let j = 0; j < height; j++) {
41
+ const v = (j + 0.5) / height;
42
+
43
+ // v = asin(y)/pi + 0.5 => y = sin((v - 0.5) * pi)
44
+ const latitude = (v - 0.5) * Math.PI;
45
+ const y = Math.sin(latitude);
46
+ const cos_latitude = Math.cos(latitude);
47
+
48
+ for (let i = 0; i < width; i++) {
49
+ const u = (i + 0.5) / width;
50
+
51
+ // u = atan2(z, x)/(2pi) + 0.5 => atan2(z, x) = (u - 0.5) * 2pi
52
+ const longitude = (u - 0.5) * TWO_PI;
53
+
54
+ direction[0] = cos_latitude * Math.cos(longitude);
55
+ direction[1] = y;
56
+ direction[2] = cos_latitude * Math.sin(longitude);
57
+
58
+ const offset = p * 4;
59
+
60
+ // writes linear RGB into data[offset .. offset + 2]
61
+ sky(data, offset, direction, 0);
62
+
63
+ data[offset + 3] = 1;
64
+
65
+ p++;
66
+ }
67
+ }
68
+
69
+ return data;
70
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Build a Hosek sky environment and apply it to a graphics scene, deriving the
3
+ * sun direction from the dataset's directional light.
4
+ *
5
+ * Delegates to {@link GraphicsEngine#set_environment_texture}, which PMREMs the
6
+ * equirectangular sky and assigns it as both the IBL source
7
+ * (`scene.environment`) and the skybox (`scene.background`).
8
+ *
9
+ * @param {GraphicsEngine} graphics
10
+ * @param {EntityComponentDataset} ecd source of the {@link DirectionalLight} that defines the sun
11
+ * @param {object} [options]
12
+ * @param {number} [options.resolution=256] width of the equirectangular map; height is resolution/2
13
+ * @param {number} [options.turbidity=2] atmospheric turbidity, 1..10
14
+ * @param {number} [options.overcast=0] 0 = clear, 1 = fully overcast
15
+ * @param {number[]|Float32Array} [options.albedo=[0,0,0]] linear ground albedo
16
+ * @returns {THREE.DataTexture} the equirectangular sky texture that was applied
17
+ */
18
+ export function setup_environment_sky_from_ecd(graphics: GraphicsEngine, ecd: EntityComponentDataset, options?: {
19
+ resolution?: number;
20
+ turbidity?: number;
21
+ overcast?: number;
22
+ albedo?: number[] | Float32Array;
23
+ }): THREE.DataTexture;
24
+ //# sourceMappingURL=setup_environment_sky_from_ecd.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setup_environment_sky_from_ecd.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/sky/hosek/setup_environment_sky_from_ecd.js"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;GAgBG;AACH;IAN4B,UAAU,GAA3B,MAAM;IACW,SAAS,GAA1B,MAAM;IACW,QAAQ,GAAzB,MAAM;IAC0B,MAAM,GAAtC,MAAM,EAAE,GAAC,YAAY;IACnB,MAAM,WAAW,CA+B7B"}
@@ -0,0 +1,51 @@
1
+ import { DirectionalLight } from "../../../render/forward_plus/model/DirectionalLight.js";
2
+ import { EnvironmentTextureProjection } from "../../../texture/EnvironmentTextureProjection.js";
3
+ import { make_environment_sky_hosek } from "./make_environment_sky_hosek.js";
4
+
5
+ /**
6
+ * Build a Hosek sky environment and apply it to a graphics scene, deriving the
7
+ * sun direction from the dataset's directional light.
8
+ *
9
+ * Delegates to {@link GraphicsEngine#set_environment_texture}, which PMREMs the
10
+ * equirectangular sky and assigns it as both the IBL source
11
+ * (`scene.environment`) and the skybox (`scene.background`).
12
+ *
13
+ * @param {GraphicsEngine} graphics
14
+ * @param {EntityComponentDataset} ecd source of the {@link DirectionalLight} that defines the sun
15
+ * @param {object} [options]
16
+ * @param {number} [options.resolution=256] width of the equirectangular map; height is resolution/2
17
+ * @param {number} [options.turbidity=2] atmospheric turbidity, 1..10
18
+ * @param {number} [options.overcast=0] 0 = clear, 1 = fully overcast
19
+ * @param {number[]|Float32Array} [options.albedo=[0,0,0]] linear ground albedo
20
+ * @returns {THREE.DataTexture} the equirectangular sky texture that was applied
21
+ */
22
+ export function setup_environment_sky_from_ecd(graphics, ecd, options = {}) {
23
+ const {
24
+ resolution = 256,
25
+ turbidity = 2,
26
+ overcast = 0,
27
+ albedo = [0, 0, 0]
28
+ } = options;
29
+
30
+ const { component: light } = ecd.getAnyComponent(DirectionalLight);
31
+
32
+ /**
33
+ * Direction *towards* the sun = negated light travel direction.
34
+ * Falls back to an overhead sun when the dataset has no directional light.
35
+ * @type {number[]}
36
+ */
37
+ let sun;
38
+
39
+ if (light !== null) {
40
+ const d = light.direction;
41
+ sun = [-d.x, -d.y, -d.z];
42
+ } else {
43
+ sun = [0, 1, 0];
44
+ }
45
+
46
+ const texture = make_environment_sky_hosek({ sun, resolution, turbidity, overcast, albedo });
47
+
48
+ graphics.set_environment_texture(texture, EnvironmentTextureProjection.Equirectangular);
49
+
50
+ return texture;
51
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * How an environment-map texture is projected onto the sphere.
3
+ */
4
+ export type EnvironmentTextureProjection = number;
5
+ export namespace EnvironmentTextureProjection {
6
+ let Equirectangular: number;
7
+ let Cube: number;
8
+ }
9
+ //# sourceMappingURL=EnvironmentTextureProjection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EnvironmentTextureProjection.d.ts","sourceRoot":"","sources":["../../../../../src/engine/graphics/texture/EnvironmentTextureProjection.js"],"names":[],"mappings":";;;2CAEU,MAAM"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * How an environment-map texture is projected onto the sphere.
3
+ * @enum {number}
4
+ */
5
+ export const EnvironmentTextureProjection = {
6
+ /**
7
+ * Lat-long / equirectangular projection. This is the default and the
8
+ * representation three.js uses for sky textures.
9
+ */
10
+ Equirectangular: 0,
11
+ /**
12
+ * Cube map (six faces packed as a CubeTexture).
13
+ */
14
+ Cube: 1
15
+ };
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Convolve an equirectangular radiance map for a single output direction,
3
+ * importance-sampling a cone around it with a spherical-gaussian GGX weight.
4
+ * This is the per-texel core of the prefilter (extracted for testing).
5
+ *
6
+ * @param {Sampler2D} input equirectangular radiance (the previous, sharper mip)
7
+ * @param {number} out_x output (reflection) direction, unit length, +Y up
8
+ * @param {number} out_y
9
+ * @param {number} out_z
10
+ * @param {number} roughness perceptual roughness for this convolution step
11
+ * @param {number} sample_count number of cone samples
12
+ * @param {number[]|Float32Array} result
13
+ * @param {number} [result_offset=0]
14
+ */
15
+ export function convolve_equirectangular_reflection_direction(input: Sampler2D, out_x: number, out_y: number, out_z: number, roughness: number, sample_count: number, result: number[] | Float32Array, result_offset?: number): void;
16
+ /**
17
+ * Convolve a whole equirectangular level into `output`.
18
+ *
19
+ * @param {Sampler2D} input source radiance (previous mip)
20
+ * @param {Sampler2D} output destination (this mip)
21
+ * @param {number} roughness convolution roughness for this step
22
+ * @param {number} sample_count
23
+ */
24
+ export function convolve_equirectangular_reflection_level(input: Sampler2D, output: Sampler2D, roughness: number, sample_count: number): void;
25
+ /**
26
+ * Build a prefiltered reflection mip chain from a base equirectangular radiance
27
+ * map. Mip 0 is the (sharp) base; each subsequent mip is half resolution and
28
+ * convolved from the previous one, so roughness increases with mip level. This
29
+ * is the CPU replacement for THREE's PMREMGenerator, decoupled from three.js.
30
+ *
31
+ * @param {Sampler2D} base equirectangular RGBA radiance (mip 0)
32
+ * @param {object} [options]
33
+ * @param {number} [options.sample_count=32] cone samples per texel (the sky is low frequency)
34
+ * @param {number} [options.mip_levels] number of levels; defaults to the full chain
35
+ * @param {number} [options.max_roughness=0.7] roughness reached at the last mip
36
+ * @returns {Sampler2D[]} mip chain, index 0 = base
37
+ */
38
+ export function build_equirectangular_reflection_mip_chain(base: Sampler2D, options?: {
39
+ sample_count?: number;
40
+ mip_levels?: number;
41
+ max_roughness?: number;
42
+ }): Sampler2D[];
43
+ import { Sampler2D } from "../sampler/Sampler2D.js";
44
+ //# sourceMappingURL=convolve_equirectangular_reflection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convolve_equirectangular_reflection.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/texture/reflection/convolve_equirectangular_reflection.js"],"names":[],"mappings":"AAyBA;;;;;;;;;;;;;GAaG;AACH,qEATW,SAAS,SACT,MAAM,SACN,MAAM,SACN,MAAM,aACN,MAAM,gBACN,MAAM,UACN,MAAM,EAAE,GAAC,YAAY,kBACrB,MAAM,QAiEhB;AAED;;;;;;;GAOG;AACH,iEALW,SAAS,UACT,SAAS,aACT,MAAM,gBACN,MAAM,QA6BhB;AAED;;;;;;;;;;;;GAYG;AACH,iEAPW,SAAS;IAEQ,YAAY,GAA7B,MAAM;IACW,UAAU,GAA3B,MAAM;IACW,aAAa,GAA9B,MAAM;IACJ,SAAS,EAAE,CAoCvB;0BArLyB,yBAAyB"}