@luma.gl/shadertools 9.1.0-alpha.16 → 9.1.0-alpha.18

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 (118) hide show
  1. package/dist/dist.dev.js +277 -344
  2. package/dist/dist.min.js +215 -314
  3. package/dist/index.cjs +276 -346
  4. package/dist/index.cjs.map +4 -4
  5. package/dist/index.d.ts +4 -2
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +0 -1
  8. package/dist/lib/shader-module/shader-module.d.ts +24 -14
  9. package/dist/lib/shader-module/shader-module.d.ts.map +1 -1
  10. package/dist/lib/shader-module/shader-module.js +11 -15
  11. package/dist/lib/shader-module/shader-pass.d.ts +4 -2
  12. package/dist/lib/shader-module/shader-pass.d.ts.map +1 -1
  13. package/dist/lib/utils/uniform-types.d.ts +11 -0
  14. package/dist/lib/utils/uniform-types.d.ts.map +1 -0
  15. package/dist/lib/utils/uniform-types.js +1 -0
  16. package/dist/modules/engine/picking/picking.d.ts +7 -7
  17. package/dist/modules/engine/picking/picking.d.ts.map +1 -1
  18. package/dist/modules/engine/picking/picking.js +2 -2
  19. package/dist/modules/engine/project/project.d.ts +9 -8
  20. package/dist/modules/engine/project/project.d.ts.map +1 -1
  21. package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts +3 -57
  22. package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts.map +1 -1
  23. package/dist/modules/lighting/gouraud-material/gouraud-material.js +9 -6
  24. package/dist/modules/lighting/lights/lighting-uniforms-glsl.d.ts +1 -1
  25. package/dist/modules/lighting/lights/lighting-uniforms-glsl.d.ts.map +1 -1
  26. package/dist/modules/lighting/lights/lighting-uniforms-glsl.js +35 -12
  27. package/dist/modules/lighting/lights/lighting.d.ts +55 -29
  28. package/dist/modules/lighting/lights/lighting.d.ts.map +1 -1
  29. package/dist/modules/lighting/lights/lighting.js +46 -35
  30. package/dist/modules/lighting/no-material/dirlight.d.ts +3 -3
  31. package/dist/modules/lighting/no-material/dirlight.d.ts.map +1 -1
  32. package/dist/modules/lighting/no-material/dirlight.js +1 -1
  33. package/dist/modules/lighting/pbr-material/pbr-fragment-glsl.d.ts +1 -1
  34. package/dist/modules/lighting/pbr-material/pbr-fragment-glsl.d.ts.map +1 -1
  35. package/dist/modules/lighting/pbr-material/pbr-fragment-glsl.js +56 -60
  36. package/dist/modules/lighting/pbr-material/pbr-material.d.ts +56 -98
  37. package/dist/modules/lighting/pbr-material/pbr-material.d.ts.map +1 -1
  38. package/dist/modules/lighting/pbr-material/pbr-material.js +14 -22
  39. package/dist/modules/lighting/pbr-material/pbr-projection.d.ts +10 -0
  40. package/dist/modules/lighting/pbr-material/pbr-projection.d.ts.map +1 -0
  41. package/dist/modules/lighting/pbr-material/pbr-projection.js +24 -0
  42. package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.d.ts +1 -1
  43. package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.d.ts.map +1 -1
  44. package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.js +8 -16
  45. package/dist/modules/lighting/phong-material/phong-material.d.ts +5 -59
  46. package/dist/modules/lighting/phong-material/phong-material.d.ts.map +1 -1
  47. package/dist/modules/lighting/phong-material/phong-material.js +6 -4
  48. package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts +1 -40
  49. package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts.map +1 -1
  50. package/dist/modules/lighting/phong-material/phong-shaders-glsl.js +8 -87
  51. package/dist/modules-webgl1/project/project.d.ts +6 -4
  52. package/dist/modules-webgl1/project/project.d.ts.map +1 -1
  53. package/dist/passes/postprocessing/fxaa/fxaa.d.ts +1 -1
  54. package/dist/passes/postprocessing/fxaa/fxaa.d.ts.map +1 -1
  55. package/dist/passes/postprocessing/fxaa/fxaa.js +1 -1
  56. package/dist/passes/postprocessing/image-adjust-filters/brightnesscontrast.d.ts +0 -1
  57. package/dist/passes/postprocessing/image-adjust-filters/brightnesscontrast.d.ts.map +1 -1
  58. package/dist/passes/postprocessing/image-adjust-filters/brightnesscontrast.js +0 -1
  59. package/dist/passes/postprocessing/image-adjust-filters/huesaturation.d.ts +0 -1
  60. package/dist/passes/postprocessing/image-adjust-filters/huesaturation.d.ts.map +1 -1
  61. package/dist/passes/postprocessing/image-adjust-filters/huesaturation.js +0 -1
  62. package/dist/passes/postprocessing/image-adjust-filters/vibrance.d.ts +3 -0
  63. package/dist/passes/postprocessing/image-adjust-filters/vibrance.d.ts.map +1 -1
  64. package/dist/passes/postprocessing/image-adjust-filters/vibrance.js +3 -0
  65. package/dist/passes/postprocessing/image-blur-filters/tiltshift.d.ts +2 -2
  66. package/dist/passes/postprocessing/image-blur-filters/tiltshift.d.ts.map +1 -1
  67. package/dist/passes/postprocessing/image-blur-filters/triangleblur.d.ts +1 -1
  68. package/dist/passes/postprocessing/image-blur-filters/triangleblur.d.ts.map +1 -1
  69. package/dist/passes/postprocessing/image-blur-filters/zoomblur.d.ts +1 -1
  70. package/dist/passes/postprocessing/image-blur-filters/zoomblur.d.ts.map +1 -1
  71. package/dist/passes/postprocessing/image-fun-filters/colorhalftone.d.ts +1 -1
  72. package/dist/passes/postprocessing/image-fun-filters/colorhalftone.d.ts.map +1 -1
  73. package/dist/passes/postprocessing/image-fun-filters/dotscreen.d.ts +1 -1
  74. package/dist/passes/postprocessing/image-fun-filters/dotscreen.d.ts.map +1 -1
  75. package/dist/passes/postprocessing/image-fun-filters/edgework.d.ts +15 -11
  76. package/dist/passes/postprocessing/image-fun-filters/edgework.d.ts.map +1 -1
  77. package/dist/passes/postprocessing/image-fun-filters/edgework.js +24 -12
  78. package/dist/passes/postprocessing/image-fun-filters/hexagonalpixelate.d.ts +1 -1
  79. package/dist/passes/postprocessing/image-fun-filters/hexagonalpixelate.d.ts.map +1 -1
  80. package/dist/passes/postprocessing/image-fun-filters/magnify.d.ts +2 -2
  81. package/dist/passes/postprocessing/image-fun-filters/magnify.d.ts.map +1 -1
  82. package/dist/passes/postprocessing/image-warp-filters/bulgepinch.d.ts +1 -1
  83. package/dist/passes/postprocessing/image-warp-filters/bulgepinch.d.ts.map +1 -1
  84. package/package.json +3 -3
  85. package/src/index.ts +9 -3
  86. package/src/lib/shader-module/shader-module.ts +31 -20
  87. package/src/lib/shader-module/shader-pass.ts +7 -4
  88. package/src/lib/utils/uniform-types.ts +66 -0
  89. package/src/modules/engine/picking/picking.ts +9 -9
  90. package/src/modules/engine/project/project.ts +10 -9
  91. package/src/modules/lighting/gouraud-material/gouraud-material.ts +14 -12
  92. package/src/modules/lighting/lights/lighting-uniforms-glsl.ts +35 -12
  93. package/src/modules/lighting/lights/lighting.ts +83 -54
  94. package/src/modules/lighting/no-material/dirlight.ts +3 -3
  95. package/src/modules/lighting/pbr-material/pbr-fragment-glsl.ts +56 -60
  96. package/src/modules/lighting/pbr-material/pbr-material.ts +40 -74
  97. package/src/modules/lighting/pbr-material/pbr-projection.ts +39 -0
  98. package/src/modules/lighting/pbr-material/pbr-vertex-glsl.ts +8 -16
  99. package/src/modules/lighting/phong-material/phong-material.ts +12 -12
  100. package/src/modules/lighting/phong-material/phong-shaders-glsl.ts +8 -88
  101. package/src/modules-webgl1/project/project.ts +8 -7
  102. package/src/passes/postprocessing/fxaa/fxaa.ts +2 -2
  103. package/src/passes/postprocessing/image-adjust-filters/brightnesscontrast.ts +0 -1
  104. package/src/passes/postprocessing/image-adjust-filters/huesaturation.ts +0 -1
  105. package/src/passes/postprocessing/image-adjust-filters/vibrance.ts +3 -0
  106. package/src/passes/postprocessing/image-blur-filters/tiltshift.ts +2 -2
  107. package/src/passes/postprocessing/image-blur-filters/triangleblur.ts +1 -1
  108. package/src/passes/postprocessing/image-blur-filters/zoomblur.ts +1 -1
  109. package/src/passes/postprocessing/image-fun-filters/colorhalftone.ts +1 -1
  110. package/src/passes/postprocessing/image-fun-filters/dotscreen.ts +1 -1
  111. package/src/passes/postprocessing/image-fun-filters/edgework.ts +26 -15
  112. package/src/passes/postprocessing/image-fun-filters/hexagonalpixelate.ts +1 -1
  113. package/src/passes/postprocessing/image-fun-filters/magnify.ts +2 -2
  114. package/src/passes/postprocessing/image-warp-filters/bulgepinch.ts +1 -1
  115. package/dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.d.ts +0 -42
  116. package/dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.d.ts.map +0 -1
  117. package/dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.js +0 -134
  118. package/src/modules/lighting/gouraud-material/gouraud-shaders-glsl.ts +0 -137
