@luma.gl/shadertools 9.1.0-beta.8 → 9.2.0-alpha.1

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 (150) hide show
  1. package/dist/dist.dev.js +426 -2497
  2. package/dist/dist.min.js +215 -419
  3. package/dist/index.cjs +297 -728
  4. package/dist/index.cjs.map +4 -4
  5. package/dist/index.d.ts +0 -6
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +0 -10
  8. package/dist/index.js.map +1 -1
  9. package/dist/lib/shader-assembly/assemble-shaders.d.ts +6 -4
  10. package/dist/lib/shader-assembly/assemble-shaders.d.ts.map +1 -1
  11. package/dist/lib/shader-assembly/assemble-shaders.js.map +1 -1
  12. package/dist/lib/shader-assembly/platform-info.d.ts +1 -1
  13. package/dist/lib/shader-assembly/platform-info.d.ts.map +1 -1
  14. package/dist/lib/shader-module/shader-module.d.ts +1 -1
  15. package/dist/lib/shader-module/shader-module.d.ts.map +1 -1
  16. package/dist/modules/lighting/gouraud-material/gouraud-material.js +1 -1
  17. package/dist/modules/lighting/gouraud-material/gouraud-material.js.map +1 -1
  18. package/dist/modules/lighting/lights/{lighting-uniforms-glsl.d.ts → lighting-glsl.d.ts} +1 -1
  19. package/dist/modules/lighting/lights/lighting-glsl.d.ts.map +1 -0
  20. package/dist/modules/lighting/lights/{lighting-uniforms-glsl.js → lighting-glsl.js} +1 -1
  21. package/dist/modules/lighting/lights/lighting-glsl.js.map +1 -0
  22. package/dist/modules/lighting/lights/{lighting-uniforms-wgsl.d.ts → lighting-wgsl.d.ts} +1 -1
  23. package/dist/modules/lighting/lights/lighting-wgsl.d.ts.map +1 -0
  24. package/dist/modules/lighting/lights/{lighting-uniforms-wgsl.js → lighting-wgsl.js} +1 -1
  25. package/dist/modules/lighting/lights/lighting-wgsl.js.map +1 -0
  26. package/dist/modules/lighting/lights/lighting.d.ts +1 -3
  27. package/dist/modules/lighting/lights/lighting.d.ts.map +1 -1
  28. package/dist/modules/lighting/lights/lighting.js +4 -4
  29. package/dist/modules/lighting/lights/lighting.js.map +1 -1
  30. package/dist/modules/lighting/pbr-material/{pbr-fragment-glsl.d.ts → pbr-material-glsl.d.ts} +2 -1
  31. package/dist/modules/lighting/pbr-material/pbr-material-glsl.d.ts.map +1 -0
  32. package/dist/modules/lighting/pbr-material/{pbr-fragment-glsl.js → pbr-material-glsl.js} +36 -1
  33. package/dist/modules/lighting/pbr-material/pbr-material-glsl.js.map +1 -0
  34. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.d.ts +3 -0
  35. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.d.ts.map +1 -0
  36. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js +489 -0
  37. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js.map +1 -0
  38. package/dist/modules/lighting/pbr-material/pbr-material.d.ts +11 -4
  39. package/dist/modules/lighting/pbr-material/pbr-material.d.ts.map +1 -1
  40. package/dist/modules/lighting/pbr-material/pbr-material.js +12 -12
  41. package/dist/modules/lighting/pbr-material/pbr-material.js.map +1 -1
  42. package/dist/modules/lighting/phong-material/phong-material.js +1 -1
  43. package/dist/modules/lighting/phong-material/phong-material.js.map +1 -1
  44. package/dist/modules/math/random/random.d.ts +1 -0
  45. package/dist/modules/math/random/random.d.ts.map +1 -1
  46. package/dist/modules/math/random/random.js +7 -0
  47. package/dist/modules/math/random/random.js.map +1 -1
  48. package/package.json +3 -3
  49. package/src/index.ts +0 -17
  50. package/src/lib/shader-assembly/assemble-shaders.ts +8 -7
  51. package/src/lib/shader-assembly/platform-info.ts +1 -1
  52. package/src/lib/shader-module/shader-module.ts +1 -1
  53. package/src/lib/wgsl/get-shader-layout-wgsl.ts +2 -2
  54. package/src/modules/lighting/gouraud-material/gouraud-material.ts +1 -1
  55. package/src/modules/lighting/lights/lighting.ts +4 -4
  56. package/src/modules/lighting/pbr-material/{pbr-fragment-glsl.ts → pbr-material-glsl.ts} +36 -1
  57. package/src/modules/lighting/pbr-material/pbr-material-wgsl.ts +492 -0
  58. package/src/modules/lighting/pbr-material/pbr-material.ts +12 -12
  59. package/src/modules/lighting/phong-material/phong-material.ts +1 -1
  60. package/src/modules/math/random/random.ts +8 -0
  61. package/dist/modules/lighting/lights/lighting-uniforms-glsl.d.ts.map +0 -1
  62. package/dist/modules/lighting/lights/lighting-uniforms-glsl.js.map +0 -1
  63. package/dist/modules/lighting/lights/lighting-uniforms-wgsl.d.ts.map +0 -1
  64. package/dist/modules/lighting/lights/lighting-uniforms-wgsl.js.map +0 -1
  65. package/dist/modules/lighting/pbr-material/pbr-fragment-glsl.d.ts.map +0 -1
  66. package/dist/modules/lighting/pbr-material/pbr-fragment-glsl.js.map +0 -1
  67. package/dist/modules/lighting/pbr-material/pbr-uniforms-glsl.d.ts +0 -2
  68. package/dist/modules/lighting/pbr-material/pbr-uniforms-glsl.d.ts.map +0 -1
  69. package/dist/modules/lighting/pbr-material/pbr-uniforms-glsl.js +0 -67
  70. package/dist/modules/lighting/pbr-material/pbr-uniforms-glsl.js.map +0 -1
  71. package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.d.ts +0 -2
  72. package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.d.ts.map +0 -1
  73. package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.js +0 -39
  74. package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.js.map +0 -1
  75. package/dist/modules/module-injectors.d.ts +0 -3
  76. package/dist/modules/module-injectors.d.ts.map +0 -1
  77. package/dist/modules/module-injectors.js +0 -31
  78. package/dist/modules/module-injectors.js.map +0 -1
  79. package/dist/modules-webgl1/geometry/geometry.d.ts +0 -9
  80. package/dist/modules-webgl1/geometry/geometry.d.ts.map +0 -1
  81. package/dist/modules-webgl1/geometry/geometry.js +0 -39
  82. package/dist/modules-webgl1/geometry/geometry.js.map +0 -1
  83. package/dist/modules-webgl1/lighting/dirlight/dirlight.d.ts +0 -10
  84. package/dist/modules-webgl1/lighting/dirlight/dirlight.d.ts.map +0 -1
  85. package/dist/modules-webgl1/lighting/dirlight/dirlight.js +0 -38
  86. package/dist/modules-webgl1/lighting/dirlight/dirlight.js.map +0 -1
  87. package/dist/modules-webgl1/lighting/lights/lights-glsl.d.ts +0 -2
  88. package/dist/modules-webgl1/lighting/lights/lights-glsl.d.ts.map +0 -1
  89. package/dist/modules-webgl1/lighting/lights/lights-glsl.js +0 -40
  90. package/dist/modules-webgl1/lighting/lights/lights-glsl.js.map +0 -1
  91. package/dist/modules-webgl1/lighting/lights/lights.d.ts +0 -38
  92. package/dist/modules-webgl1/lighting/lights/lights.d.ts.map +0 -1
  93. package/dist/modules-webgl1/lighting/lights/lights.js +0 -93
  94. package/dist/modules-webgl1/lighting/lights/lights.js.map +0 -1
  95. package/dist/modules-webgl1/lighting/pbr/pbr-fragment-glsl.d.ts +0 -2
  96. package/dist/modules-webgl1/lighting/pbr/pbr-fragment-glsl.d.ts.map +0 -1
  97. package/dist/modules-webgl1/lighting/pbr/pbr-fragment-glsl.js +0 -393
  98. package/dist/modules-webgl1/lighting/pbr/pbr-fragment-glsl.js.map +0 -1
  99. package/dist/modules-webgl1/lighting/pbr/pbr-vertex-glsl.d.ts +0 -2
  100. package/dist/modules-webgl1/lighting/pbr/pbr-vertex-glsl.d.ts.map +0 -1
  101. package/dist/modules-webgl1/lighting/pbr/pbr-vertex-glsl.js +0 -43
  102. package/dist/modules-webgl1/lighting/pbr/pbr-vertex-glsl.js.map +0 -1
  103. package/dist/modules-webgl1/lighting/pbr/pbr.d.ts +0 -23
  104. package/dist/modules-webgl1/lighting/pbr/pbr.d.ts.map +0 -1
  105. package/dist/modules-webgl1/lighting/pbr/pbr.js +0 -21
  106. package/dist/modules-webgl1/lighting/pbr/pbr.js.map +0 -1
  107. package/dist/modules-webgl1/lighting/phong-lighting/phong-lighting-glsl.d.ts +0 -2
  108. package/dist/modules-webgl1/lighting/phong-lighting/phong-lighting-glsl.d.ts.map +0 -1
  109. package/dist/modules-webgl1/lighting/phong-lighting/phong-lighting-glsl.js +0 -79
  110. package/dist/modules-webgl1/lighting/phong-lighting/phong-lighting-glsl.js.map +0 -1
  111. package/dist/modules-webgl1/lighting/phong-lighting/phong-lighting.d.ts +0 -45
  112. package/dist/modules-webgl1/lighting/phong-lighting/phong-lighting.d.ts.map +0 -1
  113. package/dist/modules-webgl1/lighting/phong-lighting/phong-lighting.js +0 -44
  114. package/dist/modules-webgl1/lighting/phong-lighting/phong-lighting.js.map +0 -1
  115. package/dist/modules-webgl1/math/fp64/fp64-arithmetic-glsl.d.ts +0 -2
  116. package/dist/modules-webgl1/math/fp64/fp64-arithmetic-glsl.d.ts.map +0 -1
  117. package/dist/modules-webgl1/math/fp64/fp64-arithmetic-glsl.js +0 -171
  118. package/dist/modules-webgl1/math/fp64/fp64-arithmetic-glsl.js.map +0 -1
  119. package/dist/modules-webgl1/math/fp64/fp64-functions-glsl.d.ts +0 -2
  120. package/dist/modules-webgl1/math/fp64/fp64-functions-glsl.d.ts.map +0 -1
  121. package/dist/modules-webgl1/math/fp64/fp64-functions-glsl.js +0 -675
  122. package/dist/modules-webgl1/math/fp64/fp64-functions-glsl.js.map +0 -1
  123. package/dist/modules-webgl1/math/fp64/fp64.d.ts +0 -35
  124. package/dist/modules-webgl1/math/fp64/fp64.d.ts.map +0 -1
  125. package/dist/modules-webgl1/math/fp64/fp64.js +0 -38
  126. package/dist/modules-webgl1/math/fp64/fp64.js.map +0 -1
  127. package/dist/modules-webgl1/project/project.d.ts +0 -20
  128. package/dist/modules-webgl1/project/project.d.ts.map +0 -1
  129. package/dist/modules-webgl1/project/project.js +0 -114
  130. package/dist/modules-webgl1/project/project.js.map +0 -1
  131. package/src/modules/lighting/pbr-material/pbr-uniforms-glsl.ts +0 -67
  132. package/src/modules/lighting/pbr-material/pbr-vertex-glsl.ts +0 -39
  133. package/src/modules/module-injectors.ts +0 -32
  134. package/src/modules-webgl1/geometry/geometry.ts +0 -41
  135. package/src/modules-webgl1/lighting/dirlight/dirlight.ts +0 -50
  136. package/src/modules-webgl1/lighting/lights/lights-glsl.ts +0 -40
  137. package/src/modules-webgl1/lighting/lights/lights.ts +0 -143
  138. package/src/modules-webgl1/lighting/pbr/README.md +0 -12
  139. package/src/modules-webgl1/lighting/pbr/pbr-fragment-glsl.ts +0 -396
  140. package/src/modules-webgl1/lighting/pbr/pbr-vertex-glsl.ts +0 -43
  141. package/src/modules-webgl1/lighting/pbr/pbr.ts +0 -23
  142. package/src/modules-webgl1/lighting/phong-lighting/phong-lighting-glsl.ts +0 -79
  143. package/src/modules-webgl1/lighting/phong-lighting/phong-lighting.ts +0 -64
  144. package/src/modules-webgl1/math/fp64/fp64-arithmetic-glsl.ts +0 -171
  145. package/src/modules-webgl1/math/fp64/fp64-functions-glsl.ts +0 -675
  146. package/src/modules-webgl1/math/fp64/fp64.ts +0 -44
  147. package/src/modules-webgl1/project/README.md +0 -52
  148. package/src/modules-webgl1/project/project.ts +0 -135
  149. /package/src/modules/lighting/lights/{lighting-uniforms-glsl.ts → lighting-glsl.ts} +0 -0
  150. /package/src/modules/lighting/lights/{lighting-uniforms-wgsl.ts → lighting-wgsl.ts} +0 -0
