@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/dist.dev.js CHANGED
@@ -347,6 +347,20 @@ ${inject[key]}` : inject[key];
347
347
  instance.propValidators = makePropValidators(propTypes);
348
348
  }
349
349
  module.instance = instance;
350
+ let defaultProps = {};
351
+ if (propTypes) {
352
+ defaultProps = Object.entries(propTypes).reduce(
353
+ (obj, [key, propType]) => {
354
+ const value = propType?.value;
355
+ if (value) {
356
+ obj[key] = value;
357
+ }
358
+ return obj;
359
+ },
360
+ {}
361
+ );
362
+ }
363
+ module.defaultUniforms = { ...module.defaultUniforms, ...defaultProps };
350
364
  }
351
365
  function getShaderModuleUniforms(module, props, oldUniforms) {
352
366
  initializeShaderModule(module);
@@ -356,13 +370,13 @@ ${inject[key]}` : inject[key];
356
370
  }
357
371
  return getValidatedProperties(props, module.instance?.propValidators, module.name);
358
372
  }
359
- function checkShaderModuleDeprecations(shaderModule, shaderSource, log2) {
373
+ function checkShaderModuleDeprecations(shaderModule, shaderSource, log3) {
360
374
  shaderModule.deprecations?.forEach((def) => {
361
375
  if (def.regex?.test(shaderSource)) {
362
376
  if (def.deprecated) {
363
- log2.deprecated(def.old, def.new)();
377
+ log3.deprecated(def.old, def.new)();
364
378
  } else {
365
- log2.removed(def.old, def.new)();
379
+ log3.removed(def.old, def.new)();
366
380
  }
367
381
  }
368
382
  });
@@ -655,7 +669,7 @@ ${DECLARATION_INJECT_MARKER}
655
669
  // defines = {},
656
670
  hookFunctions = [],
657
671
  inject = {},
658
- log: log2
672
+ log: log3
659
673
  } = options;
660
674
  assert(typeof source2 === "string", "shader source must be a string");
661
675
  const coreSource = source2;
@@ -685,8 +699,8 @@ ${DECLARATION_INJECT_MARKER}
685
699
  }
686
700
  const modulesToInject = modules;
687
701
  for (const module of modulesToInject) {
688
- if (log2) {
689
- checkShaderModuleDeprecations(module, coreSource, log2);
702
+ if (log3) {
703
+ checkShaderModuleDeprecations(module, coreSource, log3);
690
704
  }
691
705
  const moduleSource = getShaderModuleSource(module, "wgsl");
692
706
  assembledSource += moduleSource;
@@ -722,7 +736,7 @@ ${DECLARATION_INJECT_MARKER}
722
736
  hookFunctions = [],
723
737
  inject = {},
724
738
  prologue = true,
725
- log: log2
739
+ log: log3
726
740
  } = options;
727
741
  assert(typeof source2 === "string", "shader source must be a string");
728
742
  const sourceVersion = language === "glsl" ? getShaderInfo(source2).version : -1;
@@ -781,8 +795,8 @@ ${getApplicationDefines(allDefines)}
781
795
  }
782
796
  }
