@luma.gl/shadertools 9.0.19 → 9.0.20

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.
package/dist/dist.dev.js CHANGED
@@ -408,13 +408,13 @@ ${moduleSource}
408
408
  return this.defines;
409
409
  }
410
410
  // Warn about deprecated uniforms or functions
411
- checkDeprecations(shaderSource, log2) {
411
+ checkDeprecations(shaderSource, log3) {
412
412
  this.deprecations.forEach((def) => {
413
413
  if (def.regex?.test(shaderSource)) {
414
414
  if (def.deprecated) {
415
- log2.deprecated(def.old, def.new)();
415
+ log3.deprecated(def.old, def.new)();
416
416
  } else {
417
- log2.removed(def.old, def.new)();
417
+ log3.removed(def.old, def.new)();
418
418
  }
419
419
  }
420
420
  });
@@ -752,7 +752,7 @@ precision highp float;
752
752
  // defines = {},
753
753
  hookFunctions = [],
754
754
  inject = {},
755
- log: log2
755
+ log: log3
756
756
  } = options;
757
757
  assert(typeof source === "string", "shader source must be a string");
758
758
  const coreSource = source;
@@ -782,8 +782,8 @@ precision highp float;
782
782
  }
783
783
  const modulesToInject = platformInfo.type !== "webgpu" ? modules : [];
784
784
  for (const module of modulesToInject) {
785
- if (log2) {
786
- module.checkDeprecations(coreSource, log2);
785
+ if (log3) {
786
+ module.checkDeprecations(coreSource, log3);
787
787
  }
788
788
  const moduleSource = module.getModuleSource(stage, "wgsl");
789
789
  assembledSource += moduleSource;
@@ -819,7 +819,7 @@ precision highp float;
819
819
  hookFunctions = [],
820
820
  inject = {},
821
821
  prologue = true,
822
- log: log2
822
+ log: log3
823
823
  } = options;
824
824
  assert(typeof source === "string", "shader source must be a string");
825
825
  const sourceVersion = language === "glsl" ? getShaderInfo(source).version : -1;
@@ -877,8 +877,8 @@ ${getApplicationDefines(allDefines)}
877
877
  }
878
878
  }