package/dist/dist.dev.js CHANGED
@@ -62,7 +62,6 @@ var __exports__ = (() => {
62
62
  combineInjects: () => combineInjects,
63
63
  convertToVec4: () => convertToVec4,
64
64
  dirlight: () => dirlight,
65
- dirlight1: () => dirlight2,
66
65
  fp32: () => fp32,
67
66
  fp64: () => fp64,
68
67
  fp64LowPart: () => fp64LowPart,
@@ -71,7 +70,6 @@ var __exports__ = (() => {
71
70
  fp64ifyMatrix4: () => fp64ifyMatrix4,
72
71
  fromHalfFloat: () => fromHalfFloat,
73
72
  generateShaderForModule: () => generateShaderForModule,
74
- geometry1: () => geometry,
75
73
  getPassthroughFS: () => getPassthroughFS,
76
74
  getQualifierDetails: () => getQualifierDetails,
77
75
  getShaderInfo: () => getShaderInfo,
@@ -79,19 +77,14 @@ var __exports__ = (() => {
79
77
  getShaderModuleDependencies: () => getShaderModuleDependencies,
80
78
  getShaderModuleSource: () => getShaderModuleSource,
81
79
  getShaderModuleUniforms: () => getShaderModuleUniforms,
82
- gouraudLighting: () => gouraudLighting,
83
80
  gouraudMaterial: () => gouraudMaterial,
84
81
  initializeShaderModule: () => initializeShaderModule,
85
82
  initializeShaderModules: () => initializeShaderModules,
86
83
  lighting: () => lighting,
87
- lights1: () => lights,
88
- pbr: () => pbr,
89
84
  pbrMaterial: () => pbrMaterial,
90
- phongLighting: () => phongLighting,
91
85
  phongMaterial: () => phongMaterial,
92
86
  picking: () => picking,
93
87
  preprocess: () => preprocess,
94
- project1: () => project,
95
88
  random: () => random,
96
89
  toHalfFloat: () => toHalfFloat,
97
90
  typeToChannelCount: () => typeToChannelCount,
@@ -240,7 +233,7 @@ var __exports__ = (() => {
240
233
  throw new Error(type);
241
234
  }
242
235
  }
243
- function injectShader(source, stage, inject, injectStandardStubs = false) {
236
+ function injectShader(source3, stage, inject, injectStandardStubs = false) {
244
237
  const isVertex = stage === "vertex";
245
238
  for (const key in inject) {
246
239
  const fragmentData = inject[key];
@@ -254,43 +247,43 @@ var __exports__ = (() => {
254
247
  switch (key) {
255
248
  case "vs:#decl":
256
249
  if (isVertex) {
257
- source = source.replace(DECLARATION_INJECT_MARKER, fragmentString);
250
+ source3 = source3.replace(DECLARATION_INJECT_MARKER, fragmentString);
258
251
  }
259
252
  break;
260
253
  case "vs:#main-start":
261
254
  if (isVertex) {
262
- source = source.replace(REGEX_START_OF_MAIN, (match) => match + fragmentString);
255
+ source3 = source3.replace(REGEX_START_OF_MAIN, (match) => match + fragmentString);
263
256
  }
264
257
  break;
265
258
  case "vs:#main-end":
266
259
  if (isVertex) {
267
- source = source.replace(REGEX_END_OF_MAIN, (match) => fragmentString + match);
260
+ source3 = source3.replace(REGEX_END_OF_MAIN, (match) => fragmentString + match);
268
261
  }
269
262
  break;
270
263
  case "fs:#decl":
271
264
  if (!isVertex) {
272
- source = source.replace(DECLARATION_INJECT_MARKER, fragmentString);
265
+ source3 = source3.replace(DECLARATION_INJECT_MARKER, fragmentString);
273
266
  }
274
267
  break;
275
268
  case "fs:#main-start":
276
269
  if (!isVertex) {
277
- source = source.replace(REGEX_START_OF_MAIN, (match) => match + fragmentString);
270
+ source3 = source3.replace(REGEX_START_OF_MAIN, (match) => match + fragmentString);
278
271
  }
279
272
  break;
280
273
  case "fs:#main-end":
281
274
  if (!isVertex) {
282
- source = source.replace(REGEX_END_OF_MAIN, (match) => fragmentString + match);
275
+ source3 = source3.replace(REGEX_END_OF_MAIN, (match) => fragmentString + match);
283
276
  }
284
277
  break;
285
278
  default:
286
- source = source.replace(key, (match) => match + fragmentString);
279
+ source3 = source3.replace(key, (match) => match + fragmentString);
287
280
  }
288
281
  }
289
- source = source.replace(DECLARATION_INJECT_MARKER, "");
282
+ source3 = source3.replace(DECLARATION_INJECT_MARKER, "");
290
283
  if (injectStandardStubs) {
291
- source = source.replace(/\}\s*$/, (match) => match + MODULE_INJECTORS[stage]);
284
+ source3 = source3.replace(/\}\s*$/, (match) => match + MODULE_INJECTORS[stage]);
292
285
  }
293
- return source;
286
+ return source3;
294
287
  }
295
288
  function combineInjects(injects) {
296
289
  const result = {};
@@ -470,18 +463,18 @@ ${inject[key]}` : inject[key];
470
463
  }
471
464
 
472
465
  // src/lib/shader-transpiler/transpile-glsl-shader.ts
473
- function transpileGLSLShader(source, stage) {
474
- const sourceGLSLVersion = Number(source.match(/^#version[ \t]+(\d+)/m)?.[1] || 100);
466
+ function transpileGLSLShader(source3, stage) {
467
+ const sourceGLSLVersion = Number(source3.match(/^#version[ \t]+(\d+)/m)?.[1] || 100);
475
468
  if (sourceGLSLVersion !== 300) {
476
469
  throw new Error("luma.gl v9 only supports GLSL 3.00 shader sources");
477
470
  }
478
471
  switch (stage) {
479
472
  case "vertex":
480
- source = convertShader(source, ES300_VERTEX_REPLACEMENTS);
481
- return source;
473
+ source3 = convertShader(source3, ES300_VERTEX_REPLACEMENTS);
474
+ return source3;
482
475
  case "fragment":
483
- source = convertShader(source, ES300_FRAGMENT_REPLACEMENTS);
484
- return source;
476
+ source3 = convertShader(source3, ES300_FRAGMENT_REPLACEMENTS);
477
+ return source3;
485
478
  default:
486
479
  throw new Error(stage);
487
480
  }
@@ -505,11 +498,11 @@ ${inject[key]}` : inject[key];
505
498
  // `varying` keyword replaced with `in`
506
499
  [makeVariableTextRegExp("varying"), "in $1"]
507
500
  ];
508
- function convertShader(source, replacements) {
501
+ function convertShader(source3, replacements) {
509
502
  for (const [pattern, replacement] of replacements) {
510
- source = source.replace(pattern, replacement);
503
+ source3 = source3.replace(pattern, replacement);
511
504
  }
512
- return source;
505
+ return source3;
513
506
  }
514
507
  function makeVariableTextRegExp(qualifier) {
515
508
  return new RegExp(`\\b${qualifier}[ \\t]+(\\w+[ \\t]+\\w+(\\[\\w+\\])?;)`, "g");
@@ -571,11 +564,11 @@ ${inject[key]}` : inject[key];
571
564
  }
572
565
 
573
566
  // src/lib/glsl-utils/get-shader-info.ts
574
- function getShaderInfo(source, defaultName) {
567
+ function getShaderInfo(source3, defaultName) {
575
568
  return {
576
- name: getShaderName(source, defaultName),
569
+ name: getShaderName(source3, defaultName),
577
570
  language: "glsl",
578
- version: getShaderVersion(source)
571
+ version: getShaderVersion(source3)
579
572
  };
580
573
  }
581
574
  function getShaderName(shader, defaultName = "unnamed") {
@@ -583,9 +576,9 @@ ${inject[key]}` : inject[key];
583
576
  const match = SHADER_NAME_REGEXP.exec(shader);
584
577
  return match ? match[1] : defaultName;
585
578
  }
586
- function getShaderVersion(source) {
579
+ function getShaderVersion(source3) {
587
580
  let version = 100;
588
- const words = source.match(/[^\s]+/g);
581
+ const words = source3.match(/[^\s]+/g);
589
582
  if (words && words.length >= 2 && words[0] === "#version") {
590
583
  const parsedVersion = parseInt(words[1], 10);
591
584
  if (Number.isFinite(parsedVersion)) {
@@ -621,19 +614,19 @@ ${DECLARATION_INJECT_MARKER}
621
614
  };
622
615
  }
623
616
  function assembleGLSLShaderPair(options) {
624
- const { vs: vs6, fs: fs8 } = options;
617
+ const { vs: vs3, fs: fs4 } = options;
625
618
  const modules = getShaderModuleDependencies(options.modules || []);
626
619
  return {
627
620
  vs: assembleShaderGLSL(options.platformInfo, {
628
621
  ...options,
629
- source: vs6,
622
+ source: vs3,
630
623
  stage: "vertex",
631
624
  modules
632
625
  }),
633
626
  fs: assembleShaderGLSL(options.platformInfo, {
634
627
  ...options,
635
628
  // @ts-expect-error
636
- source: fs8,
629
+ source: fs4,
637
630
  stage: "fragment",
638
631
  modules
639
632
  }),
@@ -643,7 +636,7 @@ ${DECLARATION_INJECT_MARKER}
643
636
  function assembleShaderWGSL(platformInfo, options) {
644
637
  const {
645
638
  // id,
646
- source,
639
+ source: source3,
647
640
  stage,
648
641
  modules,
649
642
  // defines = {},
@@ -651,8 +644,8 @@ ${DECLARATION_INJECT_MARKER}
651
644
  inject = {},
652
645
  log: log3
653
646
  } = options;
654
- assert(typeof source === "string", "shader source must be a string");
655
- const coreSource = source;
647
+ assert(typeof source3 === "string", "shader source must be a string");
648
+ const coreSource = source3;
656
649
  let assembledSource = "";
657
650
  const hookFunctionMap = normalizeShaderHooks(hookFunctions);
658
651
  const hookInjections = {};
@@ -707,7 +700,7 @@ ${DECLARATION_INJECT_MARKER}
707
700
  }
708
701
  function assembleShaderGLSL(platformInfo, options) {
709
702
  const {
710
- source,
703
+ source: source3,
711
704
  stage,
712
705
  language = "glsl",
713
706
  modules,
@@ -717,11 +710,11 @@ ${DECLARATION_INJECT_MARKER}
717
710
  prologue = true,
718
711
  log: log3
719
712
  } = options;
720
- assert(typeof source === "string", "shader source must be a string");
721
- const sourceVersion = language === "glsl" ? getShaderInfo(source).version : -1;
713
+ assert(typeof source3 === "string", "shader source must be a string");
714
+ const sourceVersion = language === "glsl" ? getShaderInfo(source3).version : -1;
722
715
  const targetVersion = platformInfo.shaderLanguageVersion;
723
716
  const sourceVersionDirective = sourceVersion === 100 ? "#version 100" : "#version 300 es";
724
- const sourceLines = source.split("\n");
717
+ const sourceLines = source3.split("\n");
725
718
  const coreSource = sourceLines.slice(1).join("\n");
726
719
  const allDefines = {};
727
720
  modules.forEach((module) => {
@@ -804,7 +797,7 @@ ${getApplicationDefines(allDefines)}
804
797
  return assembledSource.trim();
805
798
  }
806
799
  function assembleGetUniforms(modules) {
807
- return function getUniforms8(opts) {
800
+ return function getUniforms4(opts) {
808
801
  const uniforms = {};
809
802
  for (const module of modules) {
810
803
  const moduleUniforms = module.getUniforms?.(opts, uniforms);
@@ -843,23 +836,23 @@ ${getApplicationDefines(allDefines)}
843
836
  throw new Error("Shader module must have a name");
844
837
  }
845
838
  const moduleName = module.name.toUpperCase().replace(/[^0-9a-z]/gi, "_");
846
- let source = `// ----- MODULE ${module.name} ---------------
839
+ let source3 = `// ----- MODULE ${module.name} ---------------
847
840
 
848
841
  `;
849
842
  if (stage !== "wgsl") {
850
- source += `#define MODULE_${moduleName}
843
+ source3 += `#define MODULE_${moduleName}
851
844
  `;
852
845
  }
853
- source += `${moduleSource}
846
+ source3 += `${moduleSource}
854
847
  `;
855
- return source;
848
+ return source3;
856
849
  }
857
850
 
858
851
  // src/lib/preprocessor/preprocessor.ts
859
852
  var IFDEF_REGEXP = /^\s*\#\s*ifdef\s*([a-zA-Z_]+)\s*$/;
860
853
  var ENDIF_REGEXP = /^\s*\#\s*endif\s*$/;
861
- function preprocess(source, options) {
862
- const lines = source.split("\n");
854
+ function preprocess(source3, options) {
855
+ const lines = source3.split("\n");
863
856
  const output = [];
864
857
  let conditional = true;
865
858
  let currentDefine = null;
@@ -929,15 +922,15 @@ ${getApplicationDefines(allDefines)}
929
922
  assembleWGSLShader(props) {
930
923
  const modules = this._getModuleList(props.modules);
931
924
  const hookFunctions = this._hookFunctions;
932
- const { source, getUniforms: getUniforms8 } = assembleWGSLShader({
925
+ const { source: source3, getUniforms: getUniforms4 } = assembleWGSLShader({
933
926
  ...props,
934
927
  // @ts-expect-error
935
928
  source: props.source,
936
929
  modules,
937
930
  hookFunctions
938
931
  });
939
- const preprocessedSource = props.platformInfo.shaderLanguage === "wgsl" ? preprocess(source) : source;
940
- return { source: preprocessedSource, getUniforms: getUniforms8, modules };
932
+ const preprocessedSource = props.platformInfo.shaderLanguage === "wgsl" ? preprocess(source3) : source3;
933
+ return { source: preprocessedSource, getUniforms: getUniforms4, modules };
941
934
  }
942
935
  /**
943
936
  * Assemble a pair of shaders into a single shader program
@@ -2496,12 +2489,12 @@ void main() {
2496
2489
  }
2497
2490
  };
2498
2491
  var WgslScanner = class {
2499
- constructor(source) {
2492
+ constructor(source3) {
2500
2493
  this._tokens = [];
2501
2494
  this._start = 0;
2502
2495
  this._current = 0;
2503
2496
  this._line = 1;
2504
- this._source = source !== null && source !== void 0 ? source : "";
2497
+ this._source = source3 !== null && source3 !== void 0 ? source3 : "";
2505
2498
  }
2506
2499
  /// Scan all tokens from the source.
2507
2500
  scanTokens() {
@@ -2591,10 +2584,33 @@ void main() {
2591
2584
  for (; ; ) {
2592
2585
  let matchedType = this._findType(lexeme);
2593
2586
  const nextLexeme = this._peekAhead();
2587
+ if (lexeme == "-" && this._tokens.length > 0) {
2588
+ if (nextLexeme == "=") {
2589
+ this._current++;
2590
+ lexeme += nextLexeme;
2591
+ this._addToken(TokenTypes.tokens.minus_equal);
2592
+ return true;
2593
+ }
2594
+ if (nextLexeme == "-") {
2595
+ this._current++;
2596
+ lexeme += nextLexeme;
2597
+ this._addToken(TokenTypes.tokens.minus_minus);
2598
+ return true;
2599
+ }
2600
+ const ti = this._tokens.length - 1;
2601
+ const isIdentOrLiteral = TokenTypes.literal_or_ident.indexOf(this._tokens[ti].type) != -1;
2602
+ if ((isIdentOrLiteral || this._tokens[ti].type == TokenTypes.tokens.paren_right) && nextLexeme != ">") {
2603
+ this._addToken(matchedType);
2604
+ return true;
2605
+ }
2606
+ }
2594
2607
  if (lexeme == ">" && (nextLexeme == ">" || nextLexeme == "=")) {
2595
2608
  let foundLessThan = false;
2596
2609
  let ti = this._tokens.length - 1;
2597
2610
  for (let count = 0; count < 5 && ti >= 0; ++count, --ti) {
2611
+ if (TokenTypes.assignment_operators.indexOf(this._tokens[ti].type) !== -1) {
2612
+ break;
2613
+ }
2598
2614
  if (this._tokens[ti].type === TokenTypes.tokens.less_than) {
2599
2615
  if (ti > 0 && this._tokens[ti - 1].isArrayOrTemplateType()) {
2600
2616
  foundLessThan = true;
@@ -4469,7 +4485,7 @@ void main() {
4469
4485
  struct.align = structAlign;
4470
4486
  }
4471
4487
  _getTypeSize(type) {
4472
- var _a2;
4488
+ var _a2, _b;
4473
4489
  if (type === null || type === void 0) {
4474
4490
  return null;
4475
4491
  }
@@ -4487,7 +4503,7 @@ void main() {
4487
4503
  {
4488
4504
  const info = WgslReflect._typeInfo[type.name];
4489
4505
  if (info !== void 0) {
4490
- const divisor = type["format"] === "f16" ? 2 : 1;
4506
+ const divisor = ((_a2 = type["format"]) === null || _a2 === void 0 ? void 0 : _a2.name) === "f16" ? 2 : 1;
4491
4507
  return new _TypeSize(Math.max(explicitAlign, info.align / divisor), Math.max(explicitSize, info.size / divisor));
4492
4508
  }
4493
4509
  }
@@ -4508,7 +4524,7 @@ void main() {
4508
4524
  align = E.align;
4509
4525
  }
4510
4526
  const N = arrayType.count;
4511
- const stride = this._getAttributeNum((_a2 = type === null || type === void 0 ? void 0 : type.attributes) !== null && _a2 !== void 0 ? _a2 : null, "stride", this._roundUp(align, size));
4527
+ const stride = this._getAttributeNum((_b = type === null || type === void 0 ? void 0 : type.attributes) !== null && _b !== void 0 ? _b : null, "stride", this._roundUp(align, size));
4512
4528
  size = N * stride;
4513
4529
  if (explicitSize) {
4514
4530
  size = explicitSize;
@@ -4612,11 +4628,11 @@ void main() {
4612
4628
  });
4613
4629
 
4614
4630
  // src/lib/wgsl/get-shader-layout-wgsl.ts
4615
- function getShaderLayoutFromWGSL(source) {
4631
+ function getShaderLayoutFromWGSL(source3) {
4616
4632
  const shaderLayout = { attributes: [], bindings: [] };
4617
4633
  let parsedWGSL;
4618
4634
  try {
4619
- parsedWGSL = parseWGSL(source);
4635
+ parsedWGSL = parseWGSL(source3);
4620
4636
  } catch (error) {
4621
4637
  import_core.log.error(error.message)();
4622
4638
  return shaderLayout;
@@ -4672,9 +4688,9 @@ void main() {
4672
4688
  function getType(type) {
4673
4689
  return type.format ? `${type.name}<${type.format.name}>` : type.name;
4674
4690
  }
4675
- function parseWGSL(source) {
4691
+ function parseWGSL(source3) {
4676
4692
  try {
4677
- return new WgslReflect(source);
4693
+ return new WgslReflect(source3);
4678
4694
  } catch (error) {
4679
4695
  if (error instanceof Error) {
4680
4696
  throw error;
@@ -4704,53 +4720,12 @@ void main() {
4704
4720
  };
4705
4721
  globalThis.mathgl = globalThis.mathgl || { config: { ...DEFAULT_CONFIG } };
4706
4722
  var config = globalThis.mathgl.config;
4707
- function formatValue(value, { precision = config.precision } = {}) {
4708
- value = round(value);
4709
- return `${parseFloat(value.toPrecision(precision))}`;
4710
- }
4711
4723
  function isArray(value) {
4712
4724
  return Array.isArray(value) || ArrayBuffer.isView(value) && !(value instanceof DataView);
4713
4725
  }
4714
4726
  function clamp(value, min, max) {
4715
4727
  return map(value, (value2) => Math.max(min, Math.min(max, value2)));
4716
4728
  }
4717
- function equals(a, b, epsilon) {
4718
- const oldEpsilon = config.EPSILON;
4719
- if (epsilon) {
4720
- config.EPSILON = epsilon;
4721
- }
4722
- try {
4723
- if (a === b) {
4724
- return true;
4725
- }
4726
- if (isArray(a) && isArray(b)) {
4727
- if (a.length !== b.length) {
4728
- return false;
4729
- }
4730
- for (let i = 0; i < a.length; ++i) {
4731
- if (!equals(a[i], b[i])) {
4732
- return false;
4733
- }
4734
- }
4735
- return true;
4736
- }
4737
- if (a && a.equals) {
4738
- return a.equals(b);
4739
- }
4740
- if (b && b.equals) {
4741
- return b.equals(a);
4742
- }
4743
- if (typeof a === "number" && typeof b === "number") {
4744
- return Math.abs(a - b) <= config.EPSILON * Math.max(1, Math.abs(a), Math.abs(b));
4745
- }
4746
- return false;
4747
- } finally {
4748
- config.EPSILON = oldEpsilon;
4749
- }
4750
- }
4751
- function round(value) {
4752
- return Math.round(value / config.EPSILON) * config.EPSILON;
4753
- }
4754
4729
  function duplicateArray(array) {
4755
4730
  return array.clone ? array.clone() : new Array(array.length);
4756
4731
  }
@@ -4767,1739 +4742,134 @@ void main() {
4767
4742
  return func(value);
4768
4743
  }
4769
4744
 
4770
- // ../../node_modules/@math.gl/core/dist/classes/base/math-array.js
4771
- var MathArray = class extends Array {
4772
- // Common methods
4773
- /**
4774
- * Clone the current object
4775
- * @returns a new copy of this object
4776
- */
4777
- clone() {
4778
- return new this.constructor().copy(this);
4779
- }
4780
- fromArray(array, offset = 0) {
4781
- for (let i = 0; i < this.ELEMENTS; ++i) {
4782
- this[i] = array[i + offset];
4783
- }
4784
- return this.check();
4785
- }
4786
- toArray(targetArray = [], offset = 0) {
4787
- for (let i = 0; i < this.ELEMENTS; ++i) {
4788
- targetArray[offset + i] = this[i];
4789
- }
4790
- return targetArray;
4791
- }
4792
- toObject(targetObject) {
4793
- return targetObject;
4794
- }
4795
- from(arrayOrObject) {
4796
- return Array.isArray(arrayOrObject) ? this.copy(arrayOrObject) : (
4797
- // @ts-ignore
4798
- this.fromObject(arrayOrObject)
4799
- );
4800
- }
4801
- to(arrayOrObject) {
4802
- if (arrayOrObject === this) {
4803
- return this;
4804
- }
4805
- return isArray(arrayOrObject) ? this.toArray(arrayOrObject) : this.toObject(arrayOrObject);
4806
- }
4807
- toTarget(target) {
4808
- return target ? this.to(target) : this;
4809
- }
4810
- /** @deprecated */
4811
- toFloat32Array() {
4812
- return new Float32Array(this);
4813
- }
4814
- toString() {
4815
- return this.formatString(config);
4816
- }
4817
- /** Formats string according to options */
4818
- formatString(opts) {
4819
- let string = "";
4820
- for (let i = 0; i < this.ELEMENTS; ++i) {
4821
- string += (i > 0 ? ", " : "") + formatValue(this[i], opts);
4822
- }
4823
- return `${opts.printTypes ? this.constructor.name : ""}[${string}]`;
4824
- }
4825
- equals(array) {
4826
- if (!array || this.length !== array.length) {
4827
- return false;
4828
- }
4829
- for (let i = 0; i < this.ELEMENTS; ++i) {
4830
- if (!equals(this[i], array[i])) {
4831
- return false;
4832
- }
4833
- }
4834
- return true;
4835
- }
4836
- exactEquals(array) {
4837
- if (!array || this.length !== array.length) {
4838
- return false;
4839
- }
4840
- for (let i = 0; i < this.ELEMENTS; ++i) {
4841
- if (this[i] !== array[i]) {
4842
- return false;
4843
- }
4844
- }
4845
- return true;
4846
- }
4847
- // Modifiers
4848
- /** Negates all values in this object */
4849
- negate() {
4850
- for (let i = 0; i < this.ELEMENTS; ++i) {
4851
- this[i] = -this[i];
4852
- }
4853
- return this.check();
4854
- }
4855
- lerp(a, b, t) {
4856
- if (t === void 0) {
4857
- return this.lerp(this, a, b);
4858
- }
4859
- for (let i = 0; i < this.ELEMENTS; ++i) {
4860
- const ai = a[i];
4861
- const endValue = typeof b === "number" ? b : b[i];
4862
- this[i] = ai + t * (endValue - ai);
4863
- }
4864
- return this.check();
4865
- }
4866
- /** Minimal */
4867
- min(vector) {
4868
- for (let i = 0; i < this.ELEMENTS; ++i) {
4869
- this[i] = Math.min(vector[i], this[i]);
4870
- }
4871
- return this.check();
4872
- }
4873
- /** Maximal */
4874
- max(vector) {
4875
- for (let i = 0; i < this.ELEMENTS; ++i) {
4876
- this[i] = Math.max(vector[i], this[i]);
4877
- }
4878
- return this.check();
4879
- }
4880
- clamp(minVector, maxVector) {
4881
- for (let i = 0; i < this.ELEMENTS; ++i) {
4882
- this[i] = Math.min(Math.max(this[i], minVector[i]), maxVector[i]);
4883
- }
4884
- return this.check();
4885
- }
4886
- add(...vectors) {
4887
- for (const vector of vectors) {
4888
- for (let i = 0; i < this.ELEMENTS; ++i) {
4889
- this[i] += vector[i];
4890
- }
4891
- }
4892
- return this.check();
4893
- }
4894
- subtract(...vectors) {
4895
- for (const vector of vectors) {
4896
- for (let i = 0; i < this.ELEMENTS; ++i) {
4897
- this[i] -= vector[i];
4898
- }
4899
- }
4900
- return this.check();
4901
- }
4902
- scale(scale2) {
4903
- if (typeof scale2 === "number") {
4904
- for (let i = 0; i < this.ELEMENTS; ++i) {
4905
- this[i] *= scale2;
4906
- }
4745
+ // src/modules/math/fp16/fp16-utils.ts
4746
+ var float16Tables = null;
4747
+ var buffer = new ArrayBuffer(4);
4748
+ var floatView = new Float32Array(buffer);
4749
+ var uint32View = new Uint32Array(buffer);
4750
+ function toHalfFloat(val) {
4751
+ float16Tables ||= generateFloat16Tables();
4752
+ val = clamp(val, -65504, 65504);
4753
+ floatView[0] = val;
4754
+ const f = uint32View[0];
4755
+ const e = f >> 23 & 511;
4756
+ return float16Tables.baseTable[e] + ((f & 8388607) >> float16Tables.shiftTable[e]);
4757
+ }
4758
+ function fromHalfFloat(val) {
4759
+ float16Tables ||= generateFloat16Tables();
4760
+ const m = val >> 10;
4761
+ uint32View[0] = float16Tables.mantissaTable[float16Tables.offsetTable[m] + (val & 1023)] + float16Tables.exponentTable[m];
4762
+ return floatView[0];
4763
+ }
4764
+ function generateFloat16Tables() {
4765
+ const baseTable = new Uint32Array(512);
4766
+ const shiftTable = new Uint32Array(512);
4767
+ for (let i = 0; i < 256; ++i) {
4768
+ const e = i - 127;
4769
+ if (e < -27) {
4770
+ baseTable[i] = 0;
4771
+ baseTable[i | 256] = 32768;
4772
+ shiftTable[i] = 24;
4773
+ shiftTable[i | 256] = 24;
4774
+ } else if (e < -14) {
4775
+ baseTable[i] = 1024 >> -e - 14;
4776
+ baseTable[i | 256] = 1024 >> -e - 14 | 32768;
4777
+ shiftTable[i] = -e - 1;
4778
+ shiftTable[i | 256] = -e - 1;
4779
+ } else if (e <= 15) {
4780
+ baseTable[i] = e + 15 << 10;
4781
+ baseTable[i | 256] = e + 15 << 10 | 32768;
4782
+ shiftTable[i] = 13;
4783
+ shiftTable[i | 256] = 13;
4784
+ } else if (e < 128) {
4785
+ baseTable[i] = 31744;
4786
+ baseTable[i | 256] = 64512;
4787
+ shiftTable[i] = 24;
4788
+ shiftTable[i | 256] = 24;
4907
4789
  } else {
4908
- for (let i = 0; i < this.ELEMENTS && i < scale2.length; ++i) {
4909
- this[i] *= scale2[i];
4910
- }
4911
- }
4912
- return this.check();
4913
- }
4914
- /**
4915
- * Multiplies all elements by `scale`
4916
- * Note: `Matrix4.multiplyByScalar` only scales its 3x3 "minor"
4917
- */
4918
- multiplyByScalar(scalar) {
4919
- for (let i = 0; i < this.ELEMENTS; ++i) {
4920
- this[i] *= scalar;
4921
- }
4922
- return this.check();
4923
- }
4924
- // Debug checks
4925
- /** Throws an error if array length is incorrect or contains illegal values */
4926
- check() {
4927
- if (config.debug && !this.validate()) {
4928
- throw new Error(`math.gl: ${this.constructor.name} some fields set to invalid numbers'`);
4929
- }
4930
- return this;
4931
- }
4932
- /** Returns false if the array length is incorrect or contains illegal values */
4933
- validate() {
4934
- let valid = this.length === this.ELEMENTS;
4935
- for (let i = 0; i < this.ELEMENTS; ++i) {
4936
- valid = valid && Number.isFinite(this[i]);
4937
- }
4938
- return valid;
4939
- }
4940
- // three.js compatibility
4941
- /** @deprecated */
4942
- sub(a) {
4943
- return this.subtract(a);
4944
- }
4945
- /** @deprecated */
4946
- setScalar(a) {
4947
- for (let i = 0; i < this.ELEMENTS; ++i) {
4948
- this[i] = a;
4949
- }
4950
- return this.check();
4951
- }
4952
- /** @deprecated */
4953
- addScalar(a) {
4954
- for (let i = 0; i < this.ELEMENTS; ++i) {
4955
- this[i] += a;
4790
+ baseTable[i] = 31744;
4791
+ baseTable[i | 256] = 64512;
4792
+ shiftTable[i] = 13;
4793
+ shiftTable[i | 256] = 13;
4956
4794
  }
4957
- return this.check();
4958
- }
4959
- /** @deprecated */
4960
- subScalar(a) {
4961
- return this.addScalar(-a);
4962
4795
  }
4963
- /** @deprecated */
4964
- multiplyScalar(scalar) {
4965
- for (let i = 0; i < this.ELEMENTS; ++i) {
4966
- this[i] *= scalar;
4796
+ const mantissaTable = new Uint32Array(2048);
4797
+ const exponentTable = new Uint32Array(64);
4798
+ const offsetTable = new Uint32Array(64);
4799
+ for (let i = 1; i < 1024; ++i) {
4800
+ let m = i << 13;
4801
+ let e = 0;
4802
+ while ((m & 8388608) === 0) {
4803
+ m <<= 1;
4804
+ e -= 8388608;
4967
4805
  }
4968
- return this.check();
4969
- }
4970
- /** @deprecated */
4971
- divideScalar(a) {
4972
- return this.multiplyByScalar(1 / a);
4806
+ m &= ~8388608;
4807
+ e += 947912704;
4808
+ mantissaTable[i] = m | e;
4973
4809
  }
4974
- /** @deprecated */
4975
- clampScalar(min, max) {
4976
- for (let i = 0; i < this.ELEMENTS; ++i) {
4977
- this[i] = Math.min(Math.max(this[i], min), max);
4978
- }
4979
- return this.check();
4810
+ for (let i = 1024; i < 2048; ++i) {
4811
+ mantissaTable[i] = 939524096 + (i - 1024 << 13);
4980
4812
  }
4981
- /** @deprecated */
4982
- get elements() {
4983
- return this;
4813
+ for (let i = 1; i < 31; ++i) {
4814
+ exponentTable[i] = i << 23;
4984
4815
  }
4985
- };
4986
-
4987
- // ../../node_modules/@math.gl/core/dist/lib/validators.js
4988
- function validateVector(v, length) {
4989
- if (v.length !== length) {
4990
- return false;
4816
+ exponentTable[31] = 1199570944;
4817
+ exponentTable[32] = 2147483648;
4818
+ for (let i = 33; i < 63; ++i) {
4819
+ exponentTable[i] = 2147483648 + (i - 32 << 23);
4991
4820
  }
4992
- for (let i = 0; i < v.length; ++i) {
4993
- if (!Number.isFinite(v[i])) {
4994
- return false;
4821
+ exponentTable[63] = 3347054592;
4822
+ for (let i = 1; i < 64; ++i) {
4823
+ if (i !== 32) {
4824
+ offsetTable[i] = 1024;
4995
4825
  }
4996
4826
  }
4997
- return true;
4998
- }
4999
- function checkNumber(value) {
5000
- if (!Number.isFinite(value)) {
5001
- throw new Error(`Invalid number ${JSON.stringify(value)}`);
5002
- }
5003
- return value;
5004
- }
5005
- function checkVector(v, length, callerName = "") {
5006
- if (config.debug && !validateVector(v, length)) {
5007
- throw new Error(`math.gl: ${callerName} some fields set to invalid numbers'`);
5008
- }
5009
- return v;
4827
+ return { baseTable, shiftTable, mantissaTable, exponentTable, offsetTable };
5010
4828
  }
5011
4829
 
5012
- // ../../node_modules/@math.gl/core/dist/gl-matrix/common.js
5013
- var EPSILON = 1e-6;
5014
- var ARRAY_TYPE = typeof Float32Array !== "undefined" ? Float32Array : Array;
5015
- var degree = Math.PI / 180;
5016
-
5017
- // ../../node_modules/@math.gl/core/dist/gl-matrix/vec2.js
5018
- function create() {
5019
- const out = new ARRAY_TYPE(2);
5020
- if (ARRAY_TYPE != Float32Array) {
5021
- out[0] = 0;
5022
- out[1] = 0;
5023
- }
4830
+ // src/modules/math/fp64/fp64-utils.ts
4831
+ function fp64ify(a, out = [], startIndex = 0) {
4832
+ const hiPart = Math.fround(a);
4833
+ const loPart = a - hiPart;
4834
+ out[startIndex] = hiPart;
4835
+ out[startIndex + 1] = loPart;
5024
4836
  return out;
5025
4837
  }
5026
- function transformMat4(out, a, m) {
5027
- const x = a[0];
5028
- const y = a[1];
5029
- out[0] = m[0] * x + m[4] * y + m[12];
5030
- out[1] = m[1] * x + m[5] * y + m[13];
5031
- return out;
4838
+ function fp64LowPart(a) {
4839
+ return a - Math.fround(a);
5032
4840
  }
5033
- var forEach = function() {
5034
- const vec = create();
5035
- return function(a, stride, offset, count, fn, arg) {
5036
- let i;
5037
- let l;
5038
- if (!stride) {
5039
- stride = 2;
5040
- }
5041
- if (!offset) {
5042
- offset = 0;
5043
- }
5044
- if (count) {
5045
- l = Math.min(count * stride + offset, a.length);
5046
- } else {
5047
- l = a.length;
5048
- }
5049
- for (i = offset; i < l; i += stride) {
5050
- vec[0] = a[i];
5051
- vec[1] = a[i + 1];
5052
- fn(vec, vec, arg);
5053
- a[i] = vec[0];
5054
- a[i + 1] = vec[1];
4841
+ function fp64ifyMatrix4(matrix) {
4842
+ const matrixFP64 = new Float32Array(32);
4843
+ for (let i = 0; i < 4; ++i) {
4844
+ for (let j = 0; j < 4; ++j) {
4845
+ const index = i * 4 + j;
4846
+ fp64ify(matrix[j * 4 + i], matrixFP64, index * 2);
5055
4847
  }
5056
- return a;
5057
- };
5058
- }();
5059
-
5060
- // ../../node_modules/@math.gl/core/dist/lib/gl-matrix-extras.js
5061
- function vec2_transformMat4AsVector(out, a, m) {
5062
- const x = a[0];
5063
- const y = a[1];
5064
- const w = m[3] * x + m[7] * y || 1;
5065
- out[0] = (m[0] * x + m[4] * y) / w;
5066
- out[1] = (m[1] * x + m[5] * y) / w;
5067
- return out;
5068
- }
5069
- function vec3_transformMat4AsVector(out, a, m) {
5070
- const x = a[0];
5071
- const y = a[1];
5072
- const z = a[2];
5073
- const w = m[3] * x + m[7] * y + m[11] * z || 1;
5074
- out[0] = (m[0] * x + m[4] * y + m[8] * z) / w;
5075
- out[1] = (m[1] * x + m[5] * y + m[9] * z) / w;
5076
- out[2] = (m[2] * x + m[6] * y + m[10] * z) / w;
5077
- return out;
5078
- }
5079
-
5080
- // ../../node_modules/@math.gl/core/dist/gl-matrix/vec3.js
5081
- function create2() {
5082
- const out = new ARRAY_TYPE(3);
5083
- if (ARRAY_TYPE != Float32Array) {
5084
- out[0] = 0;
5085
- out[1] = 0;
5086
- out[2] = 0;
5087
4848
  }
5088
- return out;
5089
- }
5090
- function transformMat42(out, a, m) {
5091
- const x = a[0];
5092
- const y = a[1];
5093
- const z = a[2];
5094
- let w = m[3] * x + m[7] * y + m[11] * z + m[15];
5095
- w = w || 1;
5096
- out[0] = (m[0] * x + m[4] * y + m[8] * z + m[12]) / w;
5097
- out[1] = (m[1] * x + m[5] * y + m[9] * z + m[13]) / w;
5098
- out[2] = (m[2] * x + m[6] * y + m[10] * z + m[14]) / w;
5099
- return out;
4849
+ return matrixFP64;
5100
4850
  }
5101
- var forEach2 = function() {
5102
- const vec = create2();
5103
- return function(a, stride, offset, count, fn, arg) {
5104
- let i;
5105
- let l;
5106
- if (!stride) {
5107
- stride = 3;
5108
- }
5109
- if (!offset) {
5110
- offset = 0;
5111
- }
5112
- if (count) {
5113
- l = Math.min(count * stride + offset, a.length);
5114
- } else {
5115
- l = a.length;
5116
- }
5117
- for (i = offset; i < l; i += stride) {
5118
- vec[0] = a[i];
5119
- vec[1] = a[i + 1];
5120
- vec[2] = a[i + 2];
5121
- fn(vec, vec, arg);
5122
- a[i] = vec[0];
5123
- a[i + 1] = vec[1];
5124
- a[i + 2] = vec[2];
5125
- }
5126
- return a;
5127
- };
5128
- }();
5129
-
5130
- // ../../node_modules/@math.gl/core/dist/classes/base/matrix.js
5131
- var Matrix = class extends MathArray {
5132
- // fromObject(object) {
5133
- // const array = object.elements;
5134
- // return this.fromRowMajor(array);
5135
- // }
5136
- // toObject(object) {
5137
- // const array = object.elements;
5138
- // this.toRowMajor(array);
5139
- // return object;
5140
- // }
5141
- // TODO better override formatString?
5142
- toString() {
5143
- let string = "[";
5144
- if (config.printRowMajor) {
5145
- string += "row-major:";
5146
- for (let row = 0; row < this.RANK; ++row) {
5147
- for (let col = 0; col < this.RANK; ++col) {
5148
- string += ` ${this[col * this.RANK + row]}`;
5149
- }
5150
- }
5151
- } else {
5152
- string += "column-major:";
5153
- for (let i = 0; i < this.ELEMENTS; ++i) {
5154
- string += ` ${this[i]}`;
5155
- }
5156
- }
5157
- string += "]";
5158
- return string;
5159
- }
5160
- getElementIndex(row, col) {
5161
- return col * this.RANK + row;
5162
- }
5163
- // By default assumes row major indices
5164
- getElement(row, col) {
5165
- return this[col * this.RANK + row];
5166
- }
5167
- // By default assumes row major indices
5168
- setElement(row, col, value) {
5169
- this[col * this.RANK + row] = checkNumber(value);
5170
- return this;
5171
- }
5172
- getColumn(columnIndex, result = new Array(this.RANK).fill(-0)) {
5173
- const firstIndex = columnIndex * this.RANK;
5174
- for (let i = 0; i < this.RANK; ++i) {
5175
- result[i] = this[firstIndex + i];
5176
- }
5177
- return result;
5178
- }
5179
- setColumn(columnIndex, columnVector) {
5180
- const firstIndex = columnIndex * this.RANK;
5181
- for (let i = 0; i < this.RANK; ++i) {
5182
- this[firstIndex + i] = columnVector[i];
5183
- }
5184
- return this;
5185
- }
5186
- };
5187
-
5188
- // ../../node_modules/@math.gl/core/dist/gl-matrix/mat4.js
5189
- function identity(out) {
5190
- out[0] = 1;
5191
- out[1] = 0;
5192
- out[2] = 0;
5193
- out[3] = 0;
5194
- out[4] = 0;
5195
- out[5] = 1;
5196
- out[6] = 0;
5197
- out[7] = 0;
5198
- out[8] = 0;
5199
- out[9] = 0;
5200
- out[10] = 1;
5201
- out[11] = 0;
5202
- out[12] = 0;
5203
- out[13] = 0;
5204
- out[14] = 0;
5205
- out[15] = 1;
5206
- return out;
5207
- }
5208
- function transpose(out, a) {
5209
- if (out === a) {
5210
- const a01 = a[1];
5211
- const a02 = a[2];
5212
- const a03 = a[3];
5213
- const a12 = a[6];
5214
- const a13 = a[7];
5215
- const a23 = a[11];
5216
- out[1] = a[4];
5217
- out[2] = a[8];
5218
- out[3] = a[12];
5219
- out[4] = a01;
5220
- out[6] = a[9];
5221
- out[7] = a[13];
5222
- out[8] = a02;
5223
- out[9] = a12;
5224
- out[11] = a[14];
5225
- out[12] = a03;
5226
- out[13] = a13;
5227
- out[14] = a23;
5228
- } else {
5229
- out[0] = a[0];
5230
- out[1] = a[4];
5231
- out[2] = a[8];
5232
- out[3] = a[12];
5233
- out[4] = a[1];
5234
- out[5] = a[5];
5235
- out[6] = a[9];
5236
- out[7] = a[13];
5237
- out[8] = a[2];
5238
- out[9] = a[6];
5239
- out[10] = a[10];
5240
- out[11] = a[14];
5241
- out[12] = a[3];
5242
- out[13] = a[7];
5243
- out[14] = a[11];
5244
- out[15] = a[15];
5245
- }
5246
- return out;
5247
- }
5248
- function invert(out, a) {
5249
- const a00 = a[0];
5250
- const a01 = a[1];
5251
- const a02 = a[2];
5252
- const a03 = a[3];
5253
- const a10 = a[4];
5254
- const a11 = a[5];
5255
- const a12 = a[6];
5256
- const a13 = a[7];
5257
- const a20 = a[8];
5258
- const a21 = a[9];
5259
- const a22 = a[10];
5260
- const a23 = a[11];
5261
- const a30 = a[12];
5262
- const a31 = a[13];
5263
- const a32 = a[14];
5264
- const a33 = a[15];
5265
- const b00 = a00 * a11 - a01 * a10;
5266
- const b01 = a00 * a12 - a02 * a10;
5267
- const b02 = a00 * a13 - a03 * a10;
5268
- const b03 = a01 * a12 - a02 * a11;
5269
- const b04 = a01 * a13 - a03 * a11;
5270
- const b05 = a02 * a13 - a03 * a12;
5271
- const b06 = a20 * a31 - a21 * a30;
5272
- const b07 = a20 * a32 - a22 * a30;
5273
- const b08 = a20 * a33 - a23 * a30;
5274
- const b09 = a21 * a32 - a22 * a31;
5275
- const b10 = a21 * a33 - a23 * a31;
5276
- const b11 = a22 * a33 - a23 * a32;
5277
- let det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
5278
- if (!det) {
5279
- return null;
5280
- }
5281
- det = 1 / det;
5282
- out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;
5283
- out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det;
5284
- out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det;
5285
- out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det;
5286
- out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det;
5287
- out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det;
5288
- out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det;
5289
- out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det;
5290
- out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det;
5291
- out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det;
5292
- out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det;
5293
- out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det;
5294
- out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det;
5295
- out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det;
5296
- out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det;
5297
- out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;
5298
- return out;
5299
- }
5300
- function determinant(a) {
5301
- const a00 = a[0];
5302
- const a01 = a[1];
5303
- const a02 = a[2];
5304
- const a03 = a[3];
5305
- const a10 = a[4];
5306
- const a11 = a[5];
5307
- const a12 = a[6];
5308
- const a13 = a[7];
5309
- const a20 = a[8];
5310
- const a21 = a[9];
5311
- const a22 = a[10];
5312
- const a23 = a[11];
5313
- const a30 = a[12];
5314
- const a31 = a[13];
5315
- const a32 = a[14];
5316
- const a33 = a[15];
5317
- const b0 = a00 * a11 - a01 * a10;
5318
- const b1 = a00 * a12 - a02 * a10;
5319
- const b2 = a01 * a12 - a02 * a11;
5320
- const b3 = a20 * a31 - a21 * a30;
5321
- const b4 = a20 * a32 - a22 * a30;
5322
- const b5 = a21 * a32 - a22 * a31;
5323
- const b6 = a00 * b5 - a01 * b4 + a02 * b3;
5324
- const b7 = a10 * b5 - a11 * b4 + a12 * b3;
5325
- const b8 = a20 * b2 - a21 * b1 + a22 * b0;
5326
- const b9 = a30 * b2 - a31 * b1 + a32 * b0;
5327
- return a13 * b6 - a03 * b7 + a33 * b8 - a23 * b9;
5328
- }
5329
- function multiply(out, a, b) {
5330
- const a00 = a[0];
5331
- const a01 = a[1];
5332
- const a02 = a[2];
5333
- const a03 = a[3];
5334
- const a10 = a[4];
5335
- const a11 = a[5];
5336
- const a12 = a[6];
5337
- const a13 = a[7];
5338
- const a20 = a[8];
5339
- const a21 = a[9];
5340
- const a22 = a[10];
5341
- const a23 = a[11];
5342
- const a30 = a[12];
5343
- const a31 = a[13];
5344
- const a32 = a[14];
5345
- const a33 = a[15];
5346
- let b0 = b[0];
5347
- let b1 = b[1];
5348
- let b2 = b[2];
5349
- let b3 = b[3];
5350
- out[0] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
5351
- out[1] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
5352
- out[2] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
5353
- out[3] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
5354
- b0 = b[4];
5355
- b1 = b[5];
5356
- b2 = b[6];
5357
- b3 = b[7];
5358
- out[4] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
5359
- out[5] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
5360
- out[6] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
5361
- out[7] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
5362
- b0 = b[8];
5363
- b1 = b[9];
5364
- b2 = b[10];
5365
- b3 = b[11];
5366
- out[8] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
5367
- out[9] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
5368
- out[10] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
5369
- out[11] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
5370
- b0 = b[12];
5371
- b1 = b[13];
5372
- b2 = b[14];
5373
- b3 = b[15];
5374
- out[12] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
5375
- out[13] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
5376
- out[14] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
5377
- out[15] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
5378
- return out;
5379
- }
5380
- function translate(out, a, v) {
5381
- const x = v[0];
5382
- const y = v[1];
5383
- const z = v[2];
5384
- let a00;
5385
- let a01;
5386
- let a02;
5387
- let a03;
5388
- let a10;
5389
- let a11;
5390
- let a12;
5391
- let a13;
5392
- let a20;
5393
- let a21;
5394
- let a22;
5395
- let a23;
5396
- if (a === out) {
5397
- out[12] = a[0] * x + a[4] * y + a[8] * z + a[12];
5398
- out[13] = a[1] * x + a[5] * y + a[9] * z + a[13];
5399
- out[14] = a[2] * x + a[6] * y + a[10] * z + a[14];
5400
- out[15] = a[3] * x + a[7] * y + a[11] * z + a[15];
5401
- } else {
5402
- a00 = a[0];
5403
- a01 = a[1];
5404
- a02 = a[2];
5405
- a03 = a[3];
5406
- a10 = a[4];
5407
- a11 = a[5];
5408
- a12 = a[6];
5409
- a13 = a[7];
5410
- a20 = a[8];
5411
- a21 = a[9];
5412
- a22 = a[10];
5413
- a23 = a[11];
5414
- out[0] = a00;
5415
- out[1] = a01;
5416
- out[2] = a02;
5417
- out[3] = a03;
5418
- out[4] = a10;
5419
- out[5] = a11;
5420
- out[6] = a12;
5421
- out[7] = a13;
5422
- out[8] = a20;
5423
- out[9] = a21;
5424
- out[10] = a22;
5425
- out[11] = a23;
5426
- out[12] = a00 * x + a10 * y + a20 * z + a[12];
5427
- out[13] = a01 * x + a11 * y + a21 * z + a[13];
5428
- out[14] = a02 * x + a12 * y + a22 * z + a[14];
5429
- out[15] = a03 * x + a13 * y + a23 * z + a[15];
5430
- }
5431
- return out;
5432
- }
5433
- function scale(out, a, v) {
5434
- const x = v[0];
5435
- const y = v[1];
5436
- const z = v[2];
5437
- out[0] = a[0] * x;
5438
- out[1] = a[1] * x;
5439
- out[2] = a[2] * x;
5440
- out[3] = a[3] * x;
5441
- out[4] = a[4] * y;
5442
- out[5] = a[5] * y;
5443
- out[6] = a[6] * y;
5444
- out[7] = a[7] * y;
5445
- out[8] = a[8] * z;
5446
- out[9] = a[9] * z;
5447
- out[10] = a[10] * z;
5448
- out[11] = a[11] * z;
5449
- out[12] = a[12];
5450
- out[13] = a[13];
5451
- out[14] = a[14];
5452
- out[15] = a[15];
5453
- return out;
5454
- }
5455
- function rotate(out, a, rad, axis) {
5456
- let x = axis[0];
5457
- let y = axis[1];
5458
- let z = axis[2];
5459
- let len = Math.sqrt(x * x + y * y + z * z);
5460
- let c;
5461
- let s;
5462
- let t;
5463
- let a00;
5464
- let a01;
5465
- let a02;
5466
- let a03;
5467
- let a10;
5468
- let a11;
5469
- let a12;
5470
- let a13;
5471
- let a20;
5472
- let a21;
5473
- let a22;
5474
- let a23;
5475
- let b00;
5476
- let b01;
5477
- let b02;
5478
- let b10;
5479
- let b11;
5480
- let b12;
5481
- let b20;
5482
- let b21;
5483
- let b22;
5484
- if (len < EPSILON) {
5485
- return null;
5486
- }
5487
- len = 1 / len;
5488
- x *= len;
5489
- y *= len;
5490
- z *= len;
5491
- s = Math.sin(rad);
5492
- c = Math.cos(rad);
5493
- t = 1 - c;
5494
- a00 = a[0];
5495
- a01 = a[1];
5496
- a02 = a[2];
5497
- a03 = a[3];
5498
- a10 = a[4];
5499
- a11 = a[5];
5500
- a12 = a[6];
5501
- a13 = a[7];
5502
- a20 = a[8];
5503
- a21 = a[9];
5504
- a22 = a[10];
5505
- a23 = a[11];
5506
- b00 = x * x * t + c;
5507
- b01 = y * x * t + z * s;
5508
- b02 = z * x * t - y * s;
5509
- b10 = x * y * t - z * s;
5510
- b11 = y * y * t + c;
5511
- b12 = z * y * t + x * s;
5512
- b20 = x * z * t + y * s;
5513
- b21 = y * z * t - x * s;
5514
- b22 = z * z * t + c;
5515
- out[0] = a00 * b00 + a10 * b01 + a20 * b02;
5516
- out[1] = a01 * b00 + a11 * b01 + a21 * b02;
5517
- out[2] = a02 * b00 + a12 * b01 + a22 * b02;
5518
- out[3] = a03 * b00 + a13 * b01 + a23 * b02;
5519
- out[4] = a00 * b10 + a10 * b11 + a20 * b12;
5520
- out[5] = a01 * b10 + a11 * b11 + a21 * b12;
5521
- out[6] = a02 * b10 + a12 * b11 + a22 * b12;
5522
- out[7] = a03 * b10 + a13 * b11 + a23 * b12;
5523
- out[8] = a00 * b20 + a10 * b21 + a20 * b22;
5524
- out[9] = a01 * b20 + a11 * b21 + a21 * b22;
5525
- out[10] = a02 * b20 + a12 * b21 + a22 * b22;
5526
- out[11] = a03 * b20 + a13 * b21 + a23 * b22;
5527
- if (a !== out) {
5528
- out[12] = a[12];
5529
- out[13] = a[13];
5530
- out[14] = a[14];
5531
- out[15] = a[15];
5532
- }
5533
- return out;
5534
- }
5535
- function rotateX(out, a, rad) {
5536
- const s = Math.sin(rad);
5537
- const c = Math.cos(rad);
5538
- const a10 = a[4];
5539
- const a11 = a[5];
5540
- const a12 = a[6];
5541
- const a13 = a[7];
5542
- const a20 = a[8];
5543
- const a21 = a[9];
5544
- const a22 = a[10];
5545
- const a23 = a[11];
5546
- if (a !== out) {
5547
- out[0] = a[0];
5548
- out[1] = a[1];
5549
- out[2] = a[2];
5550
- out[3] = a[3];
5551
- out[12] = a[12];
5552
- out[13] = a[13];
5553
- out[14] = a[14];
5554
- out[15] = a[15];
5555
- }
5556
- out[4] = a10 * c + a20 * s;
5557
- out[5] = a11 * c + a21 * s;
5558
- out[6] = a12 * c + a22 * s;
5559
- out[7] = a13 * c + a23 * s;
5560
- out[8] = a20 * c - a10 * s;
5561
- out[9] = a21 * c - a11 * s;
5562
- out[10] = a22 * c - a12 * s;
5563
- out[11] = a23 * c - a13 * s;
5564
- return out;
5565
- }
5566
- function rotateY(out, a, rad) {
5567
- const s = Math.sin(rad);
5568
- const c = Math.cos(rad);
5569
- const a00 = a[0];
5570
- const a01 = a[1];
5571
- const a02 = a[2];
5572
- const a03 = a[3];
5573
- const a20 = a[8];
5574
- const a21 = a[9];
5575
- const a22 = a[10];
5576
- const a23 = a[11];
5577
- if (a !== out) {
5578
- out[4] = a[4];
5579
- out[5] = a[5];
5580
- out[6] = a[6];
5581
- out[7] = a[7];
5582
- out[12] = a[12];
5583
- out[13] = a[13];
5584
- out[14] = a[14];
5585
- out[15] = a[15];
5586
- }
5587
- out[0] = a00 * c - a20 * s;
5588
- out[1] = a01 * c - a21 * s;
5589
- out[2] = a02 * c - a22 * s;
5590
- out[3] = a03 * c - a23 * s;
5591
- out[8] = a00 * s + a20 * c;
5592
- out[9] = a01 * s + a21 * c;
5593
- out[10] = a02 * s + a22 * c;
5594
- out[11] = a03 * s + a23 * c;
5595
- return out;
5596
- }
5597
- function rotateZ(out, a, rad) {
5598
- const s = Math.sin(rad);
5599
- const c = Math.cos(rad);
5600
- const a00 = a[0];
5601
- const a01 = a[1];
5602
- const a02 = a[2];
5603
- const a03 = a[3];
5604
- const a10 = a[4];
5605
- const a11 = a[5];
5606
- const a12 = a[6];
5607
- const a13 = a[7];
5608
- if (a !== out) {
5609
- out[8] = a[8];
5610
- out[9] = a[9];
5611
- out[10] = a[10];
5612
- out[11] = a[11];
5613
- out[12] = a[12];
5614
- out[13] = a[13];
5615
- out[14] = a[14];
5616
- out[15] = a[15];
5617
- }
5618
- out[0] = a00 * c + a10 * s;
5619
- out[1] = a01 * c + a11 * s;
5620
- out[2] = a02 * c + a12 * s;
5621
- out[3] = a03 * c + a13 * s;
5622
- out[4] = a10 * c - a00 * s;
5623
- out[5] = a11 * c - a01 * s;
5624
- out[6] = a12 * c - a02 * s;
5625
- out[7] = a13 * c - a03 * s;
5626
- return out;
5627
- }
5628
- function fromQuat(out, q) {
5629
- const x = q[0];
5630
- const y = q[1];
5631
- const z = q[2];
5632
- const w = q[3];
5633
- const x2 = x + x;
5634
- const y2 = y + y;
5635
- const z2 = z + z;
5636
- const xx = x * x2;
5637
- const yx = y * x2;
5638
- const yy = y * y2;
5639
- const zx = z * x2;
5640
- const zy = z * y2;
5641
- const zz = z * z2;
5642
- const wx = w * x2;
5643
- const wy = w * y2;
5644
- const wz = w * z2;
5645
- out[0] = 1 - yy - zz;
5646
- out[1] = yx + wz;
5647
- out[2] = zx - wy;
5648
- out[3] = 0;
5649
- out[4] = yx - wz;
5650
- out[5] = 1 - xx - zz;
5651
- out[6] = zy + wx;
5652
- out[7] = 0;
5653
- out[8] = zx + wy;
5654
- out[9] = zy - wx;
5655
- out[10] = 1 - xx - yy;
5656
- out[11] = 0;
5657
- out[12] = 0;
5658
- out[13] = 0;
5659
- out[14] = 0;
5660
- out[15] = 1;
5661
- return out;
5662
- }
5663
- function frustum(out, left, right, bottom, top, near, far) {
5664
- const rl = 1 / (right - left);
5665
- const tb = 1 / (top - bottom);
5666
- const nf = 1 / (near - far);
5667
- out[0] = near * 2 * rl;
5668
- out[1] = 0;
5669
- out[2] = 0;
5670
- out[3] = 0;
5671
- out[4] = 0;
5672
- out[5] = near * 2 * tb;
5673
- out[6] = 0;
5674
- out[7] = 0;
5675
- out[8] = (right + left) * rl;
5676
- out[9] = (top + bottom) * tb;
5677
- out[10] = (far + near) * nf;
5678
- out[11] = -1;
5679
- out[12] = 0;
5680
- out[13] = 0;
5681
- out[14] = far * near * 2 * nf;
5682
- out[15] = 0;
5683
- return out;
5684
- }
5685
- function perspectiveNO(out, fovy, aspect, near, far) {
5686
- const f = 1 / Math.tan(fovy / 2);
5687
- out[0] = f / aspect;
5688
- out[1] = 0;
5689
- out[2] = 0;
5690
- out[3] = 0;
5691
- out[4] = 0;
5692
- out[5] = f;
5693
- out[6] = 0;
5694
- out[7] = 0;
5695
- out[8] = 0;
5696
- out[9] = 0;
5697
- out[11] = -1;
5698
- out[12] = 0;
5699
- out[13] = 0;
5700
- out[15] = 0;
5701
- if (far != null && far !== Infinity) {
5702
- const nf = 1 / (near - far);
5703
- out[10] = (far + near) * nf;
5704
- out[14] = 2 * far * near * nf;
5705
- } else {
5706
- out[10] = -1;
5707
- out[14] = -2 * near;
5708
- }
5709
- return out;
5710
- }
5711
- var perspective = perspectiveNO;
5712
- function orthoNO(out, left, right, bottom, top, near, far) {
5713
- const lr = 1 / (left - right);
5714
- const bt = 1 / (bottom - top);
5715
- const nf = 1 / (near - far);
5716
- out[0] = -2 * lr;
5717
- out[1] = 0;
5718
- out[2] = 0;
5719
- out[3] = 0;
5720
- out[4] = 0;
5721
- out[5] = -2 * bt;
5722
- out[6] = 0;
5723
- out[7] = 0;
5724
- out[8] = 0;
5725
- out[9] = 0;
5726
- out[10] = 2 * nf;
5727
- out[11] = 0;
5728
- out[12] = (left + right) * lr;
5729
- out[13] = (top + bottom) * bt;
5730
- out[14] = (far + near) * nf;
5731
- out[15] = 1;
5732
- return out;
5733
- }
5734
- var ortho = orthoNO;
5735
- function lookAt(out, eye, center, up) {
5736
- let len;
5737
- let x0;
5738
- let x1;
5739
- let x2;
5740
- let y0;
5741
- let y1;
5742
- let y2;
5743
- let z0;
5744
- let z1;
5745
- let z2;
5746
- const eyex = eye[0];
5747
- const eyey = eye[1];
5748
- const eyez = eye[2];
5749
- const upx = up[0];
5750
- const upy = up[1];
5751
- const upz = up[2];
5752
- const centerx = center[0];
5753
- const centery = center[1];
5754
- const centerz = center[2];
5755
- if (Math.abs(eyex - centerx) < EPSILON && Math.abs(eyey - centery) < EPSILON && Math.abs(eyez - centerz) < EPSILON) {
5756
- return identity(out);
5757
- }
5758
- z0 = eyex - centerx;
5759
- z1 = eyey - centery;
5760
- z2 = eyez - centerz;
5761
- len = 1 / Math.sqrt(z0 * z0 + z1 * z1 + z2 * z2);
5762
- z0 *= len;
5763
- z1 *= len;
5764
- z2 *= len;
5765
- x0 = upy * z2 - upz * z1;
5766
- x1 = upz * z0 - upx * z2;
5767
- x2 = upx * z1 - upy * z0;
5768
- len = Math.sqrt(x0 * x0 + x1 * x1 + x2 * x2);
5769
- if (!len) {
5770
- x0 = 0;
5771
- x1 = 0;
5772
- x2 = 0;
5773
- } else {
5774
- len = 1 / len;
5775
- x0 *= len;
5776
- x1 *= len;
5777
- x2 *= len;
5778
- }
5779
- y0 = z1 * x2 - z2 * x1;
5780
- y1 = z2 * x0 - z0 * x2;
5781
- y2 = z0 * x1 - z1 * x0;
5782
- len = Math.sqrt(y0 * y0 + y1 * y1 + y2 * y2);
5783
- if (!len) {
5784
- y0 = 0;
5785
- y1 = 0;
5786
- y2 = 0;
5787
- } else {
5788
- len = 1 / len;
5789
- y0 *= len;
5790
- y1 *= len;
5791
- y2 *= len;
5792
- }
5793
- out[0] = x0;
5794
- out[1] = y0;
5795
- out[2] = z0;
5796
- out[3] = 0;
5797
- out[4] = x1;
5798
- out[5] = y1;
5799
- out[6] = z1;
5800
- out[7] = 0;
5801
- out[8] = x2;
5802
- out[9] = y2;
5803
- out[10] = z2;
5804
- out[11] = 0;
5805
- out[12] = -(x0 * eyex + x1 * eyey + x2 * eyez);
5806
- out[13] = -(y0 * eyex + y1 * eyey + y2 * eyez);
5807
- out[14] = -(z0 * eyex + z1 * eyey + z2 * eyez);
5808
- out[15] = 1;
5809
- return out;
5810
- }
5811
-
5812
- // ../../node_modules/@math.gl/core/dist/gl-matrix/vec4.js
5813
- function create3() {
5814
- const out = new ARRAY_TYPE(4);
5815
- if (ARRAY_TYPE != Float32Array) {
5816
- out[0] = 0;
5817
- out[1] = 0;
5818
- out[2] = 0;
5819
- out[3] = 0;
5820
- }
5821
- return out;
5822
- }
5823
- function transformMat43(out, a, m) {
5824
- const x = a[0];
5825
- const y = a[1];
5826
- const z = a[2];
5827
- const w = a[3];
5828
- out[0] = m[0] * x + m[4] * y + m[8] * z + m[12] * w;
5829
- out[1] = m[1] * x + m[5] * y + m[9] * z + m[13] * w;
5830
- out[2] = m[2] * x + m[6] * y + m[10] * z + m[14] * w;
5831
- out[3] = m[3] * x + m[7] * y + m[11] * z + m[15] * w;
5832
- return out;
5833
- }
5834
- var forEach3 = function() {
5835
- const vec = create3();
5836
- return function(a, stride, offset, count, fn, arg) {
5837
- let i;
5838
- let l;
5839
- if (!stride) {
5840
- stride = 4;
5841
- }
5842
- if (!offset) {
5843
- offset = 0;
5844
- }
5845
- if (count) {
5846
- l = Math.min(count * stride + offset, a.length);
5847
- } else {
5848
- l = a.length;
5849
- }
5850
- for (i = offset; i < l; i += stride) {
5851
- vec[0] = a[i];
5852
- vec[1] = a[i + 1];
5853
- vec[2] = a[i + 2];
5854
- vec[3] = a[i + 3];
5855
- fn(vec, vec, arg);
5856
- a[i] = vec[0];
5857
- a[i + 1] = vec[1];
5858
- a[i + 2] = vec[2];
5859
- a[i + 3] = vec[3];
5860
- }
5861
- return a;
5862
- };
5863
- }();
5864
-
5865
- // ../../node_modules/@math.gl/core/dist/classes/matrix4.js
5866
- var INDICES;
5867
- (function(INDICES2) {
5868
- INDICES2[INDICES2["COL0ROW0"] = 0] = "COL0ROW0";
5869
- INDICES2[INDICES2["COL0ROW1"] = 1] = "COL0ROW1";
5870
- INDICES2[INDICES2["COL0ROW2"] = 2] = "COL0ROW2";
5871
- INDICES2[INDICES2["COL0ROW3"] = 3] = "COL0ROW3";
5872
- INDICES2[INDICES2["COL1ROW0"] = 4] = "COL1ROW0";
5873
- INDICES2[INDICES2["COL1ROW1"] = 5] = "COL1ROW1";
5874
- INDICES2[INDICES2["COL1ROW2"] = 6] = "COL1ROW2";
5875
- INDICES2[INDICES2["COL1ROW3"] = 7] = "COL1ROW3";
5876
- INDICES2[INDICES2["COL2ROW0"] = 8] = "COL2ROW0";
5877
- INDICES2[INDICES2["COL2ROW1"] = 9] = "COL2ROW1";
5878
- INDICES2[INDICES2["COL2ROW2"] = 10] = "COL2ROW2";
5879
- INDICES2[INDICES2["COL2ROW3"] = 11] = "COL2ROW3";
5880
- INDICES2[INDICES2["COL3ROW0"] = 12] = "COL3ROW0";
5881
- INDICES2[INDICES2["COL3ROW1"] = 13] = "COL3ROW1";
5882
- INDICES2[INDICES2["COL3ROW2"] = 14] = "COL3ROW2";
5883
- INDICES2[INDICES2["COL3ROW3"] = 15] = "COL3ROW3";
5884
- })(INDICES || (INDICES = {}));
5885
- var DEFAULT_FOVY = 45 * Math.PI / 180;
5886
- var DEFAULT_ASPECT = 1;
5887
- var DEFAULT_NEAR = 0.1;
5888
- var DEFAULT_FAR = 500;
5889
- var IDENTITY_MATRIX = Object.freeze([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
5890
- var Matrix4 = class extends Matrix {
5891
- static get IDENTITY() {
5892
- return getIdentityMatrix();
5893
- }
5894
- static get ZERO() {
5895
- return getZeroMatrix();
5896
- }
5897
- get ELEMENTS() {
5898
- return 16;
5899
- }
5900
- get RANK() {
5901
- return 4;
5902
- }
5903
- get INDICES() {
5904
- return INDICES;
5905
- }
5906
- constructor(array) {
5907
- super(-0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0);
5908
- if (arguments.length === 1 && Array.isArray(array)) {
5909
- this.copy(array);
5910
- } else {
5911
- this.identity();
5912
- }
5913
- }
5914
- copy(array) {
5915
- this[0] = array[0];
5916
- this[1] = array[1];
5917
- this[2] = array[2];
5918
- this[3] = array[3];
5919
- this[4] = array[4];
5920
- this[5] = array[5];
5921
- this[6] = array[6];
5922
- this[7] = array[7];
5923
- this[8] = array[8];
5924
- this[9] = array[9];
5925
- this[10] = array[10];
5926
- this[11] = array[11];
5927
- this[12] = array[12];
5928
- this[13] = array[13];
5929
- this[14] = array[14];
5930
- this[15] = array[15];
5931
- return this.check();
5932
- }
5933
- // eslint-disable-next-line max-params
5934
- set(m00, m10, m20, m30, m01, m11, m21, m31, m02, m12, m22, m32, m03, m13, m23, m33) {
5935
- this[0] = m00;
5936
- this[1] = m10;
5937
- this[2] = m20;
5938
- this[3] = m30;
5939
- this[4] = m01;
5940
- this[5] = m11;
5941
- this[6] = m21;
5942
- this[7] = m31;
5943
- this[8] = m02;
5944
- this[9] = m12;
5945
- this[10] = m22;
5946
- this[11] = m32;
5947
- this[12] = m03;
5948
- this[13] = m13;
5949
- this[14] = m23;
5950
- this[15] = m33;
5951
- return this.check();
5952
- }
5953
- // accepts row major order, stores as column major
5954
- // eslint-disable-next-line max-params
5955
- setRowMajor(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {
5956
- this[0] = m00;
5957
- this[1] = m10;
5958
- this[2] = m20;
5959
- this[3] = m30;
5960
- this[4] = m01;
5961
- this[5] = m11;
5962
- this[6] = m21;
5963
- this[7] = m31;
5964
- this[8] = m02;
5965
- this[9] = m12;
5966
- this[10] = m22;
5967
- this[11] = m32;
5968
- this[12] = m03;
5969
- this[13] = m13;
5970
- this[14] = m23;
5971
- this[15] = m33;
5972
- return this.check();
5973
- }
5974
- toRowMajor(result) {
5975
- result[0] = this[0];
5976
- result[1] = this[4];
5977
- result[2] = this[8];
5978
- result[3] = this[12];
5979
- result[4] = this[1];
5980
- result[5] = this[5];
5981
- result[6] = this[9];
5982
- result[7] = this[13];
5983
- result[8] = this[2];
5984
- result[9] = this[6];
5985
- result[10] = this[10];
5986
- result[11] = this[14];
5987
- result[12] = this[3];
5988
- result[13] = this[7];
5989
- result[14] = this[11];
5990
- result[15] = this[15];
5991
- return result;
5992
- }
5993
- // Constructors
5994
- /** Set to identity matrix */
5995
- identity() {
5996
- return this.copy(IDENTITY_MATRIX);
5997
- }
5998
- /**
5999
- *
6000
- * @param object
6001
- * @returns self
6002
- */
6003
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
6004
- fromObject(object) {
6005
- return this.check();
6006
- }
6007
- /**
6008
- * Calculates a 4x4 matrix from the given quaternion
6009
- * @param quaternion Quaternion to create matrix from
6010
- * @returns self
6011
- */
6012
- fromQuaternion(quaternion) {
6013
- fromQuat(this, quaternion);
6014
- return this.check();
6015
- }
6016
- /**
6017
- * Generates a frustum matrix with the given bounds
6018
- * @param view.left - Left bound of the frustum
6019
- * @param view.right - Right bound of the frustum
6020
- * @param view.bottom - Bottom bound of the frustum
6021
- * @param view.top - Top bound of the frustum
6022
- * @param view.near - Near bound of the frustum
6023
- * @param view.far - Far bound of the frustum. Can be set to Infinity.
6024
- * @returns self
6025
- */
6026
- frustum(view) {
6027
- const { left, right, bottom, top, near = DEFAULT_NEAR, far = DEFAULT_FAR } = view;
6028
- if (far === Infinity) {
6029
- computeInfinitePerspectiveOffCenter(this, left, right, bottom, top, near);
6030
- } else {
6031
- frustum(this, left, right, bottom, top, near, far);
6032
- }
6033
- return this.check();
6034
- }
6035
- /**
6036
- * Generates a look-at matrix with the given eye position, focal point,
6037
- * and up axis
6038
- * @param view.eye - (vector) Position of the viewer
6039
- * @param view.center - (vector) Point the viewer is looking at
6040
- * @param view.up - (vector) Up axis
6041
- * @returns self
6042
- */
6043
- lookAt(view) {
6044
- const { eye, center = [0, 0, 0], up = [0, 1, 0] } = view;
6045
- lookAt(this, eye, center, up);
6046
- return this.check();
6047
- }
6048
- /**
6049
- * Generates a orthogonal projection matrix with the given bounds
6050
- * from "traditional" view space parameters
6051
- * @param view.left - Left bound of the frustum
6052
- * @param view.right number Right bound of the frustum
6053
- * @param view.bottom - Bottom bound of the frustum
6054
- * @param view.top number Top bound of the frustum
6055
- * @param view.near - Near bound of the frustum
6056
- * @param view.far number Far bound of the frustum
6057
- * @returns self
6058
- */
6059
- ortho(view) {
6060
- const { left, right, bottom, top, near = DEFAULT_NEAR, far = DEFAULT_FAR } = view;
6061
- ortho(this, left, right, bottom, top, near, far);
6062
- return this.check();
6063
- }
6064
- /**
6065
- * Generates an orthogonal projection matrix with the same parameters
6066
- * as a perspective matrix (plus focalDistance)
6067
- * @param view.fovy Vertical field of view in radians
6068
- * @param view.aspect Aspect ratio. Typically viewport width / viewport height
6069
- * @param view.focalDistance Distance in the view frustum used for extent calculations
6070
- * @param view.near Near bound of the frustum
6071
- * @param view.far Far bound of the frustum
6072
- * @returns self
6073
- */
6074
- orthographic(view) {
6075
- const { fovy = DEFAULT_FOVY, aspect = DEFAULT_ASPECT, focalDistance = 1, near = DEFAULT_NEAR, far = DEFAULT_FAR } = view;
6076
- checkRadians(fovy);
6077
- const halfY = fovy / 2;
6078
- const top = focalDistance * Math.tan(halfY);
6079
- const right = top * aspect;
6080
- return this.ortho({
6081
- left: -right,
6082
- right,
6083
- bottom: -top,
6084
- top,
6085
- near,
6086
- far
6087
- });
6088
- }
6089
- /**
6090
- * Generates a perspective projection matrix with the given bounds
6091
- * @param view.fovy Vertical field of view in radians
6092
- * @param view.aspect Aspect ratio. typically viewport width/height
6093
- * @param view.near Near bound of the frustum
6094
- * @param view.far Far bound of the frustum
6095
- * @returns self
6096
- */
6097
- perspective(view) {
6098
- const { fovy = 45 * Math.PI / 180, aspect = 1, near = 0.1, far = 500 } = view;
6099
- checkRadians(fovy);
6100
- perspective(this, fovy, aspect, near, far);
6101
- return this.check();
6102
- }
6103
- // Accessors
6104
- determinant() {
6105
- return determinant(this);
6106
- }
6107
- /**
6108
- * Extracts the non-uniform scale assuming the matrix is an affine transformation.
6109
- * The scales are the "lengths" of the column vectors in the upper-left 3x3 matrix.
6110
- * @param result
6111
- * @returns self
6112
- */
6113
- getScale(result = [-0, -0, -0]) {
6114
- result[0] = Math.sqrt(this[0] * this[0] + this[1] * this[1] + this[2] * this[2]);
6115
- result[1] = Math.sqrt(this[4] * this[4] + this[5] * this[5] + this[6] * this[6]);
6116
- result[2] = Math.sqrt(this[8] * this[8] + this[9] * this[9] + this[10] * this[10]);
6117
- return result;
6118
- }
6119
- /**
6120
- * Gets the translation portion, assuming the matrix is a affine transformation matrix.
6121
- * @param result
6122
- * @returns self
6123
- */
6124
- getTranslation(result = [-0, -0, -0]) {
6125
- result[0] = this[12];
6126
- result[1] = this[13];
6127
- result[2] = this[14];
6128
- return result;
6129
- }
6130
- /**
6131
- * Gets upper left 3x3 pure rotation matrix (non-scaling), assume affine transformation matrix
6132
- * @param result
6133
- * @param scaleResult
6134
- * @returns self
6135
- */
6136
- getRotation(result, scaleResult) {
6137
- result = result || [-0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0];
6138
- scaleResult = scaleResult || [-0, -0, -0];
6139
- const scale2 = this.getScale(scaleResult);
6140
- const inverseScale0 = 1 / scale2[0];
6141
- const inverseScale1 = 1 / scale2[1];
6142
- const inverseScale2 = 1 / scale2[2];
6143
- result[0] = this[0] * inverseScale0;
6144
- result[1] = this[1] * inverseScale1;
6145
- result[2] = this[2] * inverseScale2;
6146
- result[3] = 0;
6147
- result[4] = this[4] * inverseScale0;
6148
- result[5] = this[5] * inverseScale1;
6149
- result[6] = this[6] * inverseScale2;
6150
- result[7] = 0;
6151
- result[8] = this[8] * inverseScale0;
6152
- result[9] = this[9] * inverseScale1;
6153
- result[10] = this[10] * inverseScale2;
6154
- result[11] = 0;
6155
- result[12] = 0;
6156
- result[13] = 0;
6157
- result[14] = 0;
6158
- result[15] = 1;
6159
- return result;
6160
- }
6161
- /**
6162
- *
6163
- * @param result
6164
- * @param scaleResult
6165
- * @returns self
6166
- */
6167
- getRotationMatrix3(result, scaleResult) {
6168
- result = result || [-0, -0, -0, -0, -0, -0, -0, -0, -0];
6169
- scaleResult = scaleResult || [-0, -0, -0];
6170
- const scale2 = this.getScale(scaleResult);
6171
- const inverseScale0 = 1 / scale2[0];
6172
- const inverseScale1 = 1 / scale2[1];
6173
- const inverseScale2 = 1 / scale2[2];
6174
- result[0] = this[0] * inverseScale0;
6175
- result[1] = this[1] * inverseScale1;
6176
- result[2] = this[2] * inverseScale2;
6177
- result[3] = this[4] * inverseScale0;
6178
- result[4] = this[5] * inverseScale1;
6179
- result[5] = this[6] * inverseScale2;
6180
- result[6] = this[8] * inverseScale0;
6181
- result[7] = this[9] * inverseScale1;
6182
- result[8] = this[10] * inverseScale2;
6183
- return result;
6184
- }
6185
- // Modifiers
6186
- transpose() {
6187
- transpose(this, this);
6188
- return this.check();
6189
- }
6190
- invert() {
6191
- invert(this, this);
6192
- return this.check();
6193
- }
6194
- // Operations
6195
- multiplyLeft(a) {
6196
- multiply(this, a, this);
6197
- return this.check();
6198
- }
6199
- multiplyRight(a) {
6200
- multiply(this, this, a);
6201
- return this.check();
6202
- }
6203
- // Rotates a matrix by the given angle around the X axis
6204
- rotateX(radians2) {
6205
- rotateX(this, this, radians2);
6206
- return this.check();
6207
- }
6208
- // Rotates a matrix by the given angle around the Y axis.
6209
- rotateY(radians2) {
6210
- rotateY(this, this, radians2);
6211
- return this.check();
6212
- }
6213
- /**
6214
- * Rotates a matrix by the given angle around the Z axis.
6215
- * @param radians
6216
- * @returns self
6217
- */
6218
- rotateZ(radians2) {
6219
- rotateZ(this, this, radians2);
6220
- return this.check();
6221
- }
6222
- /**
6223
- *
6224
- * @param param0
6225
- * @returns self
6226
- */
6227
- rotateXYZ(angleXYZ) {
6228
- return this.rotateX(angleXYZ[0]).rotateY(angleXYZ[1]).rotateZ(angleXYZ[2]);
6229
- }
6230
- /**
6231
- *
6232
- * @param radians
6233
- * @param axis
6234
- * @returns self
6235
- */
6236
- rotateAxis(radians2, axis) {
6237
- rotate(this, this, radians2, axis);
6238
- return this.check();
6239
- }
6240
- /**
6241
- *
6242
- * @param factor
6243
- * @returns self
6244
- */
6245
- scale(factor) {
6246
- scale(this, this, Array.isArray(factor) ? factor : [factor, factor, factor]);
6247
- return this.check();
6248
- }
6249
- /**
6250
- *
6251
- * @param vec
6252
- * @returns self
6253
- */
6254
- translate(vector) {
6255
- translate(this, this, vector);
6256
- return this.check();
6257
- }
6258
- // Transforms
6259
- /**
6260
- * Transforms any 2, 3 or 4 element vector. 2 and 3 elements are treated as points
6261
- * @param vector
6262
- * @param result
6263
- * @returns self
6264
- */
6265
- transform(vector, result) {
6266
- if (vector.length === 4) {
6267
- result = transformMat43(result || [-0, -0, -0, -0], vector, this);
6268
- checkVector(result, 4);
6269
- return result;
6270
- }
6271
- return this.transformAsPoint(vector, result);
6272
- }
6273
- /**
6274
- * Transforms any 2 or 3 element array as point (w implicitly 1)
6275
- * @param vector
6276
- * @param result
6277
- * @returns self
6278
- */
6279
- transformAsPoint(vector, result) {
6280
- const { length } = vector;
6281
- let out;
6282
- switch (length) {
6283
- case 2:
6284
- out = transformMat4(result || [-0, -0], vector, this);
6285
- break;
6286
- case 3:
6287
- out = transformMat42(result || [-0, -0, -0], vector, this);
6288
- break;
6289
- default:
6290
- throw new Error("Illegal vector");
6291
- }
6292
- checkVector(out, vector.length);
6293
- return out;
6294
- }
6295
- /**
6296
- * Transforms any 2 or 3 element array as vector (w implicitly 0)
6297
- * @param vector
6298
- * @param result
6299
- * @returns self
6300
- */
6301
- transformAsVector(vector, result) {
6302
- let out;
6303
- switch (vector.length) {
6304
- case 2:
6305
- out = vec2_transformMat4AsVector(result || [-0, -0], vector, this);
6306
- break;
6307
- case 3:
6308
- out = vec3_transformMat4AsVector(result || [-0, -0, -0], vector, this);
6309
- break;
6310
- default:
6311
- throw new Error("Illegal vector");
6312
- }
6313
- checkVector(out, vector.length);
6314
- return out;
6315
- }
6316
- /** @deprecated */
6317
- transformPoint(vector, result) {
6318
- return this.transformAsPoint(vector, result);
6319
- }
6320
- /** @deprecated */
6321
- transformVector(vector, result) {
6322
- return this.transformAsPoint(vector, result);
6323
- }
6324
- /** @deprecated */
6325
- transformDirection(vector, result) {
6326
- return this.transformAsVector(vector, result);
6327
- }
6328
- // three.js math API compatibility
6329
- makeRotationX(radians2) {
6330
- return this.identity().rotateX(radians2);
6331
- }
6332
- makeTranslation(x, y, z) {
6333
- return this.identity().translate([x, y, z]);
6334
- }
6335
- };
6336
- var ZERO;
6337
- var IDENTITY;
6338
- function getZeroMatrix() {
6339
- if (!ZERO) {
6340
- ZERO = new Matrix4([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
6341
- Object.freeze(ZERO);
6342
- }
6343
- return ZERO;
6344
- }
6345
- function getIdentityMatrix() {
6346
- if (!IDENTITY) {
6347
- IDENTITY = new Matrix4();
6348
- Object.freeze(IDENTITY);
6349
- }
6350
- return IDENTITY;
6351
- }
6352
- function checkRadians(possiblyDegrees) {
6353
- if (possiblyDegrees > Math.PI * 2) {
6354
- throw Error("expected radians");
6355
- }
6356
- }
6357
- function computeInfinitePerspectiveOffCenter(result, left, right, bottom, top, near) {
6358
- const column0Row0 = 2 * near / (right - left);
6359
- const column1Row1 = 2 * near / (top - bottom);
6360
- const column2Row0 = (right + left) / (right - left);
6361
- const column2Row1 = (top + bottom) / (top - bottom);
6362
- const column2Row2 = -1;
6363
- const column2Row3 = -1;
6364
- const column3Row2 = -2 * near;
6365
- result[0] = column0Row0;
6366
- result[1] = 0;
6367
- result[2] = 0;
6368
- result[3] = 0;
6369
- result[4] = 0;
6370
- result[5] = column1Row1;
6371
- result[6] = 0;
6372
- result[7] = 0;
6373
- result[8] = column2Row0;
6374
- result[9] = column2Row1;
6375
- result[10] = column2Row2;
6376
- result[11] = column2Row3;
6377
- result[12] = 0;
6378
- result[13] = 0;
6379
- result[14] = column3Row2;
6380
- result[15] = 0;
6381
- return result;
6382
- }
6383
-
6384
- // src/modules/math/fp16/fp16-utils.ts
6385
- var float16Tables = null;
6386
- var buffer = new ArrayBuffer(4);
6387
- var floatView = new Float32Array(buffer);
6388
- var uint32View = new Uint32Array(buffer);
6389
- function toHalfFloat(val) {
6390
- float16Tables ||= generateFloat16Tables();
6391
- val = clamp(val, -65504, 65504);
6392
- floatView[0] = val;
6393
- const f = uint32View[0];
6394
- const e = f >> 23 & 511;
6395
- return float16Tables.baseTable[e] + ((f & 8388607) >> float16Tables.shiftTable[e]);
6396
- }
6397
- function fromHalfFloat(val) {
6398
- float16Tables ||= generateFloat16Tables();
6399
- const m = val >> 10;
6400
- uint32View[0] = float16Tables.mantissaTable[float16Tables.offsetTable[m] + (val & 1023)] + float16Tables.exponentTable[m];
6401
- return floatView[0];
6402
- }
6403
- function generateFloat16Tables() {
6404
- const baseTable = new Uint32Array(512);
6405
- const shiftTable = new Uint32Array(512);
6406
- for (let i = 0; i < 256; ++i) {
6407
- const e = i - 127;
6408
- if (e < -27) {
6409
- baseTable[i] = 0;
6410
- baseTable[i | 256] = 32768;
6411
- shiftTable[i] = 24;
6412
- shiftTable[i | 256] = 24;
6413
- } else if (e < -14) {
6414
- baseTable[i] = 1024 >> -e - 14;
6415
- baseTable[i | 256] = 1024 >> -e - 14 | 32768;
6416
- shiftTable[i] = -e - 1;
6417
- shiftTable[i | 256] = -e - 1;
6418
- } else if (e <= 15) {
6419
- baseTable[i] = e + 15 << 10;
6420
- baseTable[i | 256] = e + 15 << 10 | 32768;
6421
- shiftTable[i] = 13;
6422
- shiftTable[i | 256] = 13;
6423
- } else if (e < 128) {
6424
- baseTable[i] = 31744;
6425
- baseTable[i | 256] = 64512;
6426
- shiftTable[i] = 24;
6427
- shiftTable[i | 256] = 24;
6428
- } else {
6429
- baseTable[i] = 31744;
6430
- baseTable[i | 256] = 64512;
6431
- shiftTable[i] = 13;
6432
- shiftTable[i | 256] = 13;
6433
- }
6434
- }
6435
- const mantissaTable = new Uint32Array(2048);
6436
- const exponentTable = new Uint32Array(64);
6437
- const offsetTable = new Uint32Array(64);
6438
- for (let i = 1; i < 1024; ++i) {
6439
- let m = i << 13;
6440
- let e = 0;
6441
- while ((m & 8388608) === 0) {
6442
- m <<= 1;
6443
- e -= 8388608;
6444
- }
6445
- m &= ~8388608;
6446
- e += 947912704;
6447
- mantissaTable[i] = m | e;
6448
- }
6449
- for (let i = 1024; i < 2048; ++i) {
6450
- mantissaTable[i] = 939524096 + (i - 1024 << 13);
6451
- }
6452
- for (let i = 1; i < 31; ++i) {
6453
- exponentTable[i] = i << 23;
6454
- }
6455
- exponentTable[31] = 1199570944;
6456
- exponentTable[32] = 2147483648;
6457
- for (let i = 33; i < 63; ++i) {
6458
- exponentTable[i] = 2147483648 + (i - 32 << 23);
6459
- }
6460
- exponentTable[63] = 3347054592;
6461
- for (let i = 1; i < 64; ++i) {
6462
- if (i !== 32) {
6463
- offsetTable[i] = 1024;
6464
- }
6465
- }
6466
- return { baseTable, shiftTable, mantissaTable, exponentTable, offsetTable };
6467
- }
6468
-
6469
- // src/modules/math/fp64/fp64-utils.ts
6470
- function fp64ify(a, out = [], startIndex = 0) {
6471
- const hiPart = Math.fround(a);
6472
- const loPart = a - hiPart;
6473
- out[startIndex] = hiPart;
6474
- out[startIndex + 1] = loPart;
6475
- return out;
6476
- }
6477
- function fp64LowPart(a) {
6478
- return a - Math.fround(a);
6479
- }
6480
- function fp64ifyMatrix4(matrix) {
6481
- const matrixFP64 = new Float32Array(32);
6482
- for (let i = 0; i < 4; ++i) {
6483
- for (let j = 0; j < 4; ++j) {
6484
- const index = i * 4 + j;
6485
- fp64ify(matrix[j * 4 + i], matrixFP64, index * 2);
6486
- }
6487
- }
6488
- return matrixFP64;
6489
- }
6490
-
6491
- // src/modules/math/random/random.ts
6492
- var fs = (
6493
- /* glsl */
6494
- `float random(vec3 scale, float seed) {
6495
- /* use the fragment position for a different seed per-pixel */
6496
- return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);
6497
- }
6498
- `
6499
- );
6500
- var random = {
6501
- name: "random",
6502
- fs
4851
+
4852
+ // src/modules/math/random/random.ts
4853
+ var source = (
4854
+ /* wgsl */
4855
+ `fn random(scale: vec3f, seed: float) -> f32 {
4856
+ /* use the fragment position for a different seed per-pixel */
4857
+ return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);
4858
+ }
4859
+ `
4860
+ );
4861
+ var fs = (
4862
+ /* glsl */
4863
+ `float random(vec3 scale, float seed) {
4864
+ /* use the fragment position for a different seed per-pixel */
4865
+ return fract(sin(dot(gl_FragCoord.xyz + seed, scale)) * 43758.5453 + seed);
4866
+ }
4867
+ `
4868
+ );
4869
+ var random = {
4870
+ name: "random",
4871
+ source,
4872
+ fs
6503
4873
  };
6504
4874
 
6505
4875
  // src/modules/math/fp32/fp32.ts
@@ -7727,7 +6097,7 @@ vec4 picking_filterColor(vec4 color) {
7727
6097
  // src/modules/lighting/lights/lighting.ts
7728
6098
  var import_core3 = __toESM(require_core(), 1);
7729
6099
 
7730
- // src/modules/lighting/lights/lighting-uniforms-glsl.ts
6100
+ // src/modules/lighting/lights/lighting-glsl.ts
7731
6101
  var lightingUniformsGLSL = (
7732
6102
  /* glsl */
7733
6103
  `precision highp int;
@@ -7807,7 +6177,7 @@ float getPointLightAttenuation(PointLight pointLight, float distance) {
7807
6177
  `
7808
6178
  );
7809
6179
 
7810
- // src/modules/lighting/lights/lighting-uniforms-wgsl.ts
6180
+ // src/modules/lighting/lights/lighting-wgsl.ts
7811
6181
  var lightingUniformsWGSL = (
7812
6182
  /* wgsl */
7813
6183
  `// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
@@ -7865,14 +6235,14 @@ fn getPointLightAttenuation(pointLight: PointLight, distance: f32) -> f32 {
7865
6235
  );
7866
6236
 
7867
6237
  // src/modules/lighting/lights/lighting.ts
7868
- var MAX_LIGHTS = 3;
6238
+ var MAX_LIGHTS = 5;
7869
6239
  var COLOR_FACTOR = 255;
7870
6240
  var lighting = {
7871
6241
  props: {},
7872
6242
  uniforms: {},
7873
6243
  name: "lighting",
7874
6244
  defines: {
7875
- MAX_LIGHTS
6245
+ // MAX_LIGHTS
7876
6246
  },
7877
6247
  uniformTypes: {
7878
6248
  enabled: "i32",
@@ -7973,9 +6343,9 @@ fn getPointLightAttenuation(pointLight: PointLight, distance: f32) -> f32 {
7973
6343
  lightSourceUniforms.pointLightCount = pointLights.length;
7974
6344
  return lightSourceUniforms;
7975
6345
  }
7976
- function extractLightTypes(lights2) {
6346
+ function extractLightTypes(lights) {
7977
6347
  const lightSources = { pointLights: [], directionalLights: [] };
7978
- for (const light of lights2 || []) {
6348
+ for (const light of lights || []) {
7979
6349
  switch (light.type) {
7980
6350
  case "ambient":
7981
6351
  lightSources.ambientLight = light;
@@ -8150,7 +6520,7 @@ vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 positio
8150
6520
  vs: PHONG_FS.replace("phongMaterial", "gouraudMaterial"),
8151
6521
  fs: PHONG_VS.replace("phongMaterial", "gouraudMaterial"),
8152
6522
  defines: {
8153
- LIGHTING_VERTEX: 1
6523
+ LIGHTING_VERTEX: true
8154
6524
  },
8155
6525
  dependencies: [lighting],
8156
6526
  uniformTypes: {
@@ -8274,7 +6644,7 @@ fn lighting_getSpecularLightColor(cameraPosition: vec3<f32>, position_worldspace
8274
6644
  vs: PHONG_VS,
8275
6645
  fs: PHONG_FS,
8276
6646
  defines: {
8277
- LIGHTING_FRAGMENT: 1
6647
+ LIGHTING_FRAGMENT: true
8278
6648
  },
8279
6649
  uniformTypes: {
8280
6650
  ambient: "f32",
@@ -8297,7 +6667,7 @@ fn lighting_getSpecularLightColor(cameraPosition: vec3<f32>, position_worldspace
8297
6667
  }
8298
6668
  };
8299
6669
 
8300
- // src/modules/lighting/pbr-material/pbr-vertex-glsl.ts
6670
+ // src/modules/lighting/pbr-material/pbr-material-glsl.ts
8301
6671
  var vs2 = (
8302
6672
  /* glsl */
8303
6673
  `out vec3 pbr_vPosition;
@@ -8335,8 +6705,6 @@ void pbr_setPositionNormalTangentUV(vec4 position, vec4 normal, vec4 tangent, ve
8335
6705
  }
8336
6706
  `
8337
6707
  );
8338
-
8339
- // src/modules/lighting/pbr-material/pbr-fragment-glsl.ts
8340
6708
  var fs3 = (
8341
6709
  /* glsl */
8342
6710
  `precision highp float;
@@ -8743,532 +7111,31 @@ vec4 pbr_filterColor(vec4 colorUnused)
8743
7111
  `
8744
7112
  );
8745
7113
 
8746
- // src/modules/lighting/pbr-material/pbr-projection.ts
8747
- var uniformBlock = (
8748
- /* glsl */
8749
- `uniform pbrProjectionUniforms {
8750
- mat4 modelViewProjectionMatrix;
8751
- mat4 modelMatrix;
8752
- mat4 normalMatrix;
8753
- vec3 camera;
8754
- } pbrProjection;
8755
- `
8756
- );
8757
- var pbrProjection = {
8758
- name: "pbrProjection",
8759
- vs: uniformBlock,
8760
- fs: uniformBlock,
8761
- // TODO why is this needed?
8762
- getUniforms: (props) => props,
8763
- uniformTypes: {
8764
- modelViewProjectionMatrix: "mat4x4<f32>",
8765
- modelMatrix: "mat4x4<f32>",
8766
- normalMatrix: "mat4x4<f32>",
8767
- camera: "vec3<i32>"
8768
- }
8769
- };
8770
-
8771
- // src/modules/lighting/pbr-material/pbr-material.ts
8772
- var pbrMaterial = {
8773
- props: {},
8774
- uniforms: {},
8775
- name: "pbrMaterial",
8776
- dependencies: [lighting, pbrProjection],
8777
- vs: vs2,
8778
- fs: fs3,
8779
- defines: {
8780
- LIGHTING_FRAGMENT: 1
8781
- // TODO defining these as 0 breaks shader
8782
- // HAS_NORMALMAP: 0
8783
- // HAS_EMISSIVEMAP: 0,
8784
- // HAS_OCCLUSIONMAP: 0,
8785
- // HAS_BASECOLORMAP: 0,
8786
- // HAS_METALROUGHNESSMAP: 0,
8787
- // ALPHA_CUTOFF: 0
8788
- // USE_IBL: 0
8789
- // PBR_DEBUG: 0
8790
- },
8791
- getUniforms: (props) => props,
8792
- uniformTypes: {
8793
- // Material is unlit
8794
- unlit: "i32",
8795
- // Base color map
8796
- baseColorMapEnabled: "i32",
8797
- baseColorFactor: "vec4<f32>",
8798
- normalMapEnabled: "i32",
8799
- normalScale: "f32",
8800
- // #ifdef HAS_NORMALMAP
8801
- emissiveMapEnabled: "i32",
8802
- emissiveFactor: "vec3<f32>",
8803
- // #ifdef HAS_EMISSIVEMAP
8804
- metallicRoughnessValues: "vec2<f32>",
8805
- metallicRoughnessMapEnabled: "i32",
8806
- occlusionMapEnabled: "i32",
8807
- occlusionStrength: "f32",
8808
- // #ifdef HAS_OCCLUSIONMAP
8809
- alphaCutoffEnabled: "i32",
8810
- alphaCutoff: "f32",
8811
- // #ifdef ALPHA_CUTOFF
8812
- // IBL
8813
- IBLenabled: "i32",
8814
- scaleIBLAmbient: "vec2<f32>",
8815
- // #ifdef USE_IBL
8816
- // debugging flags used for shader output of intermediate PBR variables
8817
- // #ifdef PBR_DEBUG
8818
- scaleDiffBaseMR: "vec4<f32>",
8819
- scaleFGDSpec: "vec4<f32>"
8820
- }
8821
- };
8822
-
8823
- // src/modules-webgl1/geometry/geometry.ts
8824
- var vs3 = (
8825
- /* glsl */
8826
- `varying vec4 geometry_vPosition;
8827
- varying vec3 geometry_vNormal;
8828
-
8829
- void geometry_setNormal(vec3 normal) {
8830
- geometry_vNormal = normal;
8831
- }
8832
-
8833
- void geometry_setPosition(vec4 position) {
8834
- geometry_vPosition = position;
8835
- }
8836
-
8837
- void geometry_setPosition(vec3 position) {
8838
- geometry_vPosition = vec4(position, 1.);
8839
- }
8840
- `
8841
- );
8842
- var fs4 = (
8843
- /* glsl */
8844
- `varying vec4 geometry_vPosition;
8845
- varying vec3 geometry_vNormal;
8846
-
8847
- vec4 geometry_getPosition() {
8848
- return geometry_vPosition;
8849
- }
8850
-
8851
- vec3 geometry_getNormal() {
8852
- return geometry_vNormal;
8853
- }
8854
- `
8855
- );
8856
- var geometry = {
8857
- name: "geometry",
8858
- vs: vs3,
8859
- fs: fs4
8860
- };
8861
-
8862
- // src/modules-webgl1/project/project.ts
8863
- var IDENTITY_MATRIX2 = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
8864
- var DEFAULT_MODULE_OPTIONS = {
8865
- modelMatrix: IDENTITY_MATRIX2,
8866
- viewMatrix: IDENTITY_MATRIX2,
8867
- projectionMatrix: IDENTITY_MATRIX2,
8868
- cameraPositionWorld: [0, 0, 0]
8869
- };
8870
- function getUniforms4(opts = DEFAULT_MODULE_OPTIONS, prevUniforms = {}) {
8871
- const uniforms = {};
8872
- if (opts.modelMatrix !== void 0) {
8873
- uniforms.modelMatrix = opts.modelMatrix;
8874
- }
8875
- if (opts.viewMatrix !== void 0) {
8876
- uniforms.viewMatrix = opts.viewMatrix;
8877
- }
8878
- if (opts.projectionMatrix !== void 0) {
8879
- uniforms.projectionMatrix = opts.projectionMatrix;
8880
- }
8881
- if (opts.cameraPositionWorld !== void 0) {
8882
- uniforms.cameraPositionWorld = opts.cameraPositionWorld;
8883
- }
8884
- if (opts.projectionMatrix !== void 0 && opts.viewMatrix !== void 0) {
8885
- uniforms.viewProjectionMatrix = new Matrix4(opts.projectionMatrix).multiplyRight(
8886
- opts.viewMatrix
8887
- );
8888
- }
8889
- return uniforms;
8890
- }
8891
- var common = (
8892
- /* glsl */
8893
- `varying vec4 project_vPositionWorld;
8894
- varying vec3 project_vNormalWorld;
8895
-
8896
- vec4 project_getPosition_World() {
8897
- return project_vPositionWorld;
8898
- }
8899
-
8900
- vec3 project_getNormal_World() {
8901
- return project_vNormalWorld;
8902
- }
8903
- `
8904
- );
8905
- var vs4 = `${common}
8906
-
8907
- // Unprefixed uniforms
8908
- uniform mat4 modelMatrix;
8909
- uniform mat4 viewMatrix;
8910
- uniform mat4 projectionMatrix;
8911
- uniform mat4 viewProjectionMatrix;
8912
- uniform vec3 cameraPositionWorld;
8913
-
8914
- struct World {
8915
- vec3 position;
8916
- vec3 normal;
8917
- };
8918
-
8919
- World world;
8920
-
8921
- void project_setPosition(vec4 position) {
8922
- project_vPositionWorld = position;
8923
- }
8924
-
8925
- void project_setNormal(vec3 normal) {
8926
- project_vNormalWorld = normal;
8927
- }
8928
-
8929
- void project_setPositionAndNormal_World(vec3 position, vec3 normal) {
8930
- world.position = position;
8931
- world.normal = normal;
8932
- }
8933
-
8934
- void project_setPositionAndNormal_Model(vec3 position, vec3 normal) {
8935
- world.position = (modelMatrix * vec4(position, 1.)).xyz;
8936
- world.normal = mat3(modelMatrix) * normal;
8937
- }
8938
-
8939
- vec4 project_model_to_clipspace(vec4 position) {
8940
- return viewProjectionMatrix * modelMatrix * position;
8941
- }
8942
-
8943
- vec4 project_model_to_clipspace(vec3 position) {
8944
- return viewProjectionMatrix * modelMatrix * vec4(position, 1.);
8945
- }
8946
-
8947
- vec4 project_world_to_clipspace(vec3 position) {
8948
- return viewProjectionMatrix * vec4(position, 1.);
8949
- }
8950
-
8951
- vec4 project_view_to_clipspace(vec3 position) {
8952
- return projectionMatrix * vec4(position, 1.);
8953
- }
8954
-
8955
- vec4 project_to_clipspace(vec3 position) {
8956
- return viewProjectionMatrix * vec4(position, 1.);
8957
- }
8958
- `;
8959
- var fs5 = `
8960
- ${common}`;
8961
- var project = {
8962
- name: "project",
8963
- getUniforms: getUniforms4,
8964
- vs: vs4,
8965
- fs: fs5
8966
- };
8967
-
8968
- // src/modules-webgl1/lighting/lights/lights-glsl.ts
8969
- var lightingShader = (
8970
- /* glsl */
8971
- `#if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
8972
-
8973
- struct AmbientLight {
8974
- vec3 color;
8975
- };
8976
-
8977
- struct PointLight {
8978
- vec3 color;
8979
- vec3 position;
8980
-
8981
- // Constant-Linear-Exponential
8982
- vec3 attenuation;
8983
- };
8984
-
8985
- struct DirectionalLight {
8986
- vec3 color;
8987
- vec3 direction;
7114
+ // src/modules/lighting/pbr-material/pbr-material-wgsl.ts
7115
+ var source2 = (
7116
+ /* wgsl */
7117
+ `struct PBRFragmentInputs = {
7118
+ pbr_vPosition: vec3f;
7119
+ pbr_vUV: vec2f;
7120
+ pbr_vTBN: mat3f;
7121
+ pbr_vNormal: vec3f;
8988
7122
  };
8989
7123
 
8990
- uniform AmbientLight lighting_uAmbientLight;
8991
- uniform PointLight lighting_uPointLight[MAX_LIGHTS];
8992
- uniform DirectionalLight lighting_uDirectionalLight[MAX_LIGHTS];
8993
- uniform int lighting_uPointLightCount;
8994
- uniform int lighting_uDirectionalLightCount;
8995
-
8996
- uniform bool lighting_uEnabled;
8997
-
8998
- float getPointLightAttenuation(PointLight pointLight, float distance) {
8999
- return pointLight.attenuation.x
9000
- + pointLight.attenuation.y * distance
9001
- + pointLight.attenuation.z * distance * distance;
9002
- }
9003
-
9004
- #endif
9005
- `
9006
- );
9007
-
9008
- // src/modules-webgl1/lighting/lights/lights.ts
9009
- var INITIAL_MODULE_OPTIONS = {
9010
- lightSources: {}
9011
- };
9012
- function convertColor2(colorDef = {}) {
9013
- const { color = [0, 0, 0], intensity = 1 } = colorDef;
9014
- return color.map((component) => component * intensity / 255);
9015
- }
9016
- function getLightSourceUniforms2({
9017
- ambientLight,
9018
- pointLights = [],
9019
- directionalLights = []
9020
- }) {
9021
- const lightSourceUniforms = {};
9022
- if (ambientLight) {
9023
- lightSourceUniforms["lighting_uAmbientLight.color"] = convertColor2(ambientLight);
9024
- } else {
9025
- lightSourceUniforms["lighting_uAmbientLight.color"] = [0, 0, 0];
9026
- }
9027
- pointLights.forEach((pointLight, index) => {
9028
- lightSourceUniforms[`lighting_uPointLight[${index}].color`] = convertColor2(pointLight);
9029
- lightSourceUniforms[`lighting_uPointLight[${index}].position`] = pointLight.position;
9030
- lightSourceUniforms[`lighting_uPointLight[${index}].attenuation`] = pointLight.attenuation || [
9031
- 1,
9032
- 0,
9033
- 0
9034
- ];
9035
- });
9036
- lightSourceUniforms.lighting_uPointLightCount = pointLights.length;
9037
- directionalLights.forEach((directionalLight, index) => {
9038
- lightSourceUniforms[`lighting_uDirectionalLight[${index}].color`] = convertColor2(directionalLight);
9039
- lightSourceUniforms[`lighting_uDirectionalLight[${index}].direction`] = directionalLight.direction;
9040
- });
9041
- lightSourceUniforms.lighting_uDirectionalLightCount = directionalLights.length;
9042
- return lightSourceUniforms;
9043
- }
9044
- function getUniforms5(opts = INITIAL_MODULE_OPTIONS) {
9045
- if ("lightSources" in opts) {
9046
- const { ambientLight, pointLights, directionalLights } = opts.lightSources || {};
9047
- const hasLights = ambientLight || pointLights && pointLights.length > 0 || directionalLights && directionalLights.length > 0;
9048
- if (!hasLights) {
9049
- return { lighting_uEnabled: false };
9050
- }
9051
- return Object.assign(
9052
- {},
9053
- getLightSourceUniforms2({ ambientLight, pointLights, directionalLights }),
9054
- {
9055
- lighting_uEnabled: true
9056
- }
9057
- );
9058
- }
9059
- if ("lights" in opts) {
9060
- const lightSources = { pointLights: [], directionalLights: [] };
9061
- for (const light of opts.lights || []) {
9062
- switch (light.type) {
9063
- case "ambient":
9064
- lightSources.ambientLight = light;
9065
- break;
9066
- case "directional":
9067
- lightSources.directionalLights?.push(light);
9068
- break;
9069
- case "point":
9070
- lightSources.pointLights?.push(light);
9071
- break;
9072
- default:
9073
- }
9074
- }
9075
- return getUniforms5({ lightSources });
9076
- }
9077
- return {};
9078
- }
9079
- var lights = {
9080
- name: "lights",
9081
- vs: lightingShader,
9082
- fs: lightingShader,
9083
- getUniforms: getUniforms5,
9084
- defines: {
9085
- MAX_LIGHTS: 3
9086
- }
9087
- };
9088
-
9089
- // src/modules-webgl1/lighting/dirlight/dirlight.ts
9090
- var DEFAULT_MODULE_OPTIONS2 = {
9091
- lightDirection: new Float32Array([1, 1, 2])
9092
- };
9093
- function getUniforms6(opts = DEFAULT_MODULE_OPTIONS2) {
9094
- const uniforms = {};
9095
- if (opts.lightDirection) {
9096
- uniforms.dirlight_uLightDirection = opts.lightDirection;
9097
- }
9098
- return uniforms;
9099
- }
9100
- var fs6 = (
9101
- /* glsl */
9102
- `uniform vec3 dirlight_uLightDirection;
9103
-
9104
- /*
9105
- * Returns color attenuated by angle from light source
9106
- */
9107
- vec4 dirlight_filterColor(vec4 color) {
9108
- vec3 normal = project_getNormal_World();
9109
- float d = abs(dot(normalize(normal), normalize(dirlight_uLightDirection)));
9110
- return vec4(color.rgb * d, color.a);
9111
- }
9112
- `
9113
- );
9114
- var dirlight2 = {
9115
- name: "dirlight",
9116
- // vs // TODO - reuse normal from geometry module
9117
- fs: fs6,
9118
- getUniforms: getUniforms6,
9119
- dependencies: [project]
9120
- };
9121
-
9122
- // src/modules-webgl1/lighting/phong-lighting/phong-lighting-glsl.ts
9123
- var lightingShader2 = (
9124
- /* glsl */
9125
- `
9126
- uniform float lighting_uAmbient;
9127
- uniform float lighting_uDiffuse;
9128
- uniform float lighting_uShininess;
9129
- uniform vec3 lighting_uSpecularColor;
9130
-
9131
- vec3 lighting_getLightColor(vec3 surfaceColor, vec3 light_direction, vec3 view_direction, vec3 normal_worldspace, vec3 color) {
9132
- vec3 halfway_direction = normalize(light_direction + view_direction);
9133
- float lambertian = dot(light_direction, normal_worldspace);
9134
- float specular = 0.0;
9135
- if (lambertian > 0.0) {
9136
- float specular_angle = max(dot(normal_worldspace, halfway_direction), 0.0);
9137
- specular = pow(specular_angle, lighting_uShininess);
9138
- }
9139
- lambertian = max(lambertian, 0.0);
9140
- return (lambertian * lighting_uDiffuse * surfaceColor + specular * lighting_uSpecularColor) * color;
9141
- }
9142
-
9143
- vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
9144
- vec3 lightColor = surfaceColor;
9145
-
9146
- if (lighting_uEnabled) {
9147
- vec3 view_direction = normalize(cameraPosition - position_worldspace);
9148
- lightColor = lighting_uAmbient * surfaceColor * lighting_uAmbientLight.color;
9149
-
9150
- for (int i = 0; i < MAX_LIGHTS; i++) {
9151
- if (i >= lighting_uPointLightCount) {
9152
- break;
9153
- }
9154
- PointLight pointLight = lighting_uPointLight[i];
9155
- vec3 light_position_worldspace = pointLight.position;
9156
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
9157
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
9158
- }
9159
-
9160
- for (int i = 0; i < MAX_LIGHTS; i++) {
9161
- if (i >= lighting_uDirectionalLightCount) {
9162
- break;
9163
- }
9164
- DirectionalLight directionalLight = lighting_uDirectionalLight[i];
9165
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
9166
- }
9167
- }
9168
- return lightColor;
9169
- }
9170
-
9171
- vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
9172
- vec3 lightColor = vec3(0, 0, 0);
9173
- vec3 surfaceColor = vec3(0, 0, 0);
9174
-
9175
- if (lighting_uEnabled) {
9176
- vec3 view_direction = normalize(cameraPosition - position_worldspace);
9177
-
9178
- for (int i = 0; i < MAX_LIGHTS; i++) {
9179
- if (i >= lighting_uPointLightCount) {
9180
- break;
9181
- }
9182
- PointLight pointLight = lighting_uPointLight[i];
9183
- vec3 light_position_worldspace = pointLight.position;
9184
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
9185
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
9186
- }
9187
-
9188
- for (int i = 0; i < MAX_LIGHTS; i++) {
9189
- if (i >= lighting_uDirectionalLightCount) {
9190
- break;
9191
- }
9192
- DirectionalLight directionalLight = lighting_uDirectionalLight[i];
9193
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
9194
- }
9195
- }
9196
- return lightColor;
9197
- }
9198
- `
9199
- );
9200
-
9201
- // src/modules-webgl1/lighting/phong-lighting/phong-lighting.ts
9202
- var INITIAL_MODULE_OPTIONS2 = {};
9203
- function getMaterialUniforms(material) {
9204
- const { ambient = 0.35, diffuse = 0.6, shininess = 32, specularColor = [30, 30, 30] } = material;
9205
- return {
9206
- lighting_uAmbient: ambient,
9207
- lighting_uDiffuse: diffuse,
9208
- lighting_uShininess: shininess,
9209
- lighting_uSpecularColor: specularColor.map((x) => x / 255)
9210
- };
9211
- }
9212
- function getUniforms7(opts = INITIAL_MODULE_OPTIONS2) {
9213
- if (!("material" in opts)) {
9214
- return {};
9215
- }
9216
- const { material } = opts;
9217
- if (!material) {
9218
- return { lighting_uEnabled: false };
9219
- }
9220
- return getMaterialUniforms(material);
9221
- }
9222
- var gouraudLighting = {
9223
- name: "gouraud-lighting",
9224
- dependencies: [lights],
9225
- vs: lightingShader2,
9226
- defines: {
9227
- LIGHTING_VERTEX: 1
9228
- },
9229
- getUniforms: getUniforms7
9230
- };
9231
- var phongLighting = {
9232
- name: "phong-lighting",
9233
- dependencies: [lights],
9234
- fs: lightingShader2,
9235
- defines: {
9236
- LIGHTING_FRAGMENT: 1
9237
- },
9238
- getUniforms: getUniforms7
9239
- };
9240
-
9241
- // src/modules-webgl1/lighting/pbr/pbr-vertex-glsl.ts
9242
- var vs5 = (
9243
- /* glsl */
9244
- `uniform mat4 u_MVPMatrix;
9245
- uniform mat4 u_ModelMatrix;
9246
- uniform mat4 u_NormalMatrix;
9247
-
9248
- out vec3 pbr_vPosition;
9249
- out vec2 pbr_vUV;
7124
+ var fragmentInputs: PBRFragmentInputs;
9250
7125
 
9251
- #ifdef HAS_NORMALS
9252
- # ifdef HAS_TANGENTS
9253
- out mat3 pbr_vTBN;
9254
- # else
9255
- out vec3 pbr_vNormal;
9256
- # endif
9257
- #endif
9258
-
9259
- void pbr_setPositionNormalTangentUV(vec4 position, vec4 normal, vec4 tangent, vec2 uv)
7126
+ fn pbr_setPositionNormalTangentUV(position: vec4f, normal: vec4f, tangent: vec4f, vec2 uv)
9260
7127
  {
9261
- vec4 pos = u_ModelMatrix * position;
7128
+ pos: vec4f = pbrProjection.modelMatrix * position;
9262
7129
  pbr_vPosition = vec3(pos.xyz) / pos.w;
9263
7130
 
9264
7131
  #ifdef HAS_NORMALS
9265
7132
  #ifdef HAS_TANGENTS
9266
- vec3 normalW = normalize(vec3(u_NormalMatrix * vec4(normal.xyz, 0.0)));
9267
- vec3 tangentW = normalize(vec3(u_ModelMatrix * vec4(tangent.xyz, 0.0)));
9268
- vec3 bitangentW = cross(normalW, tangentW) * tangent.w;
9269
- pbr_vTBN = mat3(tangentW, bitangentW, normalW);
7133
+ let normalW: vec3f = normalize(vec3(pbrProjection.normalMatrix * vec4(normal.xyz, 0.0)));
7134
+ let tangentW: vec3f = normalize(vec3(pbrProjection.modelMatrix * vec4(tangent.xyz, 0.0)));
7135
+ let bitangentW: vec3f = cross(normalW, tangentW) * tangent.w;
7136
+ fragmentInputs,pbr_vTBN = mat3(tangentW, bitangentW, normalW);
9270
7137
  #else // HAS_TANGENTS != 1
9271
- pbr_vNormal = normalize(vec3(u_ModelMatrix * vec4(normal.xyz, 0.0)));
7138
+ fragmentInputs.pbr_vNormal = normalize(vec3(pbrProjection.modelMatrix * vec4(normal.xyz, 0.0)));
9272
7139
  #endif
9273
7140
  #endif
9274
7141
 
@@ -9278,84 +7145,77 @@ void pbr_setPositionNormalTangentUV(vec4 position, vec4 normal, vec4 tangent, ve
9278
7145
  pbr_vUV = vec2(0.,0.);
9279
7146
  #endif
9280
7147
  }
9281
- `
9282
- );
9283
7148
 
9284
- // src/modules-webgl1/lighting/pbr/pbr-fragment-glsl.ts
9285
- var fs7 = (
9286
- /* glsl */
9287
- `precision highp float;
7149
+ uniform pbrMaterialUniforms {
7150
+ // Material is unlit
7151
+ unlit: uint32;
9288
7152
 
9289
- uniform bool pbr_uUnlit;
7153
+ // Base color map
7154
+ baseColorMapEnabled: uint32;
7155
+ baseColorFactor: vec4f;
9290
7156
 
9291
- #ifdef USE_IBL
9292
- uniform samplerCube u_DiffuseEnvSampler;
9293
- uniform samplerCube u_SpecularEnvSampler;
9294
- uniform sampler2D u_brdfLUT;
9295
- uniform vec2 u_ScaleIBLAmbient;
9296
- #endif
7157
+ normalMapEnabled : uint32
7158
+ normalScale: f32; // #ifdef HAS_NORMALMAP
7159
+
7160
+ emissiveMapEnabled: uint32;
7161
+ vec3 emissiveFactor; // #ifdef HAS_EMISSIVEMAP
9297
7162
 
7163
+ vec2 metallicRoughnessValues;
7164
+ metallicRoughnessMapEnabled: uint32;
7165
+
7166
+ occlusionMapEnabled: uint32;
7167
+ occlusionStrength: f32; // #ifdef HAS_OCCLUSIONMAP
7168
+
7169
+ alphaCutoffEnabled: uint32;
7170
+ alphaCutoff: f32; // #ifdef ALPHA_CUTOFF
7171
+
7172
+ // IBL
7173
+ IBLenabled: uint32;
7174
+ vec2 scaleIBLAmbient; // #ifdef USE_IBL
7175
+
7176
+ // debugging flags used for shader output of intermediate PBR variables
7177
+ // #ifdef PBR_DEBUG
7178
+ scaleDiffBaseMR: vec4f;
7179
+ scaleFGDSpec: vec4f;
7180
+ // #endif
7181
+ } pbrMaterial;
7182
+
7183
+ // Samplers
9298
7184
  #ifdef HAS_BASECOLORMAP
9299
- uniform sampler2D u_BaseColorSampler;
7185
+ uniform sampler2D pbr_baseColorSampler;
9300
7186
  #endif
9301
7187
  #ifdef HAS_NORMALMAP
9302
- uniform sampler2D u_NormalSampler;
9303
- uniform float u_NormalScale;
7188
+ uniform sampler2D pbr_normalSampler;
9304
7189
  #endif
9305
7190
  #ifdef HAS_EMISSIVEMAP
9306
- uniform sampler2D u_EmissiveSampler;
9307
- uniform vec3 u_EmissiveFactor;
7191
+ uniform sampler2D pbr_emissiveSampler;
9308
7192
  #endif
9309
7193
  #ifdef HAS_METALROUGHNESSMAP
9310
- uniform sampler2D u_MetallicRoughnessSampler;
7194
+ uniform sampler2D pbr_metallicRoughnessSampler;
9311
7195
  #endif
9312
7196
  #ifdef HAS_OCCLUSIONMAP
9313
- uniform sampler2D u_OcclusionSampler;
9314
- uniform float u_OcclusionStrength;
9315
- #endif
9316
-
9317
- #ifdef ALPHA_CUTOFF
9318
- uniform float u_AlphaCutoff;
9319
- #endif
9320
-
9321
- uniform vec2 u_MetallicRoughnessValues;
9322
- uniform vec4 u_BaseColorFactor;
9323
-
9324
- uniform vec3 u_Camera;
9325
-
9326
- // debugging flags used for shader output of intermediate PBR variables
9327
- #ifdef PBR_DEBUG
9328
- uniform vec4 u_ScaleDiffBaseMR;
9329
- uniform vec4 u_ScaleFGDSpec;
9330
- #endif
9331
-
9332
- in vec3 pbr_vPosition;
9333
-
9334
- in vec2 pbr_vUV;
9335
-
9336
- #ifdef HAS_NORMALS
9337
- #ifdef HAS_TANGENTS
9338
- in mat3 pbr_vTBN;
9339
- #else
9340
- in vec3 pbr_vNormal;
7197
+ uniform sampler2D pbr_occlusionSampler;
9341
7198
  #endif
7199
+ #ifdef USE_IBL
7200
+ uniform samplerCube pbr_diffuseEnvSampler;
7201
+ uniform samplerCube pbr_specularEnvSampler;
7202
+ uniform sampler2D pbr_brdfLUT;
9342
7203
  #endif
9343
7204
 
9344
7205
  // Encapsulate the various inputs used by the various functions in the shading equation
9345
7206
  // We store values in this struct to simplify the integration of alternative implementations
9346
7207
  // of the shading terms, outlined in the Readme.MD Appendix.
9347
- struct PBRInfo
9348
- {
9349
- float NdotL; // cos angle between normal and light direction
9350
- float NdotV; // cos angle between normal and view direction
9351
- float NdotH; // cos angle between normal and half vector
9352
- float LdotH; // cos angle between light direction and half vector
9353
- float VdotH; // cos angle between view direction and half vector
9354
- float perceptualRoughness; // roughness value, as authored by the model creator (input to shader)
9355
- float metalness; // metallic value at the surface
7208
+ struct PBRInfo {
7209
+ NdotL: f32; // cos angle between normal and light direction
7210
+ NdotV: f32; // cos angle between normal and view direction
7211
+ NdotH: f32; // cos angle between normal and half vector
7212
+ LdotH: f32; // cos angle between light direction and half vector
7213
+ VdotH: f32; // cos angle between view direction and half vector
7214
+ perceptualRoughness: f32; // roughness value, as authored by the model creator (input to shader)
7215
+ metalness: f32; // metallic value at the surface
9356
7216
  vec3 reflectance0; // full reflectance color (normal incidence angle)
9357
7217
  vec3 reflectance90; // reflectance color at grazing angle
9358
- float alphaRoughness; // roughness mapped to a more linear change in the roughness (proposed by [2])
7218
+ alphaRoughness: f32; // roughness mapped to a more linear change in the roughness (proposed by [2])
9359
7219
  vec3 diffuseColor; // color contribution from diffuse lighting
9360
7220
  vec3 specularColor; // color contribution from specular lighting
9361
7221
  vec3 n; // normal at surface point
@@ -9370,7 +7230,7 @@ vec4 SRGBtoLINEAR(vec4 srgbIn)
9370
7230
  #ifdef MANUAL_SRGB
9371
7231
  #ifdef SRGB_FAST_APPROXIMATION
9372
7232
  vec3 linOut = pow(srgbIn.xyz,vec3(2.2));
9373
- #else //SRGB_FAST_APPROXIMATION
7233
+ #else // SRGB_FAST_APPROXIMATION
9374
7234
  vec3 bLess = step(vec3(0.04045),srgbIn.xyz);
9375
7235
  vec3 linOut = mix( srgbIn.xyz/vec3(12.92), pow((srgbIn.xyz+vec3(0.055))/vec3(1.055),vec3(2.4)), bLess );
9376
7236
  #endif //SRGB_FAST_APPROXIMATION
@@ -9406,8 +7266,8 @@ vec3 getNormal()
9406
7266
  #endif
9407
7267
 
9408
7268
  #ifdef HAS_NORMALMAP
9409
- vec3 n = texture(u_NormalSampler, pbr_vUV).rgb;
9410
- n = normalize(tbn * ((2.0 * n - 1.0) * vec3(u_NormalScale, u_NormalScale, 1.0)));
7269
+ vec3 n = texture(pbr_normalSampler, pbr_vUV).rgb;
7270
+ n = normalize(tbn * ((2.0 * n - 1.0) * vec3(pbrMaterial.normalScale, pbrMaterial.normalScale, 1.0)));
9411
7271
  #else
9412
7272
  // The tbn matrix is linearly interpolated, so we need to re-normalize
9413
7273
  vec3 n = normalize(tbn[2].xyz);
@@ -9420,27 +7280,27 @@ vec3 getNormal()
9420
7280
  // Precomputed Environment Maps are required uniform inputs and are computed as outlined in [1].
9421
7281
  // See our README.md on Environment Maps [3] for additional discussion.
9422
7282
  #ifdef USE_IBL
9423
- vec3 getIBLContribution(PBRInfo pbrInputs, vec3 n, vec3 reflection)
7283
+ vec3 getIBLContribution(PBRInfo pbrInfo, vec3 n, vec3 reflection)
9424
7284
  {
9425
7285
  float mipCount = 9.0; // resolution of 512x512
9426
- float lod = (pbrInputs.perceptualRoughness * mipCount);
7286
+ float lod = (pbrInfo.perceptualRoughness * mipCount);
9427
7287
  // retrieve a scale and bias to F0. See [1], Figure 3
9428
- vec3 brdf = SRGBtoLINEAR(texture(u_brdfLUT,
9429
- vec2(pbrInputs.NdotV, 1.0 - pbrInputs.perceptualRoughness))).rgb;
9430
- vec3 diffuseLight = SRGBtoLINEAR(textureCube(u_DiffuseEnvSampler, n)).rgb;
7288
+ vec3 brdf = SRGBtoLINEAR(texture(pbr_brdfLUT,
7289
+ vec2(pbrInfo.NdotV, 1.0 - pbrInfo.perceptualRoughness))).rgb;
7290
+ vec3 diffuseLight = SRGBtoLINEAR(texture(pbr_diffuseEnvSampler, n)).rgb;
9431
7291
 
9432
7292
  #ifdef USE_TEX_LOD
9433
- vec3 specularLight = SRGBtoLINEAR(textureCubeLod(u_SpecularEnvSampler, reflection, lod)).rgb;
7293
+ vec3 specularLight = SRGBtoLINEAR(texture(pbr_specularEnvSampler, reflection, lod)).rgb;
9434
7294
  #else
9435
- vec3 specularLight = SRGBtoLINEAR(textureCube(u_SpecularEnvSampler, reflection)).rgb;
7295
+ vec3 specularLight = SRGBtoLINEAR(texture(pbr_specularEnvSampler, reflection)).rgb;
9436
7296
  #endif
9437
7297
 
9438
- vec3 diffuse = diffuseLight * pbrInputs.diffuseColor;
9439
- vec3 specular = specularLight * (pbrInputs.specularColor * brdf.x + brdf.y);
7298
+ vec3 diffuse = diffuseLight * pbrInfo.diffuseColor;
7299
+ vec3 specular = specularLight * (pbrInfo.specularColor * brdf.x + brdf.y);
9440
7300
 
9441
7301
  // For presentation, this allows us to disable IBL terms
9442
- diffuse *= u_ScaleIBLAmbient.x;
9443
- specular *= u_ScaleIBLAmbient.y;
7302
+ diffuse *= pbrMaterial.scaleIBLAmbient.x;
7303
+ specular *= pbrMaterial.scaleIBLAmbient.y;
9444
7304
 
9445
7305
  return diffuse + specular;
9446
7306
  }
@@ -9449,32 +7309,31 @@ vec3 getIBLContribution(PBRInfo pbrInputs, vec3 n, vec3 reflection)
9449
7309
  // Basic Lambertian diffuse
9450
7310
  // Implementation from Lambert's Photometria https://archive.org/details/lambertsphotome00lambgoog
9451
7311
  // See also [1], Equation 1
9452
- vec3 diffuse(PBRInfo pbrInputs)
7312
+ vec3 diffuse(PBRInfo pbrInfo)
9453
7313
  {
9454
- return pbrInputs.diffuseColor / M_PI;
7314
+ return pbrInfo.diffuseColor / M_PI;
9455
7315
  }
9456
7316
 
9457
7317
  // The following equation models the Fresnel reflectance term of the spec equation (aka F())
9458
7318
  // Implementation of fresnel from [4], Equation 15
9459
- vec3 specularReflection(PBRInfo pbrInputs)
7319
+ vec3 specularReflection(PBRInfo pbrInfo)
9460
7320
  {
9461
- return pbrInputs.reflectance0 +
9462
- (pbrInputs.reflectance90 - pbrInputs.reflectance0) *
9463
- pow(clamp(1.0 - pbrInputs.VdotH, 0.0, 1.0), 5.0);
7321
+ return pbrInfo.reflectance0 +
7322
+ (pbrInfo.reflectance90 - pbrInfo.reflectance0) *
7323
+ pow(clamp(1.0 - pbrInfo.VdotH, 0.0, 1.0), 5.0);
9464
7324
  }
9465
7325
 
9466
7326
  // This calculates the specular geometric attenuation (aka G()),
9467
7327
  // where rougher material will reflect less light back to the viewer.
9468
7328
  // This implementation is based on [1] Equation 4, and we adopt their modifications to
9469
7329
  // alphaRoughness as input as originally proposed in [2].
9470
- float geometricOcclusion(PBRInfo pbrInputs)
9471
- {
9472
- float NdotL = pbrInputs.NdotL;
9473
- float NdotV = pbrInputs.NdotV;
9474
- float r = pbrInputs.alphaRoughness;
7330
+ fn geometricOcclusion(PBRInfo pbrInfo) -> f32 {
7331
+ let NdotL: f32 = pbrInfo.NdotL;
7332
+ let NdotV: f32 = pbrInfo.NdotV;
7333
+ let r: f32 = pbrInfo.alphaRoughness;
9475
7334
 
9476
- float attenuationL = 2.0 * NdotL / (NdotL + sqrt(r * r + (1.0 - r * r) * (NdotL * NdotL)));
9477
- float attenuationV = 2.0 * NdotV / (NdotV + sqrt(r * r + (1.0 - r * r) * (NdotV * NdotV)));
7335
+ let attenuationL = 2.0 * NdotL / (NdotL + sqrt(r * r + (1.0 - r * r) * (NdotL * NdotL)));
7336
+ let attenuationV = 2.0 * NdotV / (NdotV + sqrt(r * r + (1.0 - r * r) * (NdotV * NdotV)));
9478
7337
  return attenuationL * attenuationV;
9479
7338
  }
9480
7339
 
@@ -9484,80 +7343,79 @@ float geometricOcclusion(PBRInfo pbrInputs)
9484
7343
  // for Ray Reflection" by T. S. Trowbridge, and K. P. Reitz
9485
7344
  // Follows the distribution function recommended in the SIGGRAPH 2013 course notes
9486
7345
  // from EPIC Games [1], Equation 3.
9487
- float microfacetDistribution(PBRInfo pbrInputs)
9488
- {
9489
- float roughnessSq = pbrInputs.alphaRoughness * pbrInputs.alphaRoughness;
9490
- float f = (pbrInputs.NdotH * roughnessSq - pbrInputs.NdotH) * pbrInputs.NdotH + 1.0;
7346
+ fn microfacetDistribution(PBRInfo pbrInfo) -> float {
7347
+ float roughnessSq = pbrInfo.alphaRoughness * pbrInfo.alphaRoughness;
7348
+ float f = (pbrInfo.NdotH * roughnessSq - pbrInfo.NdotH) * pbrInfo.NdotH + 1.0;
9491
7349
  return roughnessSq / (M_PI * f * f);
9492
7350
  }
9493
7351
 
9494
- void PBRInfo_setAmbientLight(inout PBRInfo pbrInputs) {
9495
- pbrInputs.NdotL = 1.0;
9496
- pbrInputs.NdotH = 0.0;
9497
- pbrInputs.LdotH = 0.0;
9498
- pbrInputs.VdotH = 1.0;
7352
+ fn PBRInfo_setAmbientLight(inout pbrInfo: PBRInfo) {
7353
+ pbrInfo.NdotL = 1.0;
7354
+ pbrInfo.NdotH = 0.0;
7355
+ pbrInfo.LdotH = 0.0;
7356
+ pbrInfo.VdotH = 1.0;
9499
7357
  }
9500
7358
 
9501
- void PBRInfo_setDirectionalLight(inout PBRInfo pbrInputs, vec3 lightDirection) {
9502
- vec3 n = pbrInputs.n;
9503
- vec3 v = pbrInputs.v;
7359
+ fb PBRInfo_setDirectionalLight(inout PBRInfo pbrInfo, vec3 lightDirection) {
7360
+ vec3 n = pbrInfo.n;
7361
+ vec3 v = pbrInfo.v;
9504
7362
  vec3 l = normalize(lightDirection); // Vector from surface point to light
9505
7363
  vec3 h = normalize(l+v); // Half vector between both l and v
9506
7364
 
9507
- pbrInputs.NdotL = clamp(dot(n, l), 0.001, 1.0);
9508
- pbrInputs.NdotH = clamp(dot(n, h), 0.0, 1.0);
9509
- pbrInputs.LdotH = clamp(dot(l, h), 0.0, 1.0);
9510
- pbrInputs.VdotH = clamp(dot(v, h), 0.0, 1.0);
7365
+ pbrInfo.NdotL = clamp(dot(n, l), 0.001, 1.0);
7366
+ pbrInfo.NdotH = clamp(dot(n, h), 0.0, 1.0);
7367
+ pbrInfo.LdotH = clamp(dot(l, h), 0.0, 1.0);
7368
+ pbrInfo.VdotH = clamp(dot(v, h), 0.0, 1.0);
9511
7369
  }
9512
7370
 
9513
- void PBRInfo_setPointLight(inout PBRInfo pbrInputs, PointLight pointLight) {
7371
+ fn PBRInfo_setPointLight(inout pbrInfo: PBRInfo, pointLight: PointLight) {
9514
7372
  vec3 light_direction = normalize(pointLight.position - pbr_vPosition);
9515
- PBRInfo_setDirectionalLight(pbrInputs, light_direction);
7373
+ PBRInfo_setDirectionalLight(pbrInfo, light_direction);
9516
7374
  }
9517
7375
 
9518
- vec3 calculateFinalColor(PBRInfo pbrInputs, vec3 lightColor) {
7376
+ fn calculateFinalColor(pbrInfo: PBRInfo , lightColor: vec3f) -> vec3f {
9519
7377
  // Calculate the shading terms for the microfacet specular shading model
9520
- vec3 F = specularReflection(pbrInputs);
9521
- float G = geometricOcclusion(pbrInputs);
9522
- float D = microfacetDistribution(pbrInputs);
7378
+ let F: vec3f = specularReflection(pbrInfo);
7379
+ let G: vec3f = geometricOcclusion(pbrInfo);
7380
+ let D: vec3f = microfacetDistribution(pbrInfo);
9523
7381
 
9524
7382
  // Calculation of analytical lighting contribution
9525
- vec3 diffuseContrib = (1.0 - F) * diffuse(pbrInputs);
9526
- vec3 specContrib = F * G * D / (4.0 * pbrInputs.NdotL * pbrInputs.NdotV);
7383
+ let diffuseContrib: vec3f = (1.0 - F) * diffuse(pbrInfo);
7384
+ let specContrib: vec3f = F * G * D / (4.0 * pbrInfo.NdotL * pbrInfo.NdotV);
9527
7385
  // Obtain final intensity as reflectance (BRDF) scaled by the energy of the light (cosine law)
9528
- return pbrInputs.NdotL * lightColor * (diffuseContrib + specContrib);
7386
+ return pbrInfo.NdotL * lightColor * (diffuseContrib + specContrib);
9529
7387
  }
9530
7388
 
9531
- vec4 pbr_filterColor(vec4 colorUnused)
7389
+ fn pbr_filterColor(colorUnused: vec4f) -> vec4f
9532
7390
  {
9533
7391
  // The albedo may be defined from a base texture or a flat color
9534
7392
  #ifdef HAS_BASECOLORMAP
9535
- vec4 baseColor = SRGBtoLINEAR(texture(u_BaseColorSampler, pbr_vUV)) * u_BaseColorFactor;
7393
+ vec4 baseColor = SRGBtoLINEAR(texture(pbr_baseColorSampler, pbr_vUV)) * pbrMaterial.baseColorFactor;
9536
7394
  #else
9537
- vec4 baseColor = u_BaseColorFactor;
7395
+ vec4 baseColor = pbrMaterial.baseColorFactor;
9538
7396
  #endif
9539
7397
 
9540
7398
  #ifdef ALPHA_CUTOFF
9541
- if (baseColor.a < u_AlphaCutoff) {
7399
+ if (baseColor.a < pbrMaterial.alphaCutoff) {
9542
7400
  discard;
9543
7401
  }
9544
7402
  #endif
9545
7403
 
9546
7404
  vec3 color = vec3(0, 0, 0);
9547
7405
 
9548
- if(pbr_uUnlit){
7406
+ if(pbrMaterial.unlit){
9549
7407
  color.rgb = baseColor.rgb;
9550
7408
  }
9551
7409
  else{
9552
7410
  // Metallic and Roughness material properties are packed together
9553
7411
  // In glTF, these factors can be specified by fixed scalar values
9554
7412
  // or from a metallic-roughness map
9555
- float perceptualRoughness = u_MetallicRoughnessValues.y;
9556
- float metallic = u_MetallicRoughnessValues.x;
7413
+ float perceptualRoughness = pbrMaterial.metallicRoughnessValues.y;
7414
+ float metallic = pbrMaterial.metallicRoughnessValues.x;
9557
7415
  #ifdef HAS_METALROUGHNESSMAP
9558
7416
  // Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.
9559
7417
  // This layout intentionally reserves the 'r' channel for (optional) occlusion map data
9560
- vec4 mrSample = texture(u_MetallicRoughnessSampler, pbr_vUV);
7418
+ vec4 mrSample = texture(pbr_metallicRoughnessSampler, pbr_vUV);
9561
7419
  perceptualRoughness = mrSample.g * perceptualRoughness;
9562
7420
  metallic = mrSample.b * metallic;
9563
7421
  #endif
@@ -9584,12 +7442,12 @@ vec4 pbr_filterColor(vec4 colorUnused)
9584
7442
  vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90;
9585
7443
 
9586
7444
  vec3 n = getNormal(); // normal at surface point
9587
- vec3 v = normalize(u_Camera - pbr_vPosition); // Vector from surface point to camera
7445
+ vec3 v = normalize(pbrProjection.camera - pbr_vPosition); // Vector from surface point to camera
9588
7446
 
9589
7447
  float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);
9590
7448
  vec3 reflection = -normalize(reflect(v, n));
9591
7449
 
9592
- PBRInfo pbrInputs = PBRInfo(
7450
+ PBRInfo pbrInfo = PBRInfo(
9593
7451
  0.0, // NdotL
9594
7452
  NdotV,
9595
7453
  0.0, // NdotH
@@ -9608,41 +7466,47 @@ vec4 pbr_filterColor(vec4 colorUnused)
9608
7466
 
9609
7467
  #ifdef USE_LIGHTS
9610
7468
  // Apply ambient light
9611
- PBRInfo_setAmbientLight(pbrInputs);
9612
- color += calculateFinalColor(pbrInputs, lighting_uAmbientLight.color);
7469
+ PBRInfo_setAmbientLight(pbrInfo);
7470
+ color += calculateFinalColor(pbrInfo, lighting.ambientColor);
9613
7471
 
9614
7472
  // Apply directional light
9615
- for(int i = 0; i < lighting_uDirectionalLightCount; i++) {
9616
- if (i < lighting_uDirectionalLightCount) {
9617
- PBRInfo_setDirectionalLight(pbrInputs, lighting_uDirectionalLight[i].direction);
9618
- color += calculateFinalColor(pbrInputs, lighting_uDirectionalLight[i].color);
7473
+ for(int i = 0; i < lighting.directionalLightCount; i++) {
7474
+ if (i < lighting.directionalLightCount) {
7475
+ PBRInfo_setDirectionalLight(pbrInfo, lighting_getDirectionalLight(i).direction);
7476
+ color += calculateFinalColor(pbrInfo, lighting_getDirectionalLight(i).color);
9619
7477
  }
9620
7478
  }
9621
7479
 
9622
7480
  // Apply point light
9623
- for(int i = 0; i < lighting_uPointLightCount; i++) {
9624
- if (i < lighting_uPointLightCount) {
9625
- PBRInfo_setPointLight(pbrInputs, lighting_uPointLight[i]);
9626
- float attenuation = getPointLightAttenuation(lighting_uPointLight[i], distance(lighting_uPointLight[i].position, pbr_vPosition));
9627
- color += calculateFinalColor(pbrInputs, lighting_uPointLight[i].color / attenuation);
7481
+ for(int i = 0; i < lighting.pointLightCount; i++) {
7482
+ if (i < lighting.pointLightCount) {
7483
+ PBRInfo_setPointLight(pbrInfo, lighting_getPointLight(i));
7484
+ float attenuation = getPointLightAttenuation(lighting_getPointLight(i), distance(lighting_getPointLight(i).position, pbr_vPosition));
7485
+ color += calculateFinalColor(pbrInfo, lighting_getPointLight(i).color / attenuation);
9628
7486
  }
9629
7487
  }
9630
7488
  #endif
9631
7489
 
9632
7490
  // Calculate lighting contribution from image based lighting source (IBL)
9633
7491
  #ifdef USE_IBL
9634
- color += getIBLContribution(pbrInputs, n, reflection);
7492
+ if (pbrMaterial.IBLenabled) {
7493
+ color += getIBLContribution(pbrInfo, n, reflection);
7494
+ }
9635
7495
  #endif
9636
7496
 
9637
- // Apply optional PBR terms for additional (optional) shading
7497
+ // Apply optional PBR terms for additional (optional) shading
9638
7498
  #ifdef HAS_OCCLUSIONMAP
9639
- float ao = texture(u_OcclusionSampler, pbr_vUV).r;
9640
- color = mix(color, color * ao, u_OcclusionStrength);
7499
+ if (pbrMaterial.occlusionMapEnabled) {
7500
+ float ao = texture(pbr_occlusionSampler, pbr_vUV).r;
7501
+ color = mix(color, color * ao, pbrMaterial.occlusionStrength);
7502
+ }
9641
7503
  #endif
9642
7504
 
9643
7505
  #ifdef HAS_EMISSIVEMAP
9644
- vec3 emissive = SRGBtoLINEAR(texture(u_EmissiveSampler, pbr_vUV)).rgb * u_EmissiveFactor;
9645
- color += emissive;
7506
+ if (pbrMaterial.emissiveMapEnabled) {
7507
+ vec3 emissive = SRGBtoLINEAR(texture(pbr_emissiveSampler, pbr_vUV)).rgb * pbrMaterial.emissiveFactor;
7508
+ color += emissive;
7509
+ }
9646
7510
  #endif
9647
7511
 
9648
7512
  // This section uses mix to override final color for reference app visualization
@@ -9650,15 +7514,15 @@ vec4 pbr_filterColor(vec4 colorUnused)
9650
7514
  #ifdef PBR_DEBUG
9651
7515
  // TODO: Figure out how to debug multiple lights
9652
7516
 
9653
- // color = mix(color, F, u_ScaleFGDSpec.x);
9654
- // color = mix(color, vec3(G), u_ScaleFGDSpec.y);
9655
- // color = mix(color, vec3(D), u_ScaleFGDSpec.z);
9656
- // color = mix(color, specContrib, u_ScaleFGDSpec.w);
7517
+ // color = mix(color, F, pbr_scaleFGDSpec.x);
7518
+ // color = mix(color, vec3(G), pbr_scaleFGDSpec.y);
7519
+ // color = mix(color, vec3(D), pbr_scaleFGDSpec.z);
7520
+ // color = mix(color, specContrib, pbr_scaleFGDSpec.w);
9657
7521
 
9658
- // color = mix(color, diffuseContrib, u_ScaleDiffBaseMR.x);
9659
- color = mix(color, baseColor.rgb, u_ScaleDiffBaseMR.y);
9660
- color = mix(color, vec3(metallic), u_ScaleDiffBaseMR.z);
9661
- color = mix(color, vec3(perceptualRoughness), u_ScaleDiffBaseMR.w);
7522
+ // color = mix(color, diffuseContrib, pbr_scaleDiffBaseMR.x);
7523
+ color = mix(color, baseColor.rgb, pbrMaterial.scaleDiffBaseMR.y);
7524
+ color = mix(color, vec3(metallic), pbrMaterial.scaleDiffBaseMR.z);
7525
+ color = mix(color, vec3(perceptualRoughness), pbrMaterial.scaleDiffBaseMR.w);
9662
7526
  #endif
9663
7527
 
9664
7528
  }
@@ -9668,16 +7532,81 @@ vec4 pbr_filterColor(vec4 colorUnused)
9668
7532
  `
9669
7533
  );
9670
7534
 
9671
- // src/modules-webgl1/lighting/pbr/pbr.ts
9672
- var pbr = {
9673
- name: "pbr",
9674
- vs: vs5,
9675
- fs: fs7,
7535
+ // src/modules/lighting/pbr-material/pbr-projection.ts
7536
+ var uniformBlock = (
7537
+ /* glsl */
7538
+ `uniform pbrProjectionUniforms {
7539
+ mat4 modelViewProjectionMatrix;
7540
+ mat4 modelMatrix;
7541
+ mat4 normalMatrix;
7542
+ vec3 camera;
7543
+ } pbrProjection;
7544
+ `
7545
+ );
7546
+ var pbrProjection = {
7547
+ name: "pbrProjection",
7548
+ vs: uniformBlock,
7549
+ fs: uniformBlock,
7550
+ // TODO why is this needed?
7551
+ getUniforms: (props) => props,
7552
+ uniformTypes: {
7553
+ modelViewProjectionMatrix: "mat4x4<f32>",
7554
+ modelMatrix: "mat4x4<f32>",
7555
+ normalMatrix: "mat4x4<f32>",
7556
+ camera: "vec3<i32>"
7557
+ }
7558
+ };
7559
+
7560
+ // src/modules/lighting/pbr-material/pbr-material.ts
7561
+ var pbrMaterial = {
7562
+ props: {},
7563
+ uniforms: {},
7564
+ name: "pbrMaterial",
7565
+ dependencies: [lighting, pbrProjection],
7566
+ source: source2,
7567
+ vs: vs2,
7568
+ fs: fs3,
9676
7569
  defines: {
9677
- LIGHTING_FRAGMENT: 1
7570
+ LIGHTING_FRAGMENT: true,
7571
+ HAS_NORMALMAP: false,
7572
+ HAS_EMISSIVEMAP: false,
7573
+ HAS_OCCLUSIONMAP: false,
7574
+ HAS_BASECOLORMAP: false,
7575
+ HAS_METALROUGHNESSMAP: false,
7576
+ ALPHA_CUTOFF: false,
7577
+ USE_IBL: false,
7578
+ PBR_DEBUG: false
9678
7579
  },
9679
- dependencies: [lights],
9680
- getUniforms: (props) => props
7580
+ getUniforms: (props) => props,
7581
+ uniformTypes: {
7582
+ // Material is unlit
7583
+ unlit: "i32",
7584
+ // Base color map
7585
+ baseColorMapEnabled: "i32",
7586
+ baseColorFactor: "vec4<f32>",
7587
+ normalMapEnabled: "i32",
7588
+ normalScale: "f32",
7589
+ // #ifdef HAS_NORMALMAP
7590
+ emissiveMapEnabled: "i32",
7591
+ emissiveFactor: "vec3<f32>",
7592
+ // #ifdef HAS_EMISSIVEMAP
7593
+ metallicRoughnessValues: "vec2<f32>",
7594
+ metallicRoughnessMapEnabled: "i32",
7595
+ occlusionMapEnabled: "i32",
7596
+ occlusionStrength: "f32",
7597
+ // #ifdef HAS_OCCLUSIONMAP
7598
+ alphaCutoffEnabled: "i32",
7599
+ alphaCutoff: "f32",
7600
+ // #ifdef ALPHA_CUTOFF
7601
+ // IBL
7602
+ IBLenabled: "i32",
7603
+ scaleIBLAmbient: "vec2<f32>",
7604
+ // #ifdef USE_IBL
7605
+ // debugging flags used for shader output of intermediate PBR variables
7606
+ // #ifdef PBR_DEBUG
7607
+ scaleDiffBaseMR: "vec4<f32>",
7608
+ scaleFGDSpec: "vec4<f32>"
7609
+ }
9681
7610
  };
9682
7611
  return __toCommonJS(bundle_exports);
9683
7612
  })();