783
797
  for (const module of modules) {
784
- if (log2) {
785
- checkShaderModuleDeprecations(module, coreSource, log2);
798
+ if (log3) {
799
+ checkShaderModuleDeprecations(module, coreSource, log3);
786
800
  }
787
801
  const moduleSource = getShaderModuleSource(module, stage);
788
802
  assembledSource += moduleSource;
@@ -6661,7 +6675,7 @@ float tan_fp32(float a) {
6661
6675
  };
6662
6676
 
6663
6677
  // src/modules/engine/picking/picking.ts
6664
- var DEFAULT_HIGHLIGHT_COLOR = new Float32Array([0, 1, 1, 1]);
6678
+ var DEFAULT_HIGHLIGHT_COLOR = [0, 1, 1, 1];
6665
6679
  var vs = (
6666
6680
  /* glsl */
6667
6681
  `uniform pickingUniforms {
@@ -6814,7 +6828,7 @@ vec4 picking_filterColor(vec4 color) {
6814
6828
  isAttribute: false,
6815
6829
  isHighlightActive: false,
6816
6830
  useFloatColors: true,
6817
- highlightedObjectColor: new Float32Array([0, 0, 0]),
6831
+ highlightedObjectColor: [0, 0, 0],
6818
6832
  highlightColor: DEFAULT_HIGHLIGHT_COLOR
6819
6833
  },
6820
6834
  vs,
@@ -6848,6 +6862,9 @@ vec4 picking_filterColor(vec4 color) {
6848
6862
  return uniforms;
6849
6863
  }
6850
6864
 
6865
+ // src/modules/lighting/lights/lighting.ts
6866
+ var import_core3 = __toESM(require_core(), 1);
6867
+
6851
6868
  // src/modules/lighting/lights/lighting-uniforms-glsl.ts
6852
6869
  var lightingUniformsGLSL = (
6853
6870
  /* glsl */
@@ -6871,28 +6888,51 @@ struct DirectionalLight {
6871
6888
 
6872
6889
  uniform lightingUniforms {
6873
6890
  int enabled;
6874
- int pointLightCount;
6891
+ int lightType;
6892
+
6875
6893
  int directionalLightCount;
6894
+ int pointLightCount;
6876
6895
 
6877
6896
  vec3 ambientColor;
6878
6897
 
6879
- int lightType;
6880
- vec3 lightColor;
6881
- vec3 lightDirection;
6882
- vec3 lightPosition;
6883
- vec3 lightAttenuation;
6898
+ vec3 lightColor0;
6899
+ vec3 lightPosition0;
6900
+ vec3 lightDirection0;
6901
+ vec3 lightAttenuation0;
6884
6902
 
6885
- // AmbientLight ambientLight;
6886
- // PointLight pointLight[MAX_LIGHTS];
6887
- // DirectionalLight directionalLight[MAX_LIGHTS];
6903
+ vec3 lightColor1;
6904
+ vec3 lightPosition1;
6905
+ vec3 lightDirection1;
6906
+ vec3 lightAttenuation1;
6907
+
6908
+ vec3 lightColor2;
6909
+ vec3 lightPosition2;
6910
+ vec3 lightDirection2;
6911
+ vec3 lightAttenuation2;
6888
6912
  } lighting;
6889
6913
 
6890
6914
  PointLight lighting_getPointLight(int index) {
6891
- return PointLight(lighting.lightColor, lighting.lightPosition, lighting.lightAttenuation);
6915
+ switch (index) {
6916
+ case 0:
6917
+ return PointLight(lighting.lightColor0, lighting.lightPosition0, lighting.lightAttenuation0);
6918
+ case 1:
6919
+ return PointLight(lighting.lightColor1, lighting.lightPosition1, lighting.lightAttenuation1);
6920
+ case 2:
6921
+ default:
6922
+ return PointLight(lighting.lightColor2, lighting.lightPosition2, lighting.lightAttenuation2);
6923
+ }
6892
6924
  }
6893
6925
 
6894
6926
  DirectionalLight lighting_getDirectionalLight(int index) {
6895
- return DirectionalLight(lighting.lightColor, lighting.lightDirection);
6927
+ switch (index) {
6928
+ case 0:
6929
+ return DirectionalLight(lighting.lightColor0, lighting.lightDirection0);
6930
+ case 1:
6931
+ return DirectionalLight(lighting.lightColor1, lighting.lightDirection1);
6932
+ case 2:
6933
+ default:
6934
+ return DirectionalLight(lighting.lightColor2, lighting.lightDirection2);
6935
+ }
6896
6936
  }
6897
6937
 
6898
6938
  float getPointLightAttenuation(PointLight pointLight, float distance) {
@@ -6963,7 +7003,7 @@ fn getPointLightAttenuation(pointLight: PointLight, distance: f32) -> f32 {
6963
7003
  );
6964
7004
 
6965
7005
  // src/modules/lighting/lights/lighting.ts
6966
- var MAX_LIGHTS = 5;
7006
+ var MAX_LIGHTS = 3;
6967
7007
  var COLOR_FACTOR = 255;
6968
7008
  var lighting = {
6969
7009
  props: {},
@@ -6974,31 +7014,44 @@ fn getPointLightAttenuation(pointLight: PointLight, distance: f32) -> f32 {
6974
7014
  },
6975
7015
  uniformTypes: {
6976
7016
  enabled: "i32",
6977
- ambientLightColor: "vec3<f32>",
6978
- numberOfLights: "i32",
6979
- // , array: MAX_LIGHTS,
6980
7017
  lightType: "i32",
6981
- // , array: MAX_LIGHTS,
6982
- lightColor: "vec3<f32>",
6983
- // , array: MAX_LIGHTS,
6984
- lightPosition: "vec3<f32>",
6985
- // , array: MAX_LIGHTS,
7018
+ directionalLightCount: "i32",
7019
+ pointLightCount: "i32",
7020
+ ambientLightColor: "vec3<f32>",
7021
+ // TODO define as arrays once we have appropriate uniformTypes
7022
+ lightColor0: "vec3<f32>",
7023
+ lightPosition0: "vec3<f32>",
6986
7024
  // TODO - could combine direction and attenuation
6987
- lightDirection: "vec3<f32>",
6988
- // , array: MAX_LIGHTS,
6989
- lightAttenuation: "vec3<f32>"
6990
- // , array: MAX_LIGHTS},
7025
+ lightDirection0: "vec3<f32>",
7026
+ lightAttenuation0: "vec3<f32>",
7027
+ lightColor1: "vec3<f32>",
7028
+ lightPosition1: "vec3<f32>",
7029
+ lightDirection1: "vec3<f32>",
7030
+ lightAttenuation1: "vec3<f32>",
7031
+ lightColor2: "vec3<f32>",
7032
+ lightPosition2: "vec3<f32>",
7033
+ lightDirection2: "vec3<f32>",
7034
+ lightAttenuation2: "vec3<f32>"
6991
7035
  },
6992
7036
  defaultUniforms: {
6993
7037
  enabled: 1,
6994
- ambientLightColor: [0.1, 0.1, 0.1],
6995
- numberOfLights: 0,
6996
7038
  lightType: 0 /* POINT */,
6997
- lightColor: [1, 1, 1],
6998
- lightPosition: [1, 1, 2],
7039
+ directionalLightCount: 0,
7040
+ pointLightCount: 0,
7041
+ ambientLightColor: [0.1, 0.1, 0.1],
7042
+ lightColor0: [1, 1, 1],
7043
+ lightPosition0: [1, 1, 2],
6999
7044
  // TODO - could combine direction and attenuation
7000
- lightDirection: [1, 1, 1],
7001
- lightAttenuation: [1, 1, 1]
7045
+ lightDirection0: [1, 1, 1],
7046
+ lightAttenuation0: [1, 0, 0],
7047
+ lightColor1: [1, 1, 1],
7048
+ lightPosition1: [1, 1, 2],
7049
+ lightDirection1: [1, 1, 1],
7050
+ lightAttenuation1: [1, 0, 0],
7051
+ lightColor2: [1, 1, 1],
7052
+ lightPosition2: [1, 1, 2],
7053
+ lightDirection2: [1, 1, 1],
7054
+ lightAttenuation2: [1, 0, 0]
7002
7055
  },
7003
7056
  source: lightingUniformsWGSL,
7004
7057
  vs: lightingUniformsGLSL,
@@ -7033,30 +7086,29 @@ fn getPointLightAttenuation(pointLight: PointLight, distance: f32) -> f32 {
7033
7086
  pointLights = [],
7034
7087
  directionalLights = []
7035
7088
  }) {
7036
- const lightSourceUniforms = {
7037
- // lightType: new Array(MAX_LIGHTS).fill(0),
7038
- // lightColor: new Array(MAX_LIGHTS).fill([0, 0, 0]),
7039
- // lightPosition: new Array(MAX_LIGHTS).fill([0, 0, 0]),
7040
- // lightDirection: new Array(MAX_LIGHTS).fill([0, 0, 0]),
7041
- // lightAttenuation: new Array(MAX_LIGHTS).fill([0, 0, 0])
7042
- };
7089
+ const lightSourceUniforms = {};
7043
7090
  lightSourceUniforms.ambientLightColor = convertColor(ambientLight);
7044
7091
  let currentLight = 0;
7045
7092
  for (const pointLight of pointLights) {
7046
7093
  lightSourceUniforms.lightType = 0 /* POINT */;
7047
- lightSourceUniforms.lightColor = convertColor(pointLight);
7048
- lightSourceUniforms.lightPosition = pointLight.position;
7049
- lightSourceUniforms.lightAttenuation = [pointLight.attenuation || 1, 0, 0];
7094
+ const i = currentLight;
7095
+ lightSourceUniforms[`lightColor${i}`] = convertColor(pointLight);
7096
+ lightSourceUniforms[`lightPosition${i}`] = pointLight.position;
7097
+ lightSourceUniforms[`lightAttenuation${i}`] = pointLight.attenuation || [1, 0, 0];
7050
7098
  currentLight++;
7051
7099
  }
7052
7100
  for (const directionalLight of directionalLights) {
7053
7101
  lightSourceUniforms.lightType = 1 /* DIRECTIONAL */;
7054
- lightSourceUniforms.lightColor = convertColor(directionalLight);
7055
- lightSourceUniforms.lightPosition = directionalLight.position;
7056
- lightSourceUniforms.lightDirection = directionalLight.direction;
7102
+ const i = currentLight;
7103
+ lightSourceUniforms[`lightColor${i}`] = convertColor(directionalLight);
7104
+ lightSourceUniforms[`lightDirection${i}`] = directionalLight.direction;
7057
7105
  currentLight++;
7058
7106
  }
7059
- lightSourceUniforms.numberOfLights = currentLight;
7107
+ if (currentLight > MAX_LIGHTS) {
7108
+ import_core3.log.warn("MAX_LIGHTS exceeded")();
7109
+ }
7110
+ lightSourceUniforms.directionalLightCount = directionalLights.length;
7111
+ lightSourceUniforms.pointLightCount = pointLights.length;
7060
7112
  return lightSourceUniforms;
7061
7113
  }
7062
7114
  function extractLightTypes(lights2) {
@@ -7155,7 +7207,7 @@ vec4 dirlight_filterColor(vec4 color) {
7155
7207
  lightDirection: "vec3<f32>"
7156
7208
  },
7157
7209
  defaultUniforms: {
7158
- lightDirection: new Float32Array([1, 1, 2])
7210
+ lightDirection: [1, 1, 2]
7159
7211
  },
7160
7212
  getUniforms: getUniforms3
7161
7213
  };
@@ -7167,10 +7219,10 @@ vec4 dirlight_filterColor(vec4 color) {
7167
7219
  return uniforms;
7168
7220
  }
7169
7221
 
7170
- // src/modules/lighting/gouraud-material/gouraud-shaders-glsl.ts
7171
- var GOURAUD_VS = (
7222
+ // src/modules/lighting/phong-material/phong-shaders-glsl.ts
7223
+ var PHONG_VS = (
7172
7224
  /* glsl */
7173
- `uniform materialUniforms {
7225
+ `uniform phongMaterialUniforms {
7174
7226
  uniform float ambient;
7175
7227
  uniform float diffuse;
7176
7228
  uniform float shininess;
@@ -7178,9 +7230,9 @@ vec4 dirlight_filterColor(vec4 color) {
7178
7230
  } material;
7179
7231
  `
7180
7232
  );
7181
- var GOURAUD_FS = (
7233
+ var PHONG_FS = (
7182
7234
  /* glsl */
7183
- `uniform materialUniforms {
7235
+ `uniform phongMaterialUniforms {
7184
7236
  uniform float ambient;
7185
7237
  uniform float diffuse;
7186
7238
  uniform float shininess;
@@ -7202,63 +7254,27 @@ vec3 lighting_getLightColor(vec3 surfaceColor, vec3 light_direction, vec3 view_d
7202
7254
  vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
7203
7255
  vec3 lightColor = surfaceColor;
7204
7256
 
7205
- if (lighting.enabled) {
7206
- vec3 view_direction = normalize(cameraPosition - position_worldspace);
7207
- lightColor = material.ambient * surfaceColor * lighting.ambientColor;
7208
-
7209
- if (lighting.lightType == 0) {
7210
- PointLight pointLight = lighting_getPointLight(0);
7211
- vec3 light_position_worldspace = pointLight.position;
7212
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
7213
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
7214
- } else if (lighting.lightType == 1) {
7215
- DirectionalLight directionalLight = lighting_getDirectionalLight(0);
7216
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
7217
- }
7218
- /*
7219
- for (int i = 0; i < MAX_LIGHTS; i++) {
7220
- if (i >= lighting.pointLightCount) {
7221
- break;
7222
- }
7223
- PointLight pointLight = lighting.pointLight[i];
7224
- vec3 light_position_worldspace = pointLight.position;
7225
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
7226
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
7227
- }
7228
-
7229
- for (int i = 0; i < MAX_LIGHTS; i++) {
7230
- if (i >= lighting.directionalLightCount) {
7231
- break;
7232
- }
7233
- DirectionalLight directionalLight = lighting.directionalLight[i];
7234
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
7235
- }
7236
- */
7257
+ if (lighting.enabled == 0) {
7258
+ return lightColor;
7237
7259
  }
7238
- return lightColor;
7239
- }
7240
7260
 
7241
- vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
7242
- vec3 lightColor = vec3(0, 0, 0);
7243
- vec3 surfaceColor = vec3(0, 0, 0);
7244
-
7245
- if (lighting.enabled) {
7246
- vec3 view_direction = normalize(cameraPosition - position_worldspace);
7261
+ vec3 view_direction = normalize(cameraPosition - position_worldspace);
7262
+ lightColor = material.ambient * surfaceColor * lighting.ambientColor;
7247
7263
 
7248
- switch (lighting.lightType) {
7249
- case 0:
7250
- PointLight pointLight = lighting_getPointLight(0);
7251
- vec3 light_position_worldspace = pointLight.position;
7252
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
7253
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
7254
- break;
7264
+ for (int i = 0; i < lighting.pointLightCount; i++) {
7265
+ PointLight pointLight = lighting_getPointLight(i);
7266
+ vec3 light_position_worldspace = pointLight.position;
7267
+ vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
7268
+ float light_attenuation = getPointLightAttenuation(pointLight, distance(light_position_worldspace, position_worldspace));
7269
+ lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color / light_attenuation);
7270
+ }
7255
7271
 
7256
- case 1:
7257
- DirectionalLight directionalLight = lighting_getDirectionalLight(0);
7258
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
7259
- break;
7260
- }
7272
+ int totalLights = min(MAX_LIGHTS, lighting.pointLightCount + lighting.directionalLightCount);
7273
+ for (int i = lighting.pointLightCount; i < totalLights; i++) {
7274
+ DirectionalLight directionalLight = lighting_getDirectionalLight(i);
7275
+ lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
7261
7276
  }
7277
+
7262
7278
  return lightColor;
7263
7279
  }
7264
7280
  `
@@ -7267,11 +7283,10 @@ vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspac
7267
7283
  // src/modules/lighting/gouraud-material/gouraud-material.ts
7268
7284
  var gouraudMaterial = {
7269
7285
  props: {},
7270
- uniforms: {},
7271
- name: "gouraud-lighting",
7286
+ name: "gouraudMaterial",
7272
7287
  // Note these are switched between phong and gouraud
7273
- vs: GOURAUD_VS,
7274
- fs: GOURAUD_FS,
7288
+ vs: PHONG_FS.replace("phongMaterial", "gouraudMaterial"),
7289
+ fs: PHONG_VS.replace("phongMaterial", "gouraudMaterial"),
7275
7290
  defines: {
7276
7291
  LIGHTING_VERTEX: 1
7277
7292
  },
@@ -7289,7 +7304,11 @@ vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspac
7289
7304
  specularColor: [0.15, 0.15, 0.15]
7290
7305
  },
7291
7306
  getUniforms(props) {
7292
- return { ...gouraudMaterial.defaultUniforms, ...props };
7307
+ const uniforms = { ...props };
7308
+ if (uniforms.specularColor) {
7309
+ uniforms.specularColor = uniforms.specularColor.map((x) => x / 255);
7310
+ }
7311
+ return { ...gouraudMaterial.defaultUniforms, ...uniforms };
7293
7312
  }
7294
7313
  };
7295
7314
 
@@ -7384,111 +7403,9 @@ fn lighting_getSpecularLightColor(cameraPosition: vec3<f32>, position_worldspace
7384
7403
  `
7385
7404
  );
7386
7405
 
7387
- // src/modules/lighting/phong-material/phong-shaders-glsl.ts
7388
- var PHONG_VS = (
7389
- /* glsl */
7390
- `uniform phongMaterialUniforms {
7391
- uniform float ambient;
7392
- uniform float diffuse;
7393
- uniform float shininess;
7394
- uniform vec3 specularColor;
7395
- } material;
7396
- `
7397
- );
7398
- var PHONG_FS = (
7399
- /* glsl */
7400
- `uniform phongMaterialUniforms {
7401
- uniform float ambient;
7402
- uniform float diffuse;
7403
- uniform float shininess;
7404
- uniform vec3 specularColor;
7405
- } material;
7406
-
7407
- vec3 lighting_getLightColor(vec3 surfaceColor, vec3 light_direction, vec3 view_direction, vec3 normal_worldspace, vec3 color) {
7408
- vec3 halfway_direction = normalize(light_direction + view_direction);
7409
- float lambertian = dot(light_direction, normal_worldspace);
7410
- float specular = 0.0;
7411
- if (lambertian > 0.0) {
7412
- float specular_angle = max(dot(normal_worldspace, halfway_direction), 0.0);
7413
- specular = pow(specular_angle, material.shininess);
7414
- }
7415
- lambertian = max(lambertian, 0.0);
7416
- return (lambertian * material.diffuse * surfaceColor + specular * material.specularColor) * color;
7417
- }
7418
-
7419
- vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
7420
- vec3 lightColor = surfaceColor;
7421
-
7422
- if (lighting.enabled == 0) {
7423
- return lightColor;
7424
- }
7425
-
7426
- vec3 view_direction = normalize(cameraPosition - position_worldspace);
7427
- lightColor = material.ambient * surfaceColor * lighting.ambientColor;
7428
-
7429
- if (lighting.lightType == 0) {
7430
- PointLight pointLight = lighting_getPointLight(0);
7431
- vec3 light_position_worldspace = pointLight.position;
7432
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
7433
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
7434
- } else if (lighting.lightType == 1) {
7435
- DirectionalLight directionalLight = lighting_getDirectionalLight(0);
7436
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
7437
- }
7438
-
7439
- /*
7440
- for (int i = 0; i < MAX_LIGHTS; i++) {
7441
- if (i >= lighting.pointLightCount) {
7442
- break;
7443
- }
7444
- PointLight pointLight = lighting.pointLight[i];
7445
- vec3 light_position_worldspace = pointLight.position;
7446
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
7447
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
7448
- }
7449
-
7450
- for (int i = 0; i < MAX_LIGHTS; i++) {
7451
- if (i >= lighting.directionalLightCount) {
7452
- break;
7453
- }
7454
- DirectionalLight directionalLight = lighting.directionalLight[i];
7455
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
7456
- }
7457
- */
7458
- return lightColor;
7459
- }
7460
-
7461
- vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
7462
- vec3 lightColor = vec3(0, 0, 0);
7463
- vec3 surfaceColor = vec3(0, 0, 0);
7464
-
7465
- if (lighting.enabled == 0) {
7466
- vec3 view_direction = normalize(cameraPosition - position_worldspace);
7467
-
7468
- switch (lighting.lightType) {
7469
- case 0:
7470
- PointLight pointLight = lighting_getPointLight(0);
7471
- vec3 light_position_worldspace = pointLight.position;
7472
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
7473
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
7474
- break;
7475
-
7476
- case 1:
7477
- DirectionalLight directionalLight = lighting_getDirectionalLight(0);
7478
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
7479
- break;
7480
- }
7481
- }
7482
- return lightColor;
7483
- }
7484
- `
7485
- );
7486
-
7487
7406
  // src/modules/lighting/phong-material/phong-material.ts
7488
7407
  var phongMaterial = {
7489
- props: {},
7490
- uniforms: {},
7491
- name: "phong-lighting",
7408
+ name: "phongMaterial",
7492
7409
  dependencies: [lighting],
7493
7410
  // Note these are switched between phong and gouraud
7494
7411
  source: PHONG_WGSL,
@@ -7510,45 +7427,41 @@ vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspac
7510
7427
  specularColor: [0.15, 0.15, 0.15]
7511
7428
  },
7512
7429
  getUniforms(props) {
7513
- return { ...phongMaterial.defaultUniforms, ...props };
7430
+ const uniforms = { ...props };
7431
+ if (uniforms.specularColor) {
7432
+ uniforms.specularColor = uniforms.specularColor.map((x) => x / 255);
7433
+ }
7434
+ return { ...phongMaterial.defaultUniforms, ...uniforms };
7514
7435
  }
7515
7436
  };
7516
7437
 
7517
7438
  // src/modules/lighting/pbr-material/pbr-vertex-glsl.ts
7518
7439
  var vs2 = (
7519
7440
  /* glsl */
7520
- `uniform projection {
7521
- mat4 u_MVPMatrix;
7522
- mat4 u_ModelMatrix;
7523
- mat4 u_NormalMatrix;
7524
- // Projection
7525
- vec3 u_Camera;
7526
- }
7527
-
7528
- varying vec3 pbr_vPosition;
7529
- varying vec2 pbr_vUV;
7441
+ `out vec3 pbr_vPosition;
7442
+ out vec2 pbr_vUV;
7530
7443
 
7531
7444
  #ifdef HAS_NORMALS
7532
7445
  # ifdef HAS_TANGENTS
7533
- varying mat3 pbr_vTBN;
7446
+ out mat3 pbr_vTBN;
7534
7447
  # else
7535
- varying vec3 pbr_vNormal;
7448
+ out vec3 pbr_vNormal;
7536
7449
  # endif
7537
7450
  #endif
7538
7451
 
7539
7452
  void pbr_setPositionNormalTangentUV(vec4 position, vec4 normal, vec4 tangent, vec2 uv)
7540
7453
  {
7541
- vec4 pos = u_ModelMatrix * position;
7454
+ vec4 pos = pbrProjection.modelMatrix * position;
7542
7455
  pbr_vPosition = vec3(pos.xyz) / pos.w;
7543
7456
 
7544
7457
  #ifdef HAS_NORMALS
7545
7458
  #ifdef HAS_TANGENTS
7546
- vec3 normalW = normalize(vec3(u_NormalMatrix * vec4(normal.xyz, 0.0)));
7547
- vec3 tangentW = normalize(vec3(u_ModelMatrix * vec4(tangent.xyz, 0.0)));
7459
+ vec3 normalW = normalize(vec3(pbrProjection.normalMatrix * vec4(normal.xyz, 0.0)));
7460
+ vec3 tangentW = normalize(vec3(pbrProjection.modelMatrix * vec4(tangent.xyz, 0.0)));
7548
7461
  vec3 bitangentW = cross(normalW, tangentW) * tangent.w;
7549
7462
  pbr_vTBN = mat3(tangentW, bitangentW, normalW);
7550
7463
  #else // HAS_TANGENTS != 1
7551
- pbr_vNormal = normalize(vec3(u_ModelMatrix * vec4(normal.xyz, 0.0)));
7464
+ pbr_vNormal = normalize(vec3(pbrProjection.modelMatrix * vec4(normal.xyz, 0.0)));
7552
7465
  #endif
7553
7466
  #endif
7554
7467
 
@@ -7566,12 +7479,7 @@ void pbr_setPositionNormalTangentUV(vec4 position, vec4 normal, vec4 tangent, ve
7566
7479
  /* glsl */
7567
7480
  `precision highp float;
7568
7481
 
7569
- uniform Projection {
7570
- // Projection
7571
- uniform vec3 u_Camera;
7572
- };
7573
-
7574
- uniform pbrMaterial {
7482
+ uniform pbrMaterialUniforms {
7575
7483
  // Material is unlit
7576
7484
  bool unlit;
7577
7485
 
@@ -7603,40 +7511,40 @@ uniform pbrMaterial {
7603
7511
  vec4 scaleDiffBaseMR;
7604
7512
  vec4 scaleFGDSpec;
7605
7513
  // #endif
7606
- } u_pbrMaterial;
7514
+ } pbrMaterial;
7607
7515
 
7608
7516
  // Samplers
7609
7517
  #ifdef HAS_BASECOLORMAP
7610
- uniform sampler2D u_BaseColorSampler;
7518
+ uniform sampler2D pbr_baseColorSampler;
7611
7519
  #endif
7612
7520
  #ifdef HAS_NORMALMAP
7613
- uniform sampler2D u_NormalSampler;
7521
+ uniform sampler2D pbr_normalSampler;
7614
7522
  #endif
7615
7523
  #ifdef HAS_EMISSIVEMAP
7616
- uniform sampler2D u_EmissiveSampler;
7524
+ uniform sampler2D pbr_emissiveSampler;
7617
7525
  #endif
7618
7526
  #ifdef HAS_METALROUGHNESSMAP
7619
- uniform sampler2D u_MetallicRoughnessSampler;
7527
+ uniform sampler2D pbr_metallicRoughnessSampler;
7620
7528
  #endif
7621
7529
  #ifdef HAS_OCCLUSIONMAP
7622
- uniform sampler2D u_OcclusionSampler;
7530
+ uniform sampler2D pbr_occlusionSampler;
7623
7531
  #endif
7624
7532
  #ifdef USE_IBL
7625
- uniform samplerCube u_DiffuseEnvSampler;
7626
- uniform samplerCube u_SpecularEnvSampler;
7627
- uniform sampler2D u_brdfLUT;
7533
+ uniform samplerCube pbr_diffuseEnvSampler;
7534
+ uniform samplerCube pbr_specularEnvSampler;
7535
+ uniform sampler2D pbr_brdfLUT;
7628
7536
  #endif
7629
7537
 
7630
7538
  // Inputs from vertex shader
7631
7539
 
7632
- varying vec3 pbr_vPosition;
7633
- varying vec2 pbr_vUV;
7540
+ in vec3 pbr_vPosition;
7541
+ in vec2 pbr_vUV;
7634
7542
 
7635
7543
  #ifdef HAS_NORMALS
7636
7544
  #ifdef HAS_TANGENTS
7637
- varying mat3 pbr_vTBN;
7545
+ in mat3 pbr_vTBN;
7638
7546
  #else
7639
- varying vec3 pbr_vNormal;
7547
+ in vec3 pbr_vNormal;
7640
7548
  #endif
7641
7549
  #endif
7642
7550
 
@@ -7704,8 +7612,8 @@ vec3 getNormal()
7704
7612
  #endif
7705
7613
 
7706
7614
  #ifdef HAS_NORMALMAP
7707
- vec3 n = texture2D(u_NormalSampler, pbr_vUV).rgb;
7708
- n = normalize(tbn * ((2.0 * n - 1.0) * vec3(u_pbrMaterial.normalScale, u_pbrMaterial.normalScale, 1.0)));
7615
+ vec3 n = texture(pbr_normalSampler, pbr_vUV).rgb;
7616
+ n = normalize(tbn * ((2.0 * n - 1.0) * vec3(pbrMaterial.normalScale, pbrMaterial.normalScale, 1.0)));
7709
7617
  #else
7710
7618
  // The tbn matrix is linearly interpolated, so we need to re-normalize
7711
7619
  vec3 n = normalize(tbn[2].xyz);
@@ -7723,22 +7631,22 @@ vec3 getIBLContribution(PBRInfo pbrInfo, vec3 n, vec3 reflection)
7723
7631
  float mipCount = 9.0; // resolution of 512x512
7724
7632
  float lod = (pbrInfo.perceptualRoughness * mipCount);
7725
7633
  // retrieve a scale and bias to F0. See [1], Figure 3
7726
- vec3 brdf = SRGBtoLINEAR(texture2D(u_brdfLUT,
7634
+ vec3 brdf = SRGBtoLINEAR(texture(pbr_brdfLUT,
7727
7635
  vec2(pbrInfo.NdotV, 1.0 - pbrInfo.perceptualRoughness))).rgb;
7728
- vec3 diffuseLight = SRGBtoLINEAR(textureCube(u_DiffuseEnvSampler, n)).rgb;
7636
+ vec3 diffuseLight = SRGBtoLINEAR(texture(pbr_diffuseEnvSampler, n)).rgb;
7729
7637
 
7730
7638
  #ifdef USE_TEX_LOD
7731
- vec3 specularLight = SRGBtoLINEAR(textureCubeLod(u_SpecularEnvSampler, reflection, lod)).rgb;
7639
+ vec3 specularLight = SRGBtoLINEAR(texture(pbr_specularEnvSampler, reflection, lod)).rgb;
7732
7640
  #else
7733
- vec3 specularLight = SRGBtoLINEAR(textureCube(u_SpecularEnvSampler, reflection)).rgb;
7641
+ vec3 specularLight = SRGBtoLINEAR(texture(pbr_specularEnvSampler, reflection)).rgb;
7734
7642
  #endif
7735
7643
 
7736
7644
  vec3 diffuse = diffuseLight * pbrInfo.diffuseColor;
7737
7645
  vec3 specular = specularLight * (pbrInfo.specularColor * brdf.x + brdf.y);
7738
7646
 
7739
7647
  // For presentation, this allows us to disable IBL terms
7740
- diffuse *= u_pbrMaterial.scaleIBLAmbient.x;
7741
- specular *= u_pbrMaterial.scaleIBLAmbient.y;
7648
+ diffuse *= pbrMaterial.scaleIBLAmbient.x;
7649
+ specular *= pbrMaterial.scaleIBLAmbient.y;
7742
7650
 
7743
7651
  return diffuse + specular;
7744
7652
  }
@@ -7830,32 +7738,32 @@ vec4 pbr_filterColor(vec4 colorUnused)
7830
7738
  {
7831
7739
  // The albedo may be defined from a base texture or a flat color
7832
7740
  #ifdef HAS_BASECOLORMAP
7833
- vec4 baseColor = SRGBtoLINEAR(texture2D(u_BaseColorSampler, pbr_vUV)) * u_pbrMaterial.baseColorFactor;
7741
+ vec4 baseColor = SRGBtoLINEAR(texture(pbr_baseColorSampler, pbr_vUV)) * pbrMaterial.baseColorFactor;
7834
7742
  #else
7835
- vec4 baseColor = u_pbrMaterial.baseColorFactor;
7743
+ vec4 baseColor = pbrMaterial.baseColorFactor;
7836
7744
  #endif
7837
7745
 
7838
7746
  #ifdef ALPHA_CUTOFF
7839
- if (baseColor.a < u_pbrMaterial.alphaCutoff) {
7747
+ if (baseColor.a < pbrMaterial.alphaCutoff) {
7840
7748
  discard;
7841
7749
  }
7842
7750
  #endif
7843
7751
 
7844
7752
  vec3 color = vec3(0, 0, 0);
7845
7753
 
7846
- if(u_pbrMaterial.unlit){
7754
+ if(pbrMaterial.unlit){
7847
7755
  color.rgb = baseColor.rgb;
7848
7756
  }
7849
7757
  else{
7850
7758
  // Metallic and Roughness material properties are packed together
7851
7759
  // In glTF, these factors can be specified by fixed scalar values
7852
7760
  // or from a metallic-roughness map
7853
- float perceptualRoughness = u_pbrMaterial.metallicRoughnessValues.y;
7854
- float metallic = u_pbrMaterial.metallicRoughnessValues.x;
7761
+ float perceptualRoughness = pbrMaterial.metallicRoughnessValues.y;
7762
+ float metallic = pbrMaterial.metallicRoughnessValues.x;
7855
7763
  #ifdef HAS_METALROUGHNESSMAP
7856
7764
  // Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.
7857
7765
  // This layout intentionally reserves the 'r' channel for (optional) occlusion map data
7858
- vec4 mrSample = texture2D(u_MetallicRoughnessSampler, pbr_vUV);
7766
+ vec4 mrSample = texture(pbr_metallicRoughnessSampler, pbr_vUV);
7859
7767
  perceptualRoughness = mrSample.g * perceptualRoughness;
7860
7768
  metallic = mrSample.b * metallic;
7861
7769
  #endif
@@ -7882,7 +7790,7 @@ vec4 pbr_filterColor(vec4 colorUnused)
7882
7790
  vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90;
7883
7791
 
7884
7792
  vec3 n = getNormal(); // normal at surface point
7885
- vec3 v = normalize(u_Camera - pbr_vPosition); // Vector from surface point to camera
7793
+ vec3 v = normalize(pbrProjection.camera - pbr_vPosition); // Vector from surface point to camera
7886
7794
 
7887
7795
  float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);
7888
7796
  vec3 reflection = -normalize(reflect(v, n));
@@ -7904,47 +7812,48 @@ vec4 pbr_filterColor(vec4 colorUnused)
7904
7812
  v
7905
7813
  );
7906
7814
 
7815
+
7907
7816
  #ifdef USE_LIGHTS
7908
7817
  // Apply ambient light
7909
7818
  PBRInfo_setAmbientLight(pbrInfo);
7910
- color += calculateFinalColor(pbrInfo, lighting_uAmbientLight.color);
7819
+ color += calculateFinalColor(pbrInfo, lighting.ambientColor);
7911
7820
 
7912
7821
  // Apply directional light
7913
- for(int i = 0; i < lighting_uDirectionalLightCount; i++) {
7914
- if (i < lighting_uDirectionalLightCount) {
7915
- PBRInfo_setDirectionalLight(pbrInfo, lighting_uDirectionalLight[i].direction);
7916
- color += calculateFinalColor(pbrInfo, lighting_uDirectionalLight[i].color);
7822
+ for(int i = 0; i < lighting.directionalLightCount; i++) {
7823
+ if (i < lighting.directionalLightCount) {
7824
+ PBRInfo_setDirectionalLight(pbrInfo, lighting_getDirectionalLight(i).direction);
7825
+ color += calculateFinalColor(pbrInfo, lighting_getDirectionalLight(i).color);
7917
7826
  }
7918
7827
  }
7919
7828
 
7920
7829
  // Apply point light
7921
- for(int i = 0; i < lighting_uPointLightCount; i++) {
7922
- if (i < lighting_uPointLightCount) {
7923
- PBRInfo_setPointLight(pbrInfo, lighting_uPointLight[i]);
7924
- float attenuation = getPointLightAttenuation(lighting_uPointLight[i], distance(lighting_uPointLight[i].position, pbr_vPosition));
7925
- color += calculateFinalColor(pbrInfo, lighting_uPointLight[i].color / attenuation);
7830
+ for(int i = 0; i < lighting.pointLightCount; i++) {
7831
+ if (i < lighting.pointLightCount) {
7832
+ PBRInfo_setPointLight(pbrInfo, lighting_getPointLight(i));
7833
+ float attenuation = getPointLightAttenuation(lighting_getPointLight(i), distance(lighting_getPointLight(i).position, pbr_vPosition));
7834
+ color += calculateFinalColor(pbrInfo, lighting_getPointLight(i).color / attenuation);
7926
7835
  }
7927
7836
  }
7928
7837
  #endif
7929
7838
 
7930
7839
  // Calculate lighting contribution from image based lighting source (IBL)
7931
7840
  #ifdef USE_IBL
7932
- if (u_pbrMateral.IBLEnabled) {
7841
+ if (pbrMaterial.IBLenabled) {
7933
7842
  color += getIBLContribution(pbrInfo, n, reflection);
7934
7843
  }
7935
7844
  #endif
7936
7845
 
7937
- // Apply optional PBR terms for additional (optional) shading
7846
+ // Apply optional PBR terms for additional (optional) shading
7938
7847
  #ifdef HAS_OCCLUSIONMAP
7939
- if (u_pbrMaterial.occlusionMapEnabled) {
7940
- float ao = texture2D(u_OcclusionSampler, pbr_vUV).r;
7941
- color = mix(color, color * ao, u_pbrMaterial.occlusionStrength);
7848
+ if (pbrMaterial.occlusionMapEnabled) {
7849
+ float ao = texture(pbr_occlusionSampler, pbr_vUV).r;
7850
+ color = mix(color, color * ao, pbrMaterial.occlusionStrength);
7942
7851
  }
7943
7852
  #endif
7944
7853
 
7945
7854
  #ifdef HAS_EMISSIVEMAP
7946
- if (u_pbrMaterial.emmissiveMapEnabled) {
7947
- vec3 emissive = SRGBtoLINEAR(texture2D(u_EmissiveSampler, pbr_vUV)).rgb * u_pbrMaterial.emissiveFactor;
7855
+ if (pbrMaterial.emissiveMapEnabled) {
7856
+ vec3 emissive = SRGBtoLINEAR(texture(pbr_emissiveSampler, pbr_vUV)).rgb * pbrMaterial.emissiveFactor;
7948
7857
  color += emissive;
7949
7858
  }
7950
7859
  #endif
@@ -7954,15 +7863,15 @@ vec4 pbr_filterColor(vec4 colorUnused)
7954
7863
  #ifdef PBR_DEBUG
7955
7864
  // TODO: Figure out how to debug multiple lights
7956
7865
 
7957
- // color = mix(color, F, u_ScaleFGDSpec.x);
7958
- // color = mix(color, vec3(G), u_ScaleFGDSpec.y);
7959
- // color = mix(color, vec3(D), u_ScaleFGDSpec.z);
7960
- // color = mix(color, specContrib, u_ScaleFGDSpec.w);
7866
+ // color = mix(color, F, pbr_scaleFGDSpec.x);
7867
+ // color = mix(color, vec3(G), pbr_scaleFGDSpec.y);
7868
+ // color = mix(color, vec3(D), pbr_scaleFGDSpec.z);
7869
+ // color = mix(color, specContrib, pbr_scaleFGDSpec.w);
7961
7870
 
7962
- // color = mix(color, diffuseContrib, u_ScaleDiffBaseMR.x);
7963
- color = mix(color, baseColor.rgb, u_pbrMaterial.scaleDiffBaseMR.y);
7964
- color = mix(color, vec3(metallic), u_pbrMaterial.scaleDiffBaseMR.z);
7965
- color = mix(color, vec3(perceptualRoughness), u_pbrMaterial.scaleDiffBaseMR.w);
7871
+ // color = mix(color, diffuseContrib, pbr_scaleDiffBaseMR.x);
7872
+ color = mix(color, baseColor.rgb, pbrMaterial.scaleDiffBaseMR.y);
7873
+ color = mix(color, vec3(metallic), pbrMaterial.scaleDiffBaseMR.z);
7874
+ color = mix(color, vec3(perceptualRoughness), pbrMaterial.scaleDiffBaseMR.w);
7966
7875
  #endif
7967
7876
 
7968
7877
  }
@@ -7972,25 +7881,52 @@ vec4 pbr_filterColor(vec4 colorUnused)
7972
7881
  `
7973
7882
  );
7974
7883
 
7884
+ // src/modules/lighting/pbr-material/pbr-projection.ts
7885
+ var uniformBlock = (
7886
+ /* glsl */
7887
+ `uniform pbrProjectionUniforms {
7888
+ mat4 modelViewProjectionMatrix;
7889
+ mat4 modelMatrix;
7890
+ mat4 normalMatrix;
7891
+ vec3 camera;
7892
+ } pbrProjection;
7893
+ `
7894
+ );
7895
+ var pbrProjection = {
7896
+ name: "pbrProjection",
7897
+ vs: uniformBlock,
7898
+ fs: uniformBlock,
7899
+ // TODO why is this needed?
7900
+ getUniforms: (props) => props,
7901
+ uniformTypes: {
7902
+ modelViewProjectionMatrix: "mat4x4<f32>",
7903
+ modelMatrix: "mat4x4<f32>",
7904
+ normalMatrix: "mat4x4<f32>",
7905
+ camera: "vec3<i32>"
7906
+ }
7907
+ };
7908
+
7975
7909
  // src/modules/lighting/pbr-material/pbr-material.ts
7976
7910
  var pbrMaterial = {
7977
7911
  props: {},
7978
7912
  uniforms: {},
7979
- name: "pbr",
7980
- dependencies: [lighting],
7913
+ name: "pbrMaterial",
7914
+ dependencies: [lighting, pbrProjection],
7981
7915
  vs: vs2,
7982
7916
  fs: fs3,
7983
7917
  defines: {
7984
- LIGHTING_FRAGMENT: 1,
7985
- HAS_NORMALMAP: 0,
7986
- HAS_EMISSIVEMAP: 0,
7987
- HAS_OCCLUSIONMAP: 0,
7988
- HAS_BASECOLORMAP: 0,
7989
- HAS_METALROUGHNESSMAP: 0,
7990
- ALPHA_CUTOFF: 0,
7991
- USE_IBL: 0,
7992
- PBR_DEBUG: 0
7918
+ LIGHTING_FRAGMENT: 1
7919
+ // TODO defining these as 0 breaks shader
7920
+ // HAS_NORMALMAP: 0
7921
+ // HAS_EMISSIVEMAP: 0,
7922
+ // HAS_OCCLUSIONMAP: 0,
7923
+ // HAS_BASECOLORMAP: 0,
7924
+ // HAS_METALROUGHNESSMAP: 0,
7925
+ // ALPHA_CUTOFF: 0
7926
+ // USE_IBL: 0
7927
+ // PBR_DEBUG: 0
7993
7928
  },
7929
+ getUniforms: (props) => props,
7994
7930
  uniformTypes: {
7995
7931
  // Material is unlit
7996
7932
  unlit: "i32",
@@ -8019,25 +7955,6 @@ vec4 pbr_filterColor(vec4 colorUnused)
8019
7955
  // #ifdef PBR_DEBUG
8020
7956
  scaleDiffBaseMR: "vec4<f32>",
8021
7957
  scaleFGDSpec: "vec4<f32>"
8022
- },
8023
- bindings: {
8024
- baseColorSampler: { type: "texture", location: 8 },
8025
- // #ifdef HAS_BASECOLORMAP
8026
- normalSampler: { type: "texture", location: 9 },
8027
- // #ifdef HAS_NORMALMAP
8028
- emissiveSampler: { type: "texture", location: 10 },
8029
- // #ifdef HAS_EMISSIVEMAP
8030
- metallicRoughnessSampler: { type: "texture", location: 11 },
8031
- // #ifdef HAS_METALROUGHNESSMAP
8032
- occlusionSampler: { type: "texture", location: 12 },
8033
- // #ifdef HAS_OCCLUSIONMAP
8034
- // IBL Samplers
8035
- diffuseEnvSampler: { type: "texture", location: 13 },
8036
- // #ifdef USE_IBL (samplerCube)
8037
- specularEnvSampler: { type: "texture", location: 14 },
8038
- // #ifdef USE_IBL (samplerCube)
8039
- brdfLUT: { type: "texture", location: 15 }
8040
- // #ifdef USE_IBL
8041
7958
  }
8042
7959
  };
8043
7960
 
@@ -8087,7 +8004,6 @@ vec4 brightnessContrast_filterColor_ext(vec4 color, vec2 texSize, vec2 texCoord)
8087
8004
  );
8088
8005
  var brightnessContrast = {
8089
8006
  props: {},
8090
- uniforms: {},
8091
8007
  name: "brightnessContrast",
8092
8008
  uniformTypes: {
8093
8009
  brightness: "f32",
@@ -8186,7 +8102,6 @@ vec4 hueSaturation_filterColor_ext(vec4 color, vec2 texSize, vec2 texCoord) {
8186
8102
  );
8187
8103
  var hueSaturation = {
8188
8104
  props: {},
8189
- uniforms: {},
8190
8105
  name: "hueSaturation",
8191
8106
  fs: fs6,
8192
8107
  uniformTypes: {
@@ -8297,6 +8212,9 @@ vec4 vibrance_filterColor_ext(vec4 color, vec2 texSize, vec2 texCoord) {
8297
8212
  props: {},
8298
8213
  uniforms: {},
8299
8214
  name: "vibrance",
8215
+ uniformTypes: {
8216
+ amount: "f32"
8217
+ },
8300
8218
  propTypes: {
8301
8219
  amount: { value: 0, min: -1, max: 1 }
8302
8220
  },
@@ -8630,11 +8548,11 @@ vec4 dotScreen_filterColor_ext(vec4 color, vec2 texSize, vec2 texCoord) {
8630
8548
  /* glsl */
8631
8549
  `uniform edgeWorkUniforms {
8632
8550
  float radius;
8633
- vec2 delta;
8551
+ int mode;
8634
8552
  } edgeWork;
8635
8553
 
8636
- vec4 edgeWork_sampleColor1(sampler2D source, vec2 texSize, vec2 texCoord) {
8637
- vec2 relativeDelta = edgeWork.radius * edgeWork.delta / texSize;
8554
+ vec4 edgeWork_sampleColorRGB(sampler2D source, vec2 texSize, vec2 texCoord, vec2 delta) {
8555
+ vec2 relativeDelta = edgeWork.radius * delta / texSize;
8638
8556
 
8639
8557
  vec2 color = vec2(0.0);
8640
8558
  vec2 total = vec2(0.0);
@@ -8658,8 +8576,8 @@ vec4 edgeWork_sampleColor1(sampler2D source, vec2 texSize, vec2 texCoord) {
8658
8576
  return vec4(color / total, 0.0, 1.0);
8659
8577
  }
8660
8578
 
8661
- vec4 edgeWork_sampleColor2(sampler2D source, vec2 texSize, vec2 texCoord) {
8662
- vec2 relativeDelta = edgeWork.radius * edgeWork.delta / texSize;
8579
+ vec4 edgeWork_sampleColorXY(sampler2D source, vec2 texSize, vec2 texCoord, vec2 delta) {
8580
+ vec2 relativeDelta = edgeWork.radius * delta / texSize;
8663
8581
 
8664
8582
  vec2 color = vec2(0.0);
8665
8583
  vec2 total = vec2(0.0);
@@ -8682,6 +8600,16 @@ vec4 edgeWork_sampleColor2(sampler2D source, vec2 texSize, vec2 texCoord) {
8682
8600
  float c = clamp(10000.0 * (color.y / total.y - color.x / total.x) + 0.5, 0.0, 1.0);
8683
8601
  return vec4(c, c, c, 1.0);
8684
8602
  }
8603
+
8604
+ vec4 edgeWork_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
8605
+ switch (edgeWork.mode) {
8606
+ case 0:
8607
+ return edgeWork_sampleColorRGB(source, texSize, texCoord, vec2(1., 0.));
8608
+ case 1:
8609
+ default:
8610
+ return edgeWork_sampleColorXY(source, texSize, texCoord, vec2(0., 1.));
8611
+ }
8612
+ }
8685
8613
  `
8686
8614
  );
8687
8615
  var edgeWork = {
@@ -8690,20 +8618,22 @@ vec4 edgeWork_sampleColor2(sampler2D source, vec2 texSize, vec2 texCoord) {
8690
8618
  name: "edgeWork",
8691
8619
  dependencies: [random],
8692
8620
  fs: fs16,
8621
+ uniformTypes: {
8622
+ radius: "f32",
8623
+ mode: "i32"
8624
+ },
8693
8625
  propTypes: {
8694
8626
  radius: { value: 2, min: 1, softMax: 50 },
8695
- delta: { value: [1, 0], private: true }
8627
+ mode: { value: 0, private: true }
8696
8628
  },
8697
8629
  passes: [
8698
8630
  {
8699
- // @ts-expect-error
8700
- sampler: "edgeWork_sampleColor1",
8701
- propTypes: { delta: [1, 0] }
8631
+ sampler: true,
8632
+ uniforms: { mode: 0 }
8702
8633
  },
8703
8634
  {
8704
- // @ts-expect-error
8705
- sampler: "edgeWork_sampleColor2",
8706
- propTypes: { delta: [0, 1] }
8635
+ sampler: true,
8636
+ uniforms: { mode: 1 }
8707
8637
  }
8708
8638
  ]
8709
8639
  };
@@ -8989,7 +8919,9 @@ vec4 swirl_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
8989
8919
  };
8990
8920
 
8991
8921
  // src/passes/postprocessing/fxaa/fxaa.ts
8992
- var fs23 = `
8922
+ var fs23 = (
8923
+ /* glsl */
8924
+ `
8993
8925
  #define FXAA_QUALITY_PRESET 29
8994
8926
 
8995
8927
  #if (FXAA_QUALITY_PRESET == 10)
@@ -9569,7 +9501,8 @@ vec4 fxaa_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
9569
9501
  fxaa_QualityEdgeThresholdMin
9570
9502
  );
9571
9503
  }
9572
- `;
9504
+ `
9505
+ );
9573
9506
  var fxaa = {
9574
9507
  name: "fxaa",
9575
9508
  propTypes: {},