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