package/dist/index.cjs CHANGED
@@ -316,6 +316,17 @@ function initializeShaderModule(module2) {
316
316
  instance.propValidators = makePropValidators(propTypes);
317
317
  }
318
318
  module2.instance = instance;
319
+ let defaultProps = {};
320
+ if (propTypes) {
321
+ defaultProps = Object.entries(propTypes).reduce((obj, [key, propType]) => {
322
+ const value = propType == null ? void 0 : propType.value;
323
+ if (value) {
324
+ obj[key] = value;
325
+ }
326
+ return obj;
327
+ }, {});
328
+ }
329
+ module2.defaultUniforms = { ...module2.defaultUniforms, ...defaultProps };
319
330
  }
320
331
  function getShaderModuleUniforms(module2, props, oldUniforms) {
321
332
  var _a;
@@ -326,15 +337,15 @@ function getShaderModuleUniforms(module2, props, oldUniforms) {
326
337
  }
327
338
  return getValidatedProperties(props, (_a = module2.instance) == null ? void 0 : _a.propValidators, module2.name);
328
339
  }
329
- function checkShaderModuleDeprecations(shaderModule, shaderSource, log2) {
340
+ function checkShaderModuleDeprecations(shaderModule, shaderSource, log3) {
330
341
  var _a;
331
342
  (_a = shaderModule.deprecations) == null ? void 0 : _a.forEach((def) => {
332
343
  var _a2;
333
344
  if ((_a2 = def.regex) == null ? void 0 : _a2.test(shaderSource)) {
334
345
  if (def.deprecated) {
335
- log2.deprecated(def.old, def.new)();
346
+ log3.deprecated(def.old, def.new)();
336
347
  } else {
337
- log2.removed(def.old, def.new)();
348
+ log3.removed(def.old, def.new)();
338
349
  }
339
350
  }
340
351
  });
@@ -629,7 +640,7 @@ function assembleShaderWGSL(platformInfo, options) {
629
640
  // defines = {},
630
641
  hookFunctions = [],
631
642
  inject = {},
632
- log: log2
643
+ log: log3
633
644
  } = options;
634
645
  assert(typeof source2 === "string", "shader source must be a string");
635
646
  const coreSource = source2;
@@ -659,8 +670,8 @@ function assembleShaderWGSL(platformInfo, options) {
659
670
  }
660
671
  const modulesToInject = modules;
661
672
  for (const module2 of modulesToInject) {
662
- if (log2) {
663
- checkShaderModuleDeprecations(module2, coreSource, log2);
673
+ if (log3) {
674
+ checkShaderModuleDeprecations(module2, coreSource, log3);
664
675
  }
665
676
  const moduleSource = getShaderModuleSource(module2, "wgsl");
666
677
  assembledSource += moduleSource;
@@ -687,7 +698,7 @@ function assembleShaderWGSL(platformInfo, options) {
687
698
  }
688
699
  function assembleShaderGLSL(platformInfo, options) {
689
700
  var _a;
690
- const { id, source: source2, stage, language = "glsl", modules, defines = {}, hookFunctions = [], inject = {}, prologue = true, log: log2 } = options;
701
+ const { id, source: source2, stage, language = "glsl", modules, defines = {}, hookFunctions = [], inject = {}, prologue = true, log: log3 } = options;
691
702
  assert(typeof source2 === "string", "shader source must be a string");
692
703
  const sourceVersion = language === "glsl" ? getShaderInfo(source2).version : -1;
693
704
  const targetVersion = platformInfo.shaderLanguageVersion;
@@ -745,8 +756,8 @@ ${getApplicationDefines(allDefines)}
745
756
  }
746
757
  }
747
758
  for (const module2 of modules) {
748
- if (log2) {
749
- checkShaderModuleDeprecations(module2, coreSource, log2);
759
+ if (log3) {
760
+ checkShaderModuleDeprecations(module2, coreSource, log3);
750
761
  }
751
762
  const moduleSource = getShaderModuleSource(module2, stage);
752
763
  assembledSource += moduleSource;
@@ -1507,7 +1518,7 @@ var fp32 = {
1507
1518
  };
1508
1519
 
1509
1520
  // dist/modules/engine/picking/picking.js
1510
- var DEFAULT_HIGHLIGHT_COLOR = new Float32Array([0, 1, 1, 1]);
1521
+ var DEFAULT_HIGHLIGHT_COLOR = [0, 1, 1, 1];
1511
1522
  var vs = (
1512
1523
  /* glsl */
1513
1524
  `uniform pickingUniforms {
@@ -1660,7 +1671,7 @@ var picking = {
1660
1671
  isAttribute: false,
1661
1672
  isHighlightActive: false,
1662
1673
  useFloatColors: true,
1663
- highlightedObjectColor: new Float32Array([0, 0, 0]),
1674
+ highlightedObjectColor: [0, 0, 0],
1664
1675
  highlightColor: DEFAULT_HIGHLIGHT_COLOR
1665
1676
  },
1666
1677
  vs,
@@ -1694,6 +1705,9 @@ function getUniforms(opts = {}, prevUniforms) {
1694
1705
  return uniforms;
1695
1706
  }
1696
1707
 
1708
+ // dist/modules/lighting/lights/lighting.js
1709
+ var import_core3 = require("@luma.gl/core");
1710
+
1697
1711
  // dist/modules/lighting/lights/lighting-uniforms-glsl.js
1698
1712
  var lightingUniformsGLSL = (
1699
1713
  /* glsl */
@@ -1717,28 +1731,51 @@ struct DirectionalLight {
1717
1731
 
1718
1732
  uniform lightingUniforms {
1719
1733
  int enabled;
1720
- int pointLightCount;
1734
+ int lightType;
1735
+
1721
1736
  int directionalLightCount;
1737
+ int pointLightCount;
1722
1738
 
1723
1739
  vec3 ambientColor;
1724
1740
 
1725
- int lightType;
1726
- vec3 lightColor;
1727
- vec3 lightDirection;
1728
- vec3 lightPosition;
1729
- vec3 lightAttenuation;
1741
+ vec3 lightColor0;
1742
+ vec3 lightPosition0;
1743
+ vec3 lightDirection0;
1744
+ vec3 lightAttenuation0;
1730
1745
 
1731
- // AmbientLight ambientLight;
1732
- // PointLight pointLight[MAX_LIGHTS];
1733
- // DirectionalLight directionalLight[MAX_LIGHTS];
1746
+ vec3 lightColor1;
1747
+ vec3 lightPosition1;
1748
+ vec3 lightDirection1;
1749
+ vec3 lightAttenuation1;
1750
+
1751
+ vec3 lightColor2;
1752
+ vec3 lightPosition2;
1753
+ vec3 lightDirection2;
1754
+ vec3 lightAttenuation2;
1734
1755
  } lighting;
1735
1756
 
1736
1757
  PointLight lighting_getPointLight(int index) {
1737
- return PointLight(lighting.lightColor, lighting.lightPosition, lighting.lightAttenuation);
1758
+ switch (index) {
1759
+ case 0:
1760
+ return PointLight(lighting.lightColor0, lighting.lightPosition0, lighting.lightAttenuation0);
1761
+ case 1:
1762
+ return PointLight(lighting.lightColor1, lighting.lightPosition1, lighting.lightAttenuation1);
1763
+ case 2:
1764
+ default:
1765
+ return PointLight(lighting.lightColor2, lighting.lightPosition2, lighting.lightAttenuation2);
1766
+ }
1738
1767
  }
1739
1768
 
1740
1769
  DirectionalLight lighting_getDirectionalLight(int index) {
1741
- return DirectionalLight(lighting.lightColor, lighting.lightDirection);
1770
+ switch (index) {
1771
+ case 0:
1772
+ return DirectionalLight(lighting.lightColor0, lighting.lightDirection0);
1773
+ case 1:
1774
+ return DirectionalLight(lighting.lightColor1, lighting.lightDirection1);
1775
+ case 2:
1776
+ default:
1777
+ return DirectionalLight(lighting.lightColor2, lighting.lightDirection2);
1778
+ }
1742
1779
  }
1743
1780
 
1744
1781
  float getPointLightAttenuation(PointLight pointLight, float distance) {
@@ -1809,7 +1846,7 @@ fn getPointLightAttenuation(pointLight: PointLight, distance: f32) -> f32 {
1809
1846
  );
1810
1847
 
1811
1848
  // dist/modules/lighting/lights/lighting.js
1812
- var MAX_LIGHTS = 5;
1849
+ var MAX_LIGHTS = 3;
1813
1850
  var COLOR_FACTOR = 255;
1814
1851
  var LIGHT_TYPE;
1815
1852
  (function(LIGHT_TYPE2) {
@@ -1825,31 +1862,44 @@ var lighting = {
1825
1862
  },
1826
1863
  uniformTypes: {
1827
1864
  enabled: "i32",
1828
- ambientLightColor: "vec3<f32>",
1829
- numberOfLights: "i32",
1830
- // , array: MAX_LIGHTS,
1831
1865
  lightType: "i32",
1832
- // , array: MAX_LIGHTS,
1833
- lightColor: "vec3<f32>",
1834
- // , array: MAX_LIGHTS,
1835
- lightPosition: "vec3<f32>",
1836
- // , array: MAX_LIGHTS,
1866
+ directionalLightCount: "i32",
1867
+ pointLightCount: "i32",
1868
+ ambientLightColor: "vec3<f32>",
1869
+ // TODO define as arrays once we have appropriate uniformTypes
1870
+ lightColor0: "vec3<f32>",
1871
+ lightPosition0: "vec3<f32>",
1837
1872
  // TODO - could combine direction and attenuation
1838
- lightDirection: "vec3<f32>",
1839
- // , array: MAX_LIGHTS,
1840
- lightAttenuation: "vec3<f32>"
1841
- // , array: MAX_LIGHTS},
1873
+ lightDirection0: "vec3<f32>",
1874
+ lightAttenuation0: "vec3<f32>",
1875
+ lightColor1: "vec3<f32>",
1876
+ lightPosition1: "vec3<f32>",
1877
+ lightDirection1: "vec3<f32>",
1878
+ lightAttenuation1: "vec3<f32>",
1879
+ lightColor2: "vec3<f32>",
1880
+ lightPosition2: "vec3<f32>",
1881
+ lightDirection2: "vec3<f32>",
1882
+ lightAttenuation2: "vec3<f32>"
1842
1883
  },
1843
1884
  defaultUniforms: {
1844
1885
  enabled: 1,
1845
- ambientLightColor: [0.1, 0.1, 0.1],
1846
- numberOfLights: 0,
1847
1886
  lightType: LIGHT_TYPE.POINT,
1848
- lightColor: [1, 1, 1],
1849
- lightPosition: [1, 1, 2],
1887
+ directionalLightCount: 0,
1888
+ pointLightCount: 0,
1889
+ ambientLightColor: [0.1, 0.1, 0.1],
1890
+ lightColor0: [1, 1, 1],
1891
+ lightPosition0: [1, 1, 2],
1850
1892
  // TODO - could combine direction and attenuation
1851
- lightDirection: [1, 1, 1],
1852
- lightAttenuation: [1, 1, 1]
1893
+ lightDirection0: [1, 1, 1],
1894
+ lightAttenuation0: [1, 0, 0],
1895
+ lightColor1: [1, 1, 1],
1896
+ lightPosition1: [1, 1, 2],
1897
+ lightDirection1: [1, 1, 1],
1898
+ lightAttenuation1: [1, 0, 0],
1899
+ lightColor2: [1, 1, 1],
1900
+ lightPosition2: [1, 1, 2],
1901
+ lightDirection2: [1, 1, 1],
1902
+ lightAttenuation2: [1, 0, 0]
1853
1903
  },
1854
1904
  source: lightingUniformsWGSL,
1855
1905
  vs: lightingUniformsGLSL,
@@ -1880,30 +1930,29 @@ function getUniforms2(props, prevUniforms = {}) {
1880
1930
  return uniforms;
1881
1931
  }
1882
1932
  function getLightSourceUniforms({ ambientLight, pointLights = [], directionalLights = [] }) {
1883
- const lightSourceUniforms = {
1884
- // lightType: new Array(MAX_LIGHTS).fill(0),
1885
- // lightColor: new Array(MAX_LIGHTS).fill([0, 0, 0]),
1886
- // lightPosition: new Array(MAX_LIGHTS).fill([0, 0, 0]),
1887
- // lightDirection: new Array(MAX_LIGHTS).fill([0, 0, 0]),
1888
- // lightAttenuation: new Array(MAX_LIGHTS).fill([0, 0, 0])
1889
- };
1933
+ const lightSourceUniforms = {};
1890
1934
  lightSourceUniforms.ambientLightColor = convertColor(ambientLight);
1891
1935
  let currentLight = 0;
1892
1936
  for (const pointLight of pointLights) {
1893
1937
  lightSourceUniforms.lightType = LIGHT_TYPE.POINT;
1894
- lightSourceUniforms.lightColor = convertColor(pointLight);
1895
- lightSourceUniforms.lightPosition = pointLight.position;
1896
- lightSourceUniforms.lightAttenuation = [pointLight.attenuation || 1, 0, 0];
1938
+ const i = currentLight;
1939
+ lightSourceUniforms[`lightColor${i}`] = convertColor(pointLight);
1940
+ lightSourceUniforms[`lightPosition${i}`] = pointLight.position;
1941
+ lightSourceUniforms[`lightAttenuation${i}`] = pointLight.attenuation || [1, 0, 0];
1897
1942
  currentLight++;
1898
1943
  }
1899
1944
  for (const directionalLight of directionalLights) {
1900
1945
  lightSourceUniforms.lightType = LIGHT_TYPE.DIRECTIONAL;
1901
- lightSourceUniforms.lightColor = convertColor(directionalLight);
1902
- lightSourceUniforms.lightPosition = directionalLight.position;
1903
- lightSourceUniforms.lightDirection = directionalLight.direction;
1946
+ const i = currentLight;
1947
+ lightSourceUniforms[`lightColor${i}`] = convertColor(directionalLight);
1948
+ lightSourceUniforms[`lightDirection${i}`] = directionalLight.direction;
1904
1949
  currentLight++;
1905
1950
  }
1906
- lightSourceUniforms.numberOfLights = currentLight;
1951
+ if (currentLight > MAX_LIGHTS) {
1952
+ import_core3.log.warn("MAX_LIGHTS exceeded")();
1953
+ }
1954
+ lightSourceUniforms.directionalLightCount = directionalLights.length;
1955
+ lightSourceUniforms.pointLightCount = pointLights.length;
1907
1956
  return lightSourceUniforms;
1908
1957
  }
1909
1958
  function extractLightTypes(lights2) {
@@ -2003,7 +2052,7 @@ var dirlight = {
2003
2052
  lightDirection: "vec3<f32>"
2004
2053
  },
2005
2054
  defaultUniforms: {
2006
- lightDirection: new Float32Array([1, 1, 2])
2055
+ lightDirection: [1, 1, 2]
2007
2056
  },
2008
2057
  getUniforms: getUniforms3
2009
2058
  };
@@ -2015,10 +2064,10 @@ function getUniforms3(opts = dirlight.defaultUniforms) {
2015
2064
  return uniforms;
2016
2065
  }
2017
2066
 
2018
- // dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.js
2019
- var GOURAUD_VS = (
2067
+ // dist/modules/lighting/phong-material/phong-shaders-glsl.js
2068
+ var PHONG_VS = (
2020
2069
  /* glsl */
2021
- `uniform materialUniforms {
2070
+ `uniform phongMaterialUniforms {
2022
2071
  uniform float ambient;
2023
2072
  uniform float diffuse;
2024
2073
  uniform float shininess;
@@ -2026,9 +2075,9 @@ var GOURAUD_VS = (
2026
2075
  } material;
2027
2076
  `
2028
2077
  );
2029
- var GOURAUD_FS = (
2078
+ var PHONG_FS = (
2030
2079
  /* glsl */
2031
- `uniform materialUniforms {
2080
+ `uniform phongMaterialUniforms {
2032
2081
  uniform float ambient;
2033
2082
  uniform float diffuse;
2034
2083
  uniform float shininess;
@@ -2050,63 +2099,27 @@ vec3 lighting_getLightColor(vec3 surfaceColor, vec3 light_direction, vec3 view_d
2050
2099
  vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
2051
2100
  vec3 lightColor = surfaceColor;
2052
2101
 
2053
- if (lighting.enabled) {
2054
- vec3 view_direction = normalize(cameraPosition - position_worldspace);
2055
- lightColor = material.ambient * surfaceColor * lighting.ambientColor;
2056
-
2057
- if (lighting.lightType == 0) {
2058
- PointLight pointLight = lighting_getPointLight(0);
2059
- vec3 light_position_worldspace = pointLight.position;
2060
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
2061
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
2062
- } else if (lighting.lightType == 1) {
2063
- DirectionalLight directionalLight = lighting_getDirectionalLight(0);
2064
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
2065
- }
2066
- /*
2067
- for (int i = 0; i < MAX_LIGHTS; i++) {
2068
- if (i >= lighting.pointLightCount) {
2069
- break;
2070
- }
2071
- PointLight pointLight = lighting.pointLight[i];
2072
- vec3 light_position_worldspace = pointLight.position;
2073
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
2074
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
2075
- }
2076
-
2077
- for (int i = 0; i < MAX_LIGHTS; i++) {
2078
- if (i >= lighting.directionalLightCount) {
2079
- break;
2080
- }
2081
- DirectionalLight directionalLight = lighting.directionalLight[i];
2082
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
2083
- }
2084
- */
2102
+ if (lighting.enabled == 0) {
2103
+ return lightColor;
2085
2104
  }
2086
- return lightColor;
2087
- }
2088
-
2089
- vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
2090
- vec3 lightColor = vec3(0, 0, 0);
2091
- vec3 surfaceColor = vec3(0, 0, 0);
2092
2105
 
2093
- if (lighting.enabled) {
2094
- vec3 view_direction = normalize(cameraPosition - position_worldspace);
2106
+ vec3 view_direction = normalize(cameraPosition - position_worldspace);
2107
+ lightColor = material.ambient * surfaceColor * lighting.ambientColor;
2095
2108
 
2096
- switch (lighting.lightType) {
2097
- case 0:
2098
- PointLight pointLight = lighting_getPointLight(0);
2099
- vec3 light_position_worldspace = pointLight.position;
2100
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
2101
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
2102
- break;
2109
+ for (int i = 0; i < lighting.pointLightCount; i++) {
2110
+ PointLight pointLight = lighting_getPointLight(i);
2111
+ vec3 light_position_worldspace = pointLight.position;
2112
+ vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
2113
+ float light_attenuation = getPointLightAttenuation(pointLight, distance(light_position_worldspace, position_worldspace));
2114
+ lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color / light_attenuation);
2115
+ }
2103
2116
 
2104
- case 1:
2105
- DirectionalLight directionalLight = lighting_getDirectionalLight(0);
2106
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
2107
- break;
2108
- }
2117
+ int totalLights = min(MAX_LIGHTS, lighting.pointLightCount + lighting.directionalLightCount);
2118
+ for (int i = lighting.pointLightCount; i < totalLights; i++) {
2119
+ DirectionalLight directionalLight = lighting_getDirectionalLight(i);
2120
+ lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
2109
2121
  }
2122
+
2110
2123
  return lightColor;
2111
2124
  }
2112
2125
  `
@@ -2115,11 +2128,10 @@ vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspac
2115
2128
  // dist/modules/lighting/gouraud-material/gouraud-material.js
2116
2129
  var gouraudMaterial = {
2117
2130
  props: {},
2118
- uniforms: {},
2119
- name: "gouraud-lighting",
2131
+ name: "gouraudMaterial",
2120
2132
  // Note these are switched between phong and gouraud
2121
- vs: GOURAUD_VS,
2122
- fs: GOURAUD_FS,
2133
+ vs: PHONG_FS.replace("phongMaterial", "gouraudMaterial"),
2134
+ fs: PHONG_VS.replace("phongMaterial", "gouraudMaterial"),
2123
2135
  defines: {
2124
2136
  LIGHTING_VERTEX: 1
2125
2137
  },
@@ -2137,7 +2149,11 @@ var gouraudMaterial = {
2137
2149
  specularColor: [0.15, 0.15, 0.15]
2138
2150
  },
2139
2151
  getUniforms(props) {
2140
- return { ...gouraudMaterial.defaultUniforms, ...props };
2152
+ const uniforms = { ...props };
2153
+ if (uniforms.specularColor) {
2154
+ uniforms.specularColor = uniforms.specularColor.map((x) => x / 255);
2155
+ }
2156
+ return { ...gouraudMaterial.defaultUniforms, ...uniforms };
2141
2157
  }
2142
2158
  };
2143
2159
 
@@ -2232,111 +2248,9 @@ fn lighting_getSpecularLightColor(cameraPosition: vec3<f32>, position_worldspace
2232
2248
  `
2233
2249
  );
2234
2250
 
2235
- // dist/modules/lighting/phong-material/phong-shaders-glsl.js
2236
- var PHONG_VS = (
2237
- /* glsl */
2238
- `uniform phongMaterialUniforms {
2239
- uniform float ambient;
2240
- uniform float diffuse;
2241
- uniform float shininess;
2242
- uniform vec3 specularColor;
2243
- } material;
2244
- `
2245
- );
2246
- var PHONG_FS = (
2247
- /* glsl */
2248
- `uniform phongMaterialUniforms {
2249
- uniform float ambient;
2250
- uniform float diffuse;
2251
- uniform float shininess;
2252
- uniform vec3 specularColor;
2253
- } material;
2254
-
2255
- vec3 lighting_getLightColor(vec3 surfaceColor, vec3 light_direction, vec3 view_direction, vec3 normal_worldspace, vec3 color) {
2256
- vec3 halfway_direction = normalize(light_direction + view_direction);
2257
- float lambertian = dot(light_direction, normal_worldspace);
2258
- float specular = 0.0;
2259
- if (lambertian > 0.0) {
2260
- float specular_angle = max(dot(normal_worldspace, halfway_direction), 0.0);
2261
- specular = pow(specular_angle, material.shininess);
2262
- }
2263
- lambertian = max(lambertian, 0.0);
2264
- return (lambertian * material.diffuse * surfaceColor + specular * material.specularColor) * color;
2265
- }
2266
-
2267
- vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
2268
- vec3 lightColor = surfaceColor;
2269
-
2270
- if (lighting.enabled == 0) {
2271
- return lightColor;
2272
- }
2273
-
2274
- vec3 view_direction = normalize(cameraPosition - position_worldspace);
2275
- lightColor = material.ambient * surfaceColor * lighting.ambientColor;
2276
-
2277
- if (lighting.lightType == 0) {
2278
- PointLight pointLight = lighting_getPointLight(0);
2279
- vec3 light_position_worldspace = pointLight.position;
2280
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
2281
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
2282
- } else if (lighting.lightType == 1) {
2283
- DirectionalLight directionalLight = lighting_getDirectionalLight(0);
2284
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
2285
- }
2286
-
2287
- /*
2288
- for (int i = 0; i < MAX_LIGHTS; i++) {
2289
- if (i >= lighting.pointLightCount) {
2290
- break;
2291
- }
2292
- PointLight pointLight = lighting.pointLight[i];
2293
- vec3 light_position_worldspace = pointLight.position;
2294
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
2295
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
2296
- }
2297
-
2298
- for (int i = 0; i < MAX_LIGHTS; i++) {
2299
- if (i >= lighting.directionalLightCount) {
2300
- break;
2301
- }
2302
- DirectionalLight directionalLight = lighting.directionalLight[i];
2303
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
2304
- }
2305
- */
2306
- return lightColor;
2307
- }
2308
-
2309
- vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
2310
- vec3 lightColor = vec3(0, 0, 0);
2311
- vec3 surfaceColor = vec3(0, 0, 0);
2312
-
2313
- if (lighting.enabled == 0) {
2314
- vec3 view_direction = normalize(cameraPosition - position_worldspace);
2315
-
2316
- switch (lighting.lightType) {
2317
- case 0:
2318
- PointLight pointLight = lighting_getPointLight(0);
2319
- vec3 light_position_worldspace = pointLight.position;
2320
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
2321
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
2322
- break;
2323
-
2324
- case 1:
2325
- DirectionalLight directionalLight = lighting_getDirectionalLight(0);
2326
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
2327
- break;
2328
- }
2329
- }
2330
- return lightColor;
2331
- }
2332
- `
2333
- );
2334
-
2335
2251
  // dist/modules/lighting/phong-material/phong-material.js
2336
2252
  var phongMaterial = {
2337
- props: {},
2338
- uniforms: {},
2339
- name: "phong-lighting",
2253
+ name: "phongMaterial",
2340
2254
  dependencies: [lighting],
2341
2255
  // Note these are switched between phong and gouraud
2342
2256
  source: PHONG_WGSL,
@@ -2358,45 +2272,41 @@ var phongMaterial = {
2358
2272
  specularColor: [0.15, 0.15, 0.15]
2359
2273
  },
2360
2274
  getUniforms(props) {
2361
- return { ...phongMaterial.defaultUniforms, ...props };
2275
+ const uniforms = { ...props };
2276
+ if (uniforms.specularColor) {
2277
+ uniforms.specularColor = uniforms.specularColor.map((x) => x / 255);
2278
+ }
2279
+ return { ...phongMaterial.defaultUniforms, ...uniforms };
2362
2280
  }
2363
2281
  };
2364
2282
 
2365
2283
  // dist/modules/lighting/pbr-material/pbr-vertex-glsl.js
2366
2284
  var vs2 = (
2367
2285
  /* glsl */
2368
- `uniform projection {
2369
- mat4 u_MVPMatrix;
2370
- mat4 u_ModelMatrix;
2371
- mat4 u_NormalMatrix;
2372
- // Projection
2373
- vec3 u_Camera;
2374
- }
2375
-
2376
- varying vec3 pbr_vPosition;
2377
- varying vec2 pbr_vUV;
2286
+ `out vec3 pbr_vPosition;
2287
+ out vec2 pbr_vUV;
2378
2288
 
2379
2289
  #ifdef HAS_NORMALS
2380
2290
  # ifdef HAS_TANGENTS
2381
- varying mat3 pbr_vTBN;
2291
+ out mat3 pbr_vTBN;
2382
2292
  # else
2383
- varying vec3 pbr_vNormal;
2293
+ out vec3 pbr_vNormal;
2384
2294
  # endif
2385
2295
  #endif
2386
2296
 
2387
2297
  void pbr_setPositionNormalTangentUV(vec4 position, vec4 normal, vec4 tangent, vec2 uv)
2388
2298
  {
2389
- vec4 pos = u_ModelMatrix * position;
2299
+ vec4 pos = pbrProjection.modelMatrix * position;
2390
2300
  pbr_vPosition = vec3(pos.xyz) / pos.w;
2391
2301
 
2392
2302
  #ifdef HAS_NORMALS
2393
2303
  #ifdef HAS_TANGENTS
2394
- vec3 normalW = normalize(vec3(u_NormalMatrix * vec4(normal.xyz, 0.0)));
2395
- vec3 tangentW = normalize(vec3(u_ModelMatrix * vec4(tangent.xyz, 0.0)));
2304
+ vec3 normalW = normalize(vec3(pbrProjection.normalMatrix * vec4(normal.xyz, 0.0)));
2305
+ vec3 tangentW = normalize(vec3(pbrProjection.modelMatrix * vec4(tangent.xyz, 0.0)));
2396
2306
  vec3 bitangentW = cross(normalW, tangentW) * tangent.w;
2397
2307
  pbr_vTBN = mat3(tangentW, bitangentW, normalW);
2398
2308
  #else // HAS_TANGENTS != 1
2399
- pbr_vNormal = normalize(vec3(u_ModelMatrix * vec4(normal.xyz, 0.0)));
2309
+ pbr_vNormal = normalize(vec3(pbrProjection.modelMatrix * vec4(normal.xyz, 0.0)));
2400
2310
  #endif
2401
2311
  #endif
2402
2312
 
@@ -2414,12 +2324,7 @@ var fs3 = (
2414
2324
  /* glsl */
2415
2325
  `precision highp float;
2416
2326
 
2417
- uniform Projection {
2418
- // Projection
2419
- uniform vec3 u_Camera;
2420
- };
2421
-
2422
- uniform pbrMaterial {
2327
+ uniform pbrMaterialUniforms {
2423
2328
  // Material is unlit
2424
2329
  bool unlit;
2425
2330
 
@@ -2451,40 +2356,40 @@ uniform pbrMaterial {
2451
2356
  vec4 scaleDiffBaseMR;
2452
2357
  vec4 scaleFGDSpec;
2453
2358
  // #endif
2454
- } u_pbrMaterial;
2359
+ } pbrMaterial;
2455
2360
 
2456
2361
  // Samplers
2457
2362
  #ifdef HAS_BASECOLORMAP
2458
- uniform sampler2D u_BaseColorSampler;
2363
+ uniform sampler2D pbr_baseColorSampler;
2459
2364
  #endif
2460
2365
  #ifdef HAS_NORMALMAP
2461
- uniform sampler2D u_NormalSampler;
2366
+ uniform sampler2D pbr_normalSampler;
2462
2367
  #endif
2463
2368
  #ifdef HAS_EMISSIVEMAP
2464
- uniform sampler2D u_EmissiveSampler;
2369
+ uniform sampler2D pbr_emissiveSampler;
2465
2370
  #endif
2466
2371
  #ifdef HAS_METALROUGHNESSMAP
2467
- uniform sampler2D u_MetallicRoughnessSampler;
2372
+ uniform sampler2D pbr_metallicRoughnessSampler;
2468
2373
  #endif
2469
2374
  #ifdef HAS_OCCLUSIONMAP
2470
- uniform sampler2D u_OcclusionSampler;
2375
+ uniform sampler2D pbr_occlusionSampler;
2471
2376
  #endif
2472
2377
  #ifdef USE_IBL
2473
- uniform samplerCube u_DiffuseEnvSampler;
2474
- uniform samplerCube u_SpecularEnvSampler;
2475
- uniform sampler2D u_brdfLUT;
2378
+ uniform samplerCube pbr_diffuseEnvSampler;
2379
+ uniform samplerCube pbr_specularEnvSampler;
2380
+ uniform sampler2D pbr_brdfLUT;
2476
2381
  #endif
2477
2382
 
2478
2383
  // Inputs from vertex shader
2479
2384
 
2480
- varying vec3 pbr_vPosition;
2481
- varying vec2 pbr_vUV;
2385
+ in vec3 pbr_vPosition;
2386
+ in vec2 pbr_vUV;
2482
2387
 
2483
2388
  #ifdef HAS_NORMALS
2484
2389
  #ifdef HAS_TANGENTS
2485
- varying mat3 pbr_vTBN;
2390
+ in mat3 pbr_vTBN;
2486
2391
  #else
2487
- varying vec3 pbr_vNormal;
2392
+ in vec3 pbr_vNormal;
2488
2393
  #endif
2489
2394
  #endif
2490
2395
 
@@ -2552,8 +2457,8 @@ vec3 getNormal()
2552
2457
  #endif
2553
2458
 
2554
2459
  #ifdef HAS_NORMALMAP
2555
- vec3 n = texture2D(u_NormalSampler, pbr_vUV).rgb;
2556
- n = normalize(tbn * ((2.0 * n - 1.0) * vec3(u_pbrMaterial.normalScale, u_pbrMaterial.normalScale, 1.0)));
2460
+ vec3 n = texture(pbr_normalSampler, pbr_vUV).rgb;
2461
+ n = normalize(tbn * ((2.0 * n - 1.0) * vec3(pbrMaterial.normalScale, pbrMaterial.normalScale, 1.0)));
2557
2462
  #else
2558
2463
  // The tbn matrix is linearly interpolated, so we need to re-normalize
2559
2464
  vec3 n = normalize(tbn[2].xyz);
@@ -2571,22 +2476,22 @@ vec3 getIBLContribution(PBRInfo pbrInfo, vec3 n, vec3 reflection)
2571
2476
  float mipCount = 9.0; // resolution of 512x512
2572
2477
  float lod = (pbrInfo.perceptualRoughness * mipCount);
2573
2478
  // retrieve a scale and bias to F0. See [1], Figure 3
2574
- vec3 brdf = SRGBtoLINEAR(texture2D(u_brdfLUT,
2479
+ vec3 brdf = SRGBtoLINEAR(texture(pbr_brdfLUT,
2575
2480
  vec2(pbrInfo.NdotV, 1.0 - pbrInfo.perceptualRoughness))).rgb;
2576
- vec3 diffuseLight = SRGBtoLINEAR(textureCube(u_DiffuseEnvSampler, n)).rgb;
2481
+ vec3 diffuseLight = SRGBtoLINEAR(texture(pbr_diffuseEnvSampler, n)).rgb;
2577
2482
 
2578
2483
  #ifdef USE_TEX_LOD
2579
- vec3 specularLight = SRGBtoLINEAR(textureCubeLod(u_SpecularEnvSampler, reflection, lod)).rgb;
2484
+ vec3 specularLight = SRGBtoLINEAR(texture(pbr_specularEnvSampler, reflection, lod)).rgb;
2580
2485
  #else
2581
- vec3 specularLight = SRGBtoLINEAR(textureCube(u_SpecularEnvSampler, reflection)).rgb;
2486
+ vec3 specularLight = SRGBtoLINEAR(texture(pbr_specularEnvSampler, reflection)).rgb;
2582
2487
  #endif
2583
2488
 
2584
2489
  vec3 diffuse = diffuseLight * pbrInfo.diffuseColor;
2585
2490
  vec3 specular = specularLight * (pbrInfo.specularColor * brdf.x + brdf.y);
2586
2491
 
2587
2492
  // For presentation, this allows us to disable IBL terms
2588
- diffuse *= u_pbrMaterial.scaleIBLAmbient.x;
2589
- specular *= u_pbrMaterial.scaleIBLAmbient.y;
2493
+ diffuse *= pbrMaterial.scaleIBLAmbient.x;
2494
+ specular *= pbrMaterial.scaleIBLAmbient.y;
2590
2495
 
2591
2496
  return diffuse + specular;
2592
2497
  }
@@ -2678,32 +2583,32 @@ vec4 pbr_filterColor(vec4 colorUnused)
2678
2583
  {
2679
2584
  // The albedo may be defined from a base texture or a flat color
2680
2585
  #ifdef HAS_BASECOLORMAP
2681
- vec4 baseColor = SRGBtoLINEAR(texture2D(u_BaseColorSampler, pbr_vUV)) * u_pbrMaterial.baseColorFactor;
2586
+ vec4 baseColor = SRGBtoLINEAR(texture(pbr_baseColorSampler, pbr_vUV)) * pbrMaterial.baseColorFactor;
2682
2587
  #else
2683
- vec4 baseColor = u_pbrMaterial.baseColorFactor;
2588
+ vec4 baseColor = pbrMaterial.baseColorFactor;
2684
2589
  #endif
2685
2590
 
2686
2591
  #ifdef ALPHA_CUTOFF
2687
- if (baseColor.a < u_pbrMaterial.alphaCutoff) {
2592
+ if (baseColor.a < pbrMaterial.alphaCutoff) {
2688
2593
  discard;
2689
2594
  }
2690
2595
  #endif
2691
2596
 
2692
2597
  vec3 color = vec3(0, 0, 0);
2693
2598
 
2694
- if(u_pbrMaterial.unlit){
2599
+ if(pbrMaterial.unlit){
2695
2600
  color.rgb = baseColor.rgb;
2696
2601
  }
2697
2602
  else{
2698
2603
  // Metallic and Roughness material properties are packed together
2699
2604
  // In glTF, these factors can be specified by fixed scalar values
2700
2605
  // or from a metallic-roughness map
2701
- float perceptualRoughness = u_pbrMaterial.metallicRoughnessValues.y;
2702
- float metallic = u_pbrMaterial.metallicRoughnessValues.x;
2606
+ float perceptualRoughness = pbrMaterial.metallicRoughnessValues.y;
2607
+ float metallic = pbrMaterial.metallicRoughnessValues.x;
2703
2608
  #ifdef HAS_METALROUGHNESSMAP
2704
2609
  // Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.
2705
2610
  // This layout intentionally reserves the 'r' channel for (optional) occlusion map data
2706
- vec4 mrSample = texture2D(u_MetallicRoughnessSampler, pbr_vUV);
2611
+ vec4 mrSample = texture(pbr_metallicRoughnessSampler, pbr_vUV);
2707
2612
  perceptualRoughness = mrSample.g * perceptualRoughness;
2708
2613
  metallic = mrSample.b * metallic;
2709
2614
  #endif
@@ -2730,7 +2635,7 @@ vec4 pbr_filterColor(vec4 colorUnused)
2730
2635
  vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90;
2731
2636
 
2732
2637
  vec3 n = getNormal(); // normal at surface point
2733
- vec3 v = normalize(u_Camera - pbr_vPosition); // Vector from surface point to camera
2638
+ vec3 v = normalize(pbrProjection.camera - pbr_vPosition); // Vector from surface point to camera
2734
2639
 
2735
2640
  float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);
2736
2641
  vec3 reflection = -normalize(reflect(v, n));
@@ -2752,47 +2657,48 @@ vec4 pbr_filterColor(vec4 colorUnused)
2752
2657
  v
2753
2658
  );
2754
2659
 
2660
+
2755
2661
  #ifdef USE_LIGHTS
2756
2662
  // Apply ambient light
2757
2663
  PBRInfo_setAmbientLight(pbrInfo);
2758
- color += calculateFinalColor(pbrInfo, lighting_uAmbientLight.color);
2664
+ color += calculateFinalColor(pbrInfo, lighting.ambientColor);
2759
2665
 
2760
2666
  // Apply directional light
2761
- for(int i = 0; i < lighting_uDirectionalLightCount; i++) {
2762
- if (i < lighting_uDirectionalLightCount) {
2763
- PBRInfo_setDirectionalLight(pbrInfo, lighting_uDirectionalLight[i].direction);
2764
- color += calculateFinalColor(pbrInfo, lighting_uDirectionalLight[i].color);
2667
+ for(int i = 0; i < lighting.directionalLightCount; i++) {
2668
+ if (i < lighting.directionalLightCount) {
2669
+ PBRInfo_setDirectionalLight(pbrInfo, lighting_getDirectionalLight(i).direction);
2670
+ color += calculateFinalColor(pbrInfo, lighting_getDirectionalLight(i).color);
2765
2671
  }
2766
2672
  }
2767
2673
 
2768
2674
  // Apply point light
2769
- for(int i = 0; i < lighting_uPointLightCount; i++) {
2770
- if (i < lighting_uPointLightCount) {
2771
- PBRInfo_setPointLight(pbrInfo, lighting_uPointLight[i]);
2772
- float attenuation = getPointLightAttenuation(lighting_uPointLight[i], distance(lighting_uPointLight[i].position, pbr_vPosition));
2773
- color += calculateFinalColor(pbrInfo, lighting_uPointLight[i].color / attenuation);
2675
+ for(int i = 0; i < lighting.pointLightCount; i++) {
2676
+ if (i < lighting.pointLightCount) {
2677
+ PBRInfo_setPointLight(pbrInfo, lighting_getPointLight(i));
2678
+ float attenuation = getPointLightAttenuation(lighting_getPointLight(i), distance(lighting_getPointLight(i).position, pbr_vPosition));
2679
+ color += calculateFinalColor(pbrInfo, lighting_getPointLight(i).color / attenuation);
2774
2680
  }
2775
2681
  }
2776
2682
  #endif
2777
2683
 
2778
2684
  // Calculate lighting contribution from image based lighting source (IBL)
2779
2685
  #ifdef USE_IBL
2780
- if (u_pbrMateral.IBLEnabled) {
2686
+ if (pbrMaterial.IBLenabled) {
2781
2687
  color += getIBLContribution(pbrInfo, n, reflection);
2782
2688
  }
2783
2689
  #endif
2784
2690
 
2785
- // Apply optional PBR terms for additional (optional) shading
2691
+ // Apply optional PBR terms for additional (optional) shading
2786
2692
  #ifdef HAS_OCCLUSIONMAP
2787
- if (u_pbrMaterial.occlusionMapEnabled) {
2788
- float ao = texture2D(u_OcclusionSampler, pbr_vUV).r;
2789
- color = mix(color, color * ao, u_pbrMaterial.occlusionStrength);
2693
+ if (pbrMaterial.occlusionMapEnabled) {
2694
+ float ao = texture(pbr_occlusionSampler, pbr_vUV).r;
2695
+ color = mix(color, color * ao, pbrMaterial.occlusionStrength);
2790
2696
  }
2791
2697
  #endif
2792
2698
 
2793
2699
  #ifdef HAS_EMISSIVEMAP
2794
- if (u_pbrMaterial.emmissiveMapEnabled) {
2795
- vec3 emissive = SRGBtoLINEAR(texture2D(u_EmissiveSampler, pbr_vUV)).rgb * u_pbrMaterial.emissiveFactor;
2700
+ if (pbrMaterial.emissiveMapEnabled) {
2701
+ vec3 emissive = SRGBtoLINEAR(texture(pbr_emissiveSampler, pbr_vUV)).rgb * pbrMaterial.emissiveFactor;
2796
2702
  color += emissive;
2797
2703
  }
2798
2704
  #endif
@@ -2802,15 +2708,15 @@ vec4 pbr_filterColor(vec4 colorUnused)
2802
2708
  #ifdef PBR_DEBUG
2803
2709
  // TODO: Figure out how to debug multiple lights
2804
2710
 
2805
- // color = mix(color, F, u_ScaleFGDSpec.x);
2806
- // color = mix(color, vec3(G), u_ScaleFGDSpec.y);
2807
- // color = mix(color, vec3(D), u_ScaleFGDSpec.z);
2808
- // color = mix(color, specContrib, u_ScaleFGDSpec.w);
2711
+ // color = mix(color, F, pbr_scaleFGDSpec.x);
2712
+ // color = mix(color, vec3(G), pbr_scaleFGDSpec.y);
2713
+ // color = mix(color, vec3(D), pbr_scaleFGDSpec.z);
2714
+ // color = mix(color, specContrib, pbr_scaleFGDSpec.w);
2809
2715
 
2810
- // color = mix(color, diffuseContrib, u_ScaleDiffBaseMR.x);
2811
- color = mix(color, baseColor.rgb, u_pbrMaterial.scaleDiffBaseMR.y);
2812
- color = mix(color, vec3(metallic), u_pbrMaterial.scaleDiffBaseMR.z);
2813
- color = mix(color, vec3(perceptualRoughness), u_pbrMaterial.scaleDiffBaseMR.w);
2716
+ // color = mix(color, diffuseContrib, pbr_scaleDiffBaseMR.x);
2717
+ color = mix(color, baseColor.rgb, pbrMaterial.scaleDiffBaseMR.y);
2718
+ color = mix(color, vec3(metallic), pbrMaterial.scaleDiffBaseMR.z);
2719
+ color = mix(color, vec3(perceptualRoughness), pbrMaterial.scaleDiffBaseMR.w);
2814
2720
  #endif
2815
2721
 
2816
2722
  }
@@ -2820,25 +2726,52 @@ vec4 pbr_filterColor(vec4 colorUnused)
2820
2726
  `
2821
2727
  );
2822
2728
 
2729
+ // dist/modules/lighting/pbr-material/pbr-projection.js
2730
+ var uniformBlock = (
2731
+ /* glsl */
2732
+ `uniform pbrProjectionUniforms {
2733
+ mat4 modelViewProjectionMatrix;
2734
+ mat4 modelMatrix;
2735
+ mat4 normalMatrix;
2736
+ vec3 camera;
2737
+ } pbrProjection;
2738
+ `
2739
+ );
2740
+ var pbrProjection = {
2741
+ name: "pbrProjection",
2742
+ vs: uniformBlock,
2743
+ fs: uniformBlock,
2744
+ // TODO why is this needed?
2745
+ getUniforms: (props) => props,
2746
+ uniformTypes: {
2747
+ modelViewProjectionMatrix: "mat4x4<f32>",
2748
+ modelMatrix: "mat4x4<f32>",
2749
+ normalMatrix: "mat4x4<f32>",
2750
+ camera: "vec3<i32>"
2751
+ }
2752
+ };
2753
+
2823
2754
  // dist/modules/lighting/pbr-material/pbr-material.js
2824
2755
  var pbrMaterial = {
2825
2756
  props: {},
2826
2757
  uniforms: {},
2827
- name: "pbr",
2828
- dependencies: [lighting],
2758
+ name: "pbrMaterial",
2759
+ dependencies: [lighting, pbrProjection],
2829
2760
  vs: vs2,
2830
2761
  fs: fs3,
2831
2762
  defines: {
2832
- LIGHTING_FRAGMENT: 1,
2833
- HAS_NORMALMAP: 0,
2834
- HAS_EMISSIVEMAP: 0,
2835
- HAS_OCCLUSIONMAP: 0,
2836
- HAS_BASECOLORMAP: 0,
2837
- HAS_METALROUGHNESSMAP: 0,
2838
- ALPHA_CUTOFF: 0,
2839
- USE_IBL: 0,
2840
- PBR_DEBUG: 0
2763
+ LIGHTING_FRAGMENT: 1
2764
+ // TODO defining these as 0 breaks shader
2765
+ // HAS_NORMALMAP: 0
2766
+ // HAS_EMISSIVEMAP: 0,
2767
+ // HAS_OCCLUSIONMAP: 0,
2768
+ // HAS_BASECOLORMAP: 0,
2769
+ // HAS_METALROUGHNESSMAP: 0,
2770
+ // ALPHA_CUTOFF: 0
2771
+ // USE_IBL: 0
2772
+ // PBR_DEBUG: 0
2841
2773
  },
2774
+ getUniforms: (props) => props,
2842
2775
  uniformTypes: {
2843
2776
  // Material is unlit
2844
2777
  unlit: "i32",
@@ -2867,25 +2800,6 @@ var pbrMaterial = {
2867
2800
  // #ifdef PBR_DEBUG
2868
2801
  scaleDiffBaseMR: "vec4<f32>",
2869
2802
  scaleFGDSpec: "vec4<f32>"
2870
- },
2871
- bindings: {
2872
- baseColorSampler: { type: "texture", location: 8 },
2873
- // #ifdef HAS_BASECOLORMAP
2874
- normalSampler: { type: "texture", location: 9 },
2875
- // #ifdef HAS_NORMALMAP
2876
- emissiveSampler: { type: "texture", location: 10 },
2877
- // #ifdef HAS_EMISSIVEMAP
2878
- metallicRoughnessSampler: { type: "texture", location: 11 },
2879
- // #ifdef HAS_METALROUGHNESSMAP
2880
- occlusionSampler: { type: "texture", location: 12 },
2881
- // #ifdef HAS_OCCLUSIONMAP
2882
- // IBL Samplers
2883
- diffuseEnvSampler: { type: "texture", location: 13 },
2884
- // #ifdef USE_IBL (samplerCube)
2885
- specularEnvSampler: { type: "texture", location: 14 },
2886
- // #ifdef USE_IBL (samplerCube)
2887
- brdfLUT: { type: "texture", location: 15 }
2888
- // #ifdef USE_IBL
2889
2803
  }
2890
2804
  };
2891
2805
 
@@ -2935,7 +2849,6 @@ vec4 brightnessContrast_filterColor_ext(vec4 color, vec2 texSize, vec2 texCoord)
2935
2849
  );
2936
2850
  var brightnessContrast = {
2937
2851
  props: {},
2938
- uniforms: {},
2939
2852
  name: "brightnessContrast",
2940
2853
  uniformTypes: {
2941
2854
  brightness: "f32",
@@ -3034,7 +2947,6 @@ vec4 hueSaturation_filterColor_ext(vec4 color, vec2 texSize, vec2 texCoord) {
3034
2947
  );
3035
2948
  var hueSaturation = {
3036
2949
  props: {},
3037
- uniforms: {},
3038
2950
  name: "hueSaturation",
3039
2951
  fs: fs6,
3040
2952
  uniformTypes: {
@@ -3145,6 +3057,9 @@ var vibrance = {
3145
3057
  props: {},
3146
3058
  uniforms: {},
3147
3059
  name: "vibrance",
3060
+ uniformTypes: {
3061
+ amount: "f32"
3062
+ },
3148
3063
  propTypes: {
3149
3064
  amount: { value: 0, min: -1, max: 1 }
3150
3065
  },
@@ -3478,11 +3393,11 @@ var fs16 = (
3478
3393
  /* glsl */
3479
3394
  `uniform edgeWorkUniforms {
3480
3395
  float radius;
3481
- vec2 delta;
3396
+ int mode;
3482
3397
  } edgeWork;
3483
3398
 
3484
- vec4 edgeWork_sampleColor1(sampler2D source, vec2 texSize, vec2 texCoord) {
3485
- vec2 relativeDelta = edgeWork.radius * edgeWork.delta / texSize;
3399
+ vec4 edgeWork_sampleColorRGB(sampler2D source, vec2 texSize, vec2 texCoord, vec2 delta) {
3400
+ vec2 relativeDelta = edgeWork.radius * delta / texSize;
3486
3401
 
3487
3402
  vec2 color = vec2(0.0);
3488
3403
  vec2 total = vec2(0.0);
@@ -3506,8 +3421,8 @@ vec4 edgeWork_sampleColor1(sampler2D source, vec2 texSize, vec2 texCoord) {
3506
3421
  return vec4(color / total, 0.0, 1.0);
3507
3422
  }
3508
3423
 
3509
- vec4 edgeWork_sampleColor2(sampler2D source, vec2 texSize, vec2 texCoord) {
3510
- vec2 relativeDelta = edgeWork.radius * edgeWork.delta / texSize;
3424
+ vec4 edgeWork_sampleColorXY(sampler2D source, vec2 texSize, vec2 texCoord, vec2 delta) {
3425
+ vec2 relativeDelta = edgeWork.radius * delta / texSize;
3511
3426
 
3512
3427
  vec2 color = vec2(0.0);
3513
3428
  vec2 total = vec2(0.0);
@@ -3530,6 +3445,16 @@ vec4 edgeWork_sampleColor2(sampler2D source, vec2 texSize, vec2 texCoord) {
3530
3445
  float c = clamp(10000.0 * (color.y / total.y - color.x / total.x) + 0.5, 0.0, 1.0);
3531
3446
  return vec4(c, c, c, 1.0);
3532
3447
  }
3448
+
3449
+ vec4 edgeWork_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
3450
+ switch (edgeWork.mode) {
3451
+ case 0:
3452
+ return edgeWork_sampleColorRGB(source, texSize, texCoord, vec2(1., 0.));
3453
+ case 1:
3454
+ default:
3455
+ return edgeWork_sampleColorXY(source, texSize, texCoord, vec2(0., 1.));
3456
+ }
3457
+ }
3533
3458
  `
3534
3459
  );
3535
3460
  var edgeWork = {
@@ -3538,20 +3463,22 @@ var edgeWork = {
3538
3463
  name: "edgeWork",
3539
3464
  dependencies: [random],
3540
3465
  fs: fs16,
3466
+ uniformTypes: {
3467
+ radius: "f32",
3468
+ mode: "i32"
3469
+ },
3541
3470
  propTypes: {
3542
3471
  radius: { value: 2, min: 1, softMax: 50 },
3543
- delta: { value: [1, 0], private: true }
3472
+ mode: { value: 0, private: true }
3544
3473
  },
3545
3474
  passes: [
3546
3475
  {
3547
- // @ts-expect-error
3548
- sampler: "edgeWork_sampleColor1",
3549
- propTypes: { delta: [1, 0] }
3476
+ sampler: true,
3477
+ uniforms: { mode: 0 }
3550
3478
  },
3551
3479
  {
3552
- // @ts-expect-error
3553
- sampler: "edgeWork_sampleColor2",
3554
- propTypes: { delta: [0, 1] }
3480
+ sampler: true,
3481
+ uniforms: { mode: 1 }
3555
3482
  }
3556
3483
  ]
3557
3484
  };
@@ -3837,7 +3764,9 @@ var swirl = {
3837
3764
  };
3838
3765
 
3839
3766
  // dist/passes/postprocessing/fxaa/fxaa.js
3840
- var fs23 = `
3767
+ var fs23 = (
3768
+ /* glsl */
3769
+ `
3841
3770
  #define FXAA_QUALITY_PRESET 29
3842
3771
 
3843
3772
  #if (FXAA_QUALITY_PRESET == 10)
@@ -4417,7 +4346,8 @@ vec4 fxaa_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
4417
4346
  fxaa_QualityEdgeThresholdMin
4418
4347
  );
4419
4348
  }
4420
- `;
4349
+ `
4350
+ );
4421
4351
  var fxaa = {
4422
4352
  name: "fxaa",
4423
4353
  propTypes: {},
@@ -5338,7 +5268,7 @@ var geometry = {
5338
5268
  };
5339
5269
 
5340
5270
  // dist/modules-webgl1/project/project.js
5341
- var import_core3 = require("@math.gl/core");
5271
+ var import_core4 = require("@math.gl/core");
5342
5272
  var IDENTITY_MATRIX = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
5343
5273
  var DEFAULT_MODULE_OPTIONS = {
5344
5274
  modelMatrix: IDENTITY_MATRIX,
@@ -5361,7 +5291,7 @@ function getUniforms5(opts = DEFAULT_MODULE_OPTIONS, prevUniforms = {}) {
5361
5291
  uniforms.cameraPositionWorld = opts.cameraPositionWorld;
5362
5292
  }
5363
5293
  if (opts.projectionMatrix !== void 0 && opts.viewMatrix !== void 0) {
5364
- uniforms.viewProjectionMatrix = new import_core3.Matrix4(opts.projectionMatrix).multiplyRight(opts.viewMatrix);
5294
+ uniforms.viewProjectionMatrix = new import_core4.Matrix4(opts.projectionMatrix).multiplyRight(opts.viewMatrix);
5365
5295
  }
5366
5296
  return uniforms;
5367
5297
  }