879
879
  for (const module of modules) {
880
- if (log2) {
881
- module.checkDeprecations(coreSource, log2);
880
+ if (log3) {
881
+ module.checkDeprecations(coreSource, log3);
882
882
  }
883
883
  const moduleSource = module.getModuleSource(stage);
884
884
  assembledSource += moduleSource;
@@ -5119,22 +5119,44 @@ uniform lightingUniforms {
5119
5119
 
5120
5120
  vec3 ambientColor;
5121
5121
 
5122
- vec3 lightColor;
5123
- vec3 lightPosition;
5124
- vec3 lightDirection;
5125
- vec3 lightAttenuation;
5122
+ vec3 lightColor0;
5123
+ vec3 lightPosition0;
5124
+ vec3 lightDirection0;
5125
+ vec3 lightAttenuation0;
5126
+
5127
+ vec3 lightColor1;
5128
+ vec3 lightPosition1;
5129
+ vec3 lightDirection1;
5130
+ vec3 lightAttenuation1;
5126
5131
 
5127
- // AmbientLight ambientLight;
5128
- // PointLight pointLight[MAX_LIGHTS];
5129
- // DirectionalLight directionalLight[MAX_LIGHTS];
5132
+ vec3 lightColor2;
5133
+ vec3 lightPosition2;
5134
+ vec3 lightDirection2;
5135
+ vec3 lightAttenuation2;
5130
5136
  } lighting;
5131
5137
 
5132
5138
  PointLight lighting_getPointLight(int index) {
5133
- return PointLight(lighting.lightColor, lighting.lightPosition, lighting.lightAttenuation);
5139
+ switch (index) {
5140
+ case 0:
5141
+ return PointLight(lighting.lightColor0, lighting.lightPosition0, lighting.lightAttenuation0);
5142
+ case 1:
5143
+ return PointLight(lighting.lightColor1, lighting.lightPosition1, lighting.lightAttenuation1);
5144
+ case 2:
5145
+ default:
5146
+ return PointLight(lighting.lightColor2, lighting.lightPosition2, lighting.lightAttenuation2);
5147
+ }
5134
5148
  }
5135
5149
 
5136
5150
  DirectionalLight lighting_getDirectionalLight(int index) {
5137
- return DirectionalLight(lighting.lightColor, lighting.lightDirection);
5151
+ switch (index) {
5152
+ case 0:
5153
+ return DirectionalLight(lighting.lightColor0, lighting.lightDirection0);
5154
+ case 1:
5155
+ return DirectionalLight(lighting.lightColor1, lighting.lightDirection1);
5156
+ case 2:
5157
+ default:
5158
+ return DirectionalLight(lighting.lightColor2, lighting.lightDirection2);
5159
+ }
5138
5160
  }
5139
5161
 
5140
5162
  float getPointLightAttenuation(PointLight pointLight, float distance) {
@@ -5147,7 +5169,8 @@ float getPointLightAttenuation(PointLight pointLight, float distance) {
5147
5169
  `;
5148
5170
 
5149
5171
  // src/modules/lighting/lights/lighting-uniforms.ts
5150
- var MAX_LIGHTS = 5;
5172
+ var import_core2 = __toESM(require_core(), 1);
5173
+ var MAX_LIGHTS = 3;
5151
5174
  var COLOR_FACTOR = 255;
5152
5175
  var lighting = {
5153
5176
  name: "lighting",
@@ -5162,21 +5185,23 @@ float getPointLightAttenuation(PointLight pointLight, float distance) {
5162
5185
  uniformTypes: {
5163
5186
  enabled: "i32",
5164
5187
  lightType: "i32",
5165
- // , array: MAX_LIGHTS,
5166
5188
  directionalLightCount: "i32",
5167
- // , array: MAX_LIGHTS,
5168
5189
  pointLightCount: "i32",
5169
- // , array: MAX_LIGHTS,
5170
5190
  ambientLightColor: "vec3<f32>",
5171
- lightColor: "vec3<f32>",
5172
- // , array: MAX_LIGHTS,
5173
- lightPosition: "vec3<f32>",
5174
- // , array: MAX_LIGHTS,
5191
+ // TODO define as arrays once we have appropriate uniformTypes
5192
+ lightColor0: "vec3<f32>",
5193
+ lightPosition0: "vec3<f32>",
5175
5194
  // TODO - could combine direction and attenuation
5176
- lightDirection: "vec3<f32>",
5177
- // , array: MAX_LIGHTS,
5178
- lightAttenuation: "vec3<f32>"
5179
- // , array: MAX_LIGHTS},
5195
+ lightDirection0: "vec3<f32>",
5196
+ lightAttenuation0: "vec3<f32>",
5197
+ lightColor1: "vec3<f32>",
5198
+ lightPosition1: "vec3<f32>",
5199
+ lightDirection1: "vec3<f32>",
5200
+ lightAttenuation1: "vec3<f32>",
5201
+ lightColor2: "vec3<f32>",
5202
+ lightPosition2: "vec3<f32>",
5203
+ lightDirection2: "vec3<f32>",
5204
+ lightAttenuation2: "vec3<f32>"
5180
5205
  },
5181
5206
  defaultUniforms: {
5182
5207
  enabled: 1,
@@ -5184,11 +5209,19 @@ float getPointLightAttenuation(PointLight pointLight, float distance) {
5184
5209
  directionalLightCount: 0,
5185
5210
  pointLightCount: 0,
5186
5211
  ambientLightColor: [0.1, 0.1, 0.1],
5187
- lightColor: [1, 1, 1],
5188
- lightPosition: [1, 1, 2],
5212
+ lightColor0: [1, 1, 1],
5213
+ lightPosition0: [1, 1, 2],
5189
5214
  // TODO - could combine direction and attenuation
5190
- lightDirection: [1, 1, 1],
5191
- lightAttenuation: [1, 1, 1]
5215
+ lightDirection0: [1, 1, 1],
5216
+ lightAttenuation0: [1, 1, 1],
5217
+ lightColor1: [1, 1, 1],
5218
+ lightPosition1: [1, 1, 2],
5219
+ lightDirection1: [1, 1, 1],
5220
+ lightAttenuation1: [1, 1, 1],
5221
+ lightColor2: [1, 1, 1],
5222
+ lightPosition2: [1, 1, 2],
5223
+ lightDirection2: [1, 1, 1],
5224
+ lightAttenuation2: [1, 1, 1]
5192
5225
  }
5193
5226
  };
5194
5227
  function getUniforms2(props, prevUniforms = {}) {
@@ -5219,29 +5252,27 @@ float getPointLightAttenuation(PointLight pointLight, float distance) {
5219
5252
  pointLights = [],
5220
5253
  directionalLights = []
5221
5254
  }) {
5222
- const lightSourceUniforms = {
5223
- // lightType: new Array(MAX_LIGHTS).fill(0),
5224
- // lightColor: new Array(MAX_LIGHTS).fill([0, 0, 0]),
5225
- // lightPosition: new Array(MAX_LIGHTS).fill([0, 0, 0]),
5226
- // lightDirection: new Array(MAX_LIGHTS).fill([0, 0, 0]),
5227
- // lightAttenuation: new Array(MAX_LIGHTS).fill([0, 0, 0])
5228
- };
5255
+ const lightSourceUniforms = {};
5229
5256
  lightSourceUniforms.ambientLightColor = convertColor(ambientLight);
5230
5257
  let currentLight = 0;
5231
5258
  for (const pointLight of pointLights) {
5232
5259
  lightSourceUniforms.lightType = 0 /* POINT */;
5233
- lightSourceUniforms.lightColor = convertColor(pointLight);
5234
- lightSourceUniforms.lightPosition = pointLight.position;
5235
- lightSourceUniforms.lightAttenuation = [pointLight.attenuation || 1, 0, 0];
5260
+ const i = currentLight;
5261
+ lightSourceUniforms[`lightColor${i}`] = convertColor(pointLight);
5262
+ lightSourceUniforms[`lightPosition${i}`] = pointLight.position;
5263
+ lightSourceUniforms[`lightAttenuation${i}`] = [pointLight.attenuation || 1, 0, 0];
5236
5264
  currentLight++;
5237
5265
  }
5238
5266
  for (const directionalLight of directionalLights) {
5239
5267
  lightSourceUniforms.lightType = 1 /* DIRECTIONAL */;
5240
- lightSourceUniforms.lightColor = convertColor(directionalLight);
5241
- lightSourceUniforms.lightPosition = directionalLight.position;
5242
- lightSourceUniforms.lightDirection = directionalLight.direction;
5268
+ const i = currentLight;
5269
+ lightSourceUniforms[`lightColor${i}`] = convertColor(directionalLight);
5270
+ lightSourceUniforms[`lightDirection${i}`] = directionalLight.direction;
5243
5271
  currentLight++;
5244
5272
  }
5273
+ if (currentLight > MAX_LIGHTS) {
5274
+ import_core2.log.warn("MAX_LIGHTS exceeded")();
5275
+ }
5245
5276
  lightSourceUniforms.directionalLightCount = directionalLights.length;
5246
5277
  lightSourceUniforms.pointLightCount = pointLights.length;
5247
5278
  return lightSourceUniforms;
@@ -5317,9 +5348,17 @@ vec4 dirlight_filterColor(vec4 color) {
5317
5348
  return uniforms;
5318
5349
  }
5319
5350
 
5320
- // src/modules/lighting/gouraud-material/gouraud-shaders-glsl.ts
5321
- var GOURAUD_VS = glsl`\
5322
- uniform gouraudMaterialUniforms {
5351
+ // src/modules/lighting/phong-material/phong-shaders-glsl.ts
5352
+ var PHONG_VS = glsl`\
5353
+ uniform phongMaterialUniforms {
5354
+ uniform float ambient;
5355
+ uniform float diffuse;
5356
+ uniform float shininess;
5357
+ uniform vec3 specularColor;
5358
+ } material;
5359
+ `;
5360
+ var PHONG_FS = glsl`\
5361
+ uniform phongMaterialUniforms {
5323
5362
  uniform float ambient;
5324
5363
  uniform float diffuse;
5325
5364
  uniform float shininess;
@@ -5348,79 +5387,31 @@ vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 positio
5348
5387
  vec3 view_direction = normalize(cameraPosition - position_worldspace);
5349
5388
  lightColor = material.ambient * surfaceColor * lighting.ambientColor;
5350
5389
 
5351
- if (lighting.lightType == 0) {
5352
- PointLight pointLight = lighting_getPointLight(0);
5390
+ for (int i = 0; i < lighting.pointLightCount; i++) {
5391
+ PointLight pointLight = lighting_getPointLight(i);
5353
5392
  vec3 light_position_worldspace = pointLight.position;
5354
5393
  vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
5355
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
5356
- } else if (lighting.lightType == 1) {
5357
- DirectionalLight directionalLight = lighting_getDirectionalLight(0);
5358
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
5359
- }
5360
- /*
5361
- for (int i = 0; i < MAX_LIGHTS; i++) {
5362
- if (i >= lighting.pointLightCount) {
5363
- break;
5364
- }
5365
- PointLight pointLight = lighting.pointLight[i];
5366
- vec3 light_position_worldspace = pointLight.position;
5367
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
5368
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
5394
+ float light_attenuation = getPointLightAttenuation(pointLight, distance(light_position_worldspace, position_worldspace));
5395
+ lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color / light_attenuation);
5369
5396
  }
5370
5397
 
5371
- for (int i = 0; i < MAX_LIGHTS; i++) {
5372
- if (i >= lighting.directionalLightCount) {
5373
- break;
5374
- }
5375
- DirectionalLight directionalLight = lighting.directionalLight[i];
5398
+ int totalLights = min(MAX_LIGHTS, lighting.pointLightCount + lighting.directionalLightCount);
5399
+ for (int i = lighting.pointLightCount; i < totalLights; i++) {
5400
+ DirectionalLight directionalLight = lighting_getDirectionalLight(i);
5376
5401
  lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
5377
5402
  }
5378
- */
5403
+
5379
5404
  return lightColor;
5380
5405
  }
5381
5406
 
5382
- vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
5383
- vec3 lightColor = vec3(0, 0, 0);
5384
- vec3 surfaceColor = vec3(0, 0, 0);
5385
-
5386
- if (lighting.enabled == 0) {
5387
- return lightColor;
5388
- }
5389
-
5390
- vec3 view_direction = normalize(cameraPosition - position_worldspace);
5391
-
5392
- switch (lighting.lightType) {
5393
- case 0:
5394
- PointLight pointLight = lighting_getPointLight(0);
5395
- vec3 light_position_worldspace = pointLight.position;
5396
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
5397
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
5398
- break;
5399
-
5400
- case 1:
5401
- DirectionalLight directionalLight = lighting_getDirectionalLight(0);
5402
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
5403
- break;
5404
- }
5405
-
5406
- return lightColor;
5407
- }
5408
- `;
5409
- var GOURAUD_FS = glsl`\
5410
- uniform gouraudMaterialUniforms {
5411
- uniform float ambient;
5412
- uniform float diffuse;
5413
- uniform float shininess;
5414
- uniform vec3 specularColor;
5415
- } material;
5416
5407
  `;
5417
5408
 
5418
5409
  // src/modules/lighting/gouraud-material/gouraud-material.ts
5419
5410
  var gouraudMaterial = {
5420
5411
  name: "gouraudMaterial",
5421
5412
  // Note these are switched between phong and gouraud
5422
- vs: GOURAUD_VS,
5423
- fs: GOURAUD_FS,
5413
+ vs: PHONG_FS.replace("phongMaterial", "gouraudMaterial"),
5414
+ fs: PHONG_VS.replace("phongMaterial", "gouraudMaterial"),
5424
5415
  defines: {
5425
5416
  LIGHTING_VERTEX: 1
5426
5417
  },
@@ -5442,104 +5433,6 @@ uniform gouraudMaterialUniforms {
5442
5433
  }
5443
5434
  };
5444
5435
 
5445
- // src/modules/lighting/phong-material/phong-shaders-glsl.ts
5446
- var PHONG_VS = glsl`\
5447
- uniform phongMaterialUniforms {
5448
- uniform float ambient;
5449
- uniform float diffuse;
5450
- uniform float shininess;
5451
- uniform vec3 specularColor;
5452
- } material;
5453
- `;
5454
- var PHONG_FS = glsl`\
5455
- uniform phongMaterialUniforms {
5456
- uniform float ambient;
5457
- uniform float diffuse;
5458
- uniform float shininess;
5459
- uniform vec3 specularColor;
5460
- } material;
5461
-
5462
- vec3 lighting_getLightColor(vec3 surfaceColor, vec3 light_direction, vec3 view_direction, vec3 normal_worldspace, vec3 color) {
5463
- vec3 halfway_direction = normalize(light_direction + view_direction);
5464
- float lambertian = dot(light_direction, normal_worldspace);
5465
- float specular = 0.0;
5466
- if (lambertian > 0.0) {
5467
- float specular_angle = max(dot(normal_worldspace, halfway_direction), 0.0);
5468
- specular = pow(specular_angle, material.shininess);
5469
- }
5470
- lambertian = max(lambertian, 0.0);
5471
- return (lambertian * material.diffuse * surfaceColor + specular * material.specularColor) * color;
5472
- }
5473
-
5474
- vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
5475
- vec3 lightColor = surfaceColor;
5476
-
5477
- if (lighting.enabled == 0) {
5478
- return lightColor;
5479
- }
5480
-
5481
- vec3 view_direction = normalize(cameraPosition - position_worldspace);
5482
- lightColor = material.ambient * surfaceColor * lighting.ambientColor;
5483
-
5484
- if (lighting.lightType == 0) {
5485
- PointLight pointLight = lighting_getPointLight(0);
5486
- vec3 light_position_worldspace = pointLight.position;
5487
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
5488
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
5489
- } else if (lighting.lightType == 1) {
5490
- DirectionalLight directionalLight = lighting_getDirectionalLight(0);
5491
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
5492
- }
5493
-
5494
- /*
5495
- for (int i = 0; i < MAX_LIGHTS; i++) {
5496
- if (i >= lighting.pointLightCount) {
5497
- break;
5498
- }
5499
- PointLight pointLight = lighting.pointLight[i];
5500
- vec3 light_position_worldspace = pointLight.position;
5501
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
5502
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
5503
- }
5504
-
5505
- for (int i = 0; i < MAX_LIGHTS; i++) {
5506
- if (i >= lighting.directionalLightCount) {
5507
- break;
5508
- }
5509
- DirectionalLight directionalLight = lighting.directionalLight[i];
5510
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
5511
- }
5512
- */
5513
- return lightColor;
5514
- }
5515
-
5516
- vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
5517
- vec3 lightColor = vec3(0, 0, 0);
5518
- vec3 surfaceColor = vec3(0, 0, 0);
5519
-
5520
- if (lighting.enabled == 0) {
5521
- return lightColor;
5522
- }
5523
-
5524
- vec3 view_direction = normalize(cameraPosition - position_worldspace);
5525
-
5526
- switch (lighting.lightType) {
5527
- case 0:
5528
- PointLight pointLight = lighting_getPointLight(0);
5529
- vec3 light_position_worldspace = pointLight.position;
5530
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
5531
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
5532
- break;
5533
-
5534
- case 1:
5535
- DirectionalLight directionalLight = lighting_getDirectionalLight(0);
5536
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
5537
- break;
5538
- }
5539
- return lightColor;
5540
- }
5541
- `;
5542
-
5543
5436
  // src/modules/lighting/phong-material/phong-material.ts
5544
5437
  var phongMaterial = {
5545
5438
  name: "phongMaterial",