@luma.gl/shadertools 9.0.0-alpha.48 → 9.0.0-alpha.50

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
@@ -316,7 +316,7 @@ ${inject[key]}` : inject[key];
316
316
  if (module instanceof ShaderModuleInstance) {
317
317
  return module;
318
318
  }
319
- assert(typeof module !== "string", `Shader module use by name is deprecated. Import shader module '${module}' and use it directly.`);
319
+ assert(typeof module !== "string", `Shader module use by name is deprecated. Import shader module '${JSON.stringify(module)}' and use it directly.`);
320
320
  if (!module.name) {
321
321
  console.warn("shader module has no name");
322
322
  module.name = `shader-module-${index++}`;
@@ -1112,7 +1112,7 @@ ${FS_GLES}`;
1112
1112
  const {
1113
1113
  version = 100,
1114
1114
  input,
1115
- inputType,
1115
+ inputChannels,
1116
1116
  output
1117
1117
  } = options || {};
1118
1118
  if (!input) {
@@ -1124,10 +1124,11 @@ ${FS_GLES}`;
1124
1124
  }
1125
1125
  return FS100;
1126
1126
  }
1127
- if (!inputType) {
1128
- throw new Error("inputType");
1127
+ if (!inputChannels) {
1128
+ throw new Error("inputChannels");
1129
1129
  }
1130
- const outputValue = convertToVec4(input, inputType);
1130
+ const inputType = channelCountToType(inputChannels);
1131
+ const outputValue = convertToVec4(input, inputChannels);
1131
1132
  if (version >= 300) {
1132
1133
  return `#version ${version} ${version === 300 ? "es" : ""}
1133
1134
  in ${inputType} ${input};
@@ -1169,18 +1170,32 @@ void main() {
1169
1170
  throw new Error(type);
1170
1171
  }
1171
1172
  }
1172
- function convertToVec4(variable, type) {
1173
- switch (type) {
1174
- case "float":
1173
+ function channelCountToType(channels) {
1174
+ switch (channels) {
1175
+ case 1:
1176
+ return "float";
1177
+ case 2:
1178
+ return "vec2";
1179
+ case 3:
1180
+ return "vec3";
1181
+ case 4:
1182
+ return "vec4";
1183
+ default:
1184
+ throw new Error(`invalid channels: ${channels}`);
1185
+ }
1186
+ }
1187
+ function convertToVec4(variable, channels) {
1188
+ switch (channels) {
1189
+ case 1:
1175
1190
  return `vec4(${variable}, 0.0, 0.0, 1.0)`;
1176
- case "vec2":
1191
+ case 2:
1177
1192
  return `vec4(${variable}, 0.0, 1.0)`;
1178
- case "vec3":
1193
+ case 3:
1179
1194
  return `vec4(${variable}, 1.0)`;
1180
- case "vec4":
1195
+ case 4:
1181
1196
  return variable;
1182
1197
  default:
1183
- throw new Error(type);
1198
+ throw new Error(`invalid channels: ${channels}`);
1184
1199
  }
1185
1200
  }
1186
1201
 
@@ -4339,27 +4354,24 @@ vec4 picking_filterColor(vec4 color) {
4339
4354
  uniformTypes: {
4340
4355
  isActive: "f32",
4341
4356
  isAttribute: "f32",
4342
- useFloatColors: "f32",
4343
4357
  isHighlightActive: "f32",
4358
+ useFloatColors: "f32",
4344
4359
  highlightedObjectColor: "vec3<f32>",
4345
4360
  highlightColor: "vec4<f32>"
4346
4361
  },
4347
4362
  defaultUniforms: {
4348
4363
  isActive: false,
4349
4364
  isAttribute: false,
4350
- useFloatColors: true,
4351
4365
  isHighlightActive: false,
4366
+ useFloatColors: true,
4352
4367
  highlightedObjectColor: new Float32Array([0, 0, 0]),
4353
4368
  highlightColor: DEFAULT_HIGHLIGHT_COLOR
4354
4369
  },
4355
4370
  getUniforms
4356
4371
  };
4357
4372
  function getUniforms(opts = {}, prevUniforms) {
4358
- const uniforms = {
4359
- ...picking.defaultUniforms
4360
- };
4373
+ const uniforms = {};
4361
4374
  if (opts.highlightedObjectColor === void 0) {
4362
- delete uniforms.highlightedObjectColor;
4363
4375
  } else if (opts.highlightedObjectColor === null) {
4364
4376
  uniforms.isHighlightActive = false;
4365
4377
  } else {
@@ -4518,7 +4530,6 @@ float getPointLightAttenuation(PointLight pointLight, float distance) {
4518
4530
  if (props.enabled !== void 0) {
4519
4531
  uniforms.enabled = props.enabled ? 1 : 0;
4520
4532
  }
4521
- console.error(uniforms);
4522
4533
  return uniforms;
4523
4534
  }
4524
4535
  function getLightSourceUniforms({
package/dist/index.cjs CHANGED
@@ -304,7 +304,7 @@ var ShaderModuleInstance = class {
304
304
  }
305
305
  assert(
306
306
  typeof module2 !== "string",
307
- `Shader module use by name is deprecated. Import shader module '${module2}' and use it directly.`
307
+ `Shader module use by name is deprecated. Import shader module '${JSON.stringify(module2)}' and use it directly.`
308
308
  );
309
309
  if (!module2.name) {
310
310
  console.warn("shader module has no name");
@@ -1091,7 +1091,7 @@ function getQualifierDetails(line, qualifiers) {
1091
1091
  return { qualifier, type, name };
1092
1092
  }
1093
1093
  function getPassthroughFS(options) {
1094
- const { version = 100, input, inputType, output } = options || {};
1094
+ const { version = 100, input, inputChannels, output } = options || {};
1095
1095
  if (!input) {
1096
1096
  if (version === 300) {
1097
1097
  return FS300;
@@ -1101,10 +1101,11 @@ ${FS_GLES}`;
1101
1101
  }
1102
1102
  return FS100;
1103
1103
  }
1104
- if (!inputType) {
1105
- throw new Error("inputType");
1104
+ if (!inputChannels) {
1105
+ throw new Error("inputChannels");
1106
1106
  }
1107
- const outputValue = convertToVec4(input, inputType);
1107
+ const inputType = channelCountToType(inputChannels);
1108
+ const outputValue = convertToVec4(input, inputChannels);
1108
1109
  if (version >= 300) {
1109
1110
  return `#version ${version} ${version === 300 ? "es" : ""}
1110
1111
  in ${inputType} ${input};
@@ -1146,18 +1147,32 @@ function typeToChannelCount(type) {
1146
1147
  throw new Error(type);
1147
1148
  }
1148
1149
  }
1149
- function convertToVec4(variable, type) {
1150
- switch (type) {
1151
- case "float":
1150
+ function channelCountToType(channels) {
1151
+ switch (channels) {
1152
+ case 1:
1153
+ return "float";
1154
+ case 2:
1155
+ return "vec2";
1156
+ case 3:
1157
+ return "vec3";
1158
+ case 4:
1159
+ return "vec4";
1160
+ default:
1161
+ throw new Error(`invalid channels: ${channels}`);
1162
+ }
1163
+ }
1164
+ function convertToVec4(variable, channels) {
1165
+ switch (channels) {
1166
+ case 1:
1152
1167
  return `vec4(${variable}, 0.0, 0.0, 1.0)`;
1153
- case "vec2":
1168
+ case 2:
1154
1169
  return `vec4(${variable}, 0.0, 1.0)`;
1155
- case "vec3":
1170
+ case 3:
1156
1171
  return `vec4(${variable}, 1.0)`;
1157
- case "vec4":
1172
+ case 4:
1158
1173
  return variable;
1159
1174
  default:
1160
- throw new Error(type);
1175
+ throw new Error(`invalid channels: ${channels}`);
1161
1176
  }
1162
1177
  }
1163
1178
 
@@ -4425,25 +4440,24 @@ var picking = {
4425
4440
  uniformTypes: {
4426
4441
  isActive: "f32",
4427
4442
  isAttribute: "f32",
4428
- useFloatColors: "f32",
4429
4443
  isHighlightActive: "f32",
4444
+ useFloatColors: "f32",
4430
4445
  highlightedObjectColor: "vec3<f32>",
4431
4446
  highlightColor: "vec4<f32>"
4432
4447
  },
4433
4448
  defaultUniforms: {
4434
4449
  isActive: false,
4435
4450
  isAttribute: false,
4436
- useFloatColors: true,
4437
4451
  isHighlightActive: false,
4452
+ useFloatColors: true,
4438
4453
  highlightedObjectColor: new Float32Array([0, 0, 0]),
4439
4454
  highlightColor: DEFAULT_HIGHLIGHT_COLOR
4440
4455
  },
4441
4456
  getUniforms
4442
4457
  };
4443
4458
  function getUniforms(opts = {}, prevUniforms) {
4444
- const uniforms = { ...picking.defaultUniforms };
4459
+ const uniforms = {};
4445
4460
  if (opts.highlightedObjectColor === void 0) {
4446
- delete uniforms.highlightedObjectColor;
4447
4461
  } else if (opts.highlightedObjectColor === null) {
4448
4462
  uniforms.isHighlightActive = false;
4449
4463
  } else {
@@ -4586,7 +4600,6 @@ function getUniforms2(props, prevUniforms = {}) {
4586
4600
  if (props.enabled !== void 0) {
4587
4601
  uniforms.enabled = props.enabled ? 1 : 0;
4588
4602
  }
4589
- console.error(uniforms);
4590
4603
  return uniforms;
4591
4604
  }
4592
4605
  function getLightSourceUniforms({
@@ -11,7 +11,7 @@ export declare function getQualifierDetails(line: string, qualifiers: string | s
11
11
  export declare function getPassthroughFS(options?: {
12
12
  version?: number;
13
13
  input?: string;
14
- inputType?: string;
14
+ inputChannels?: 1 | 2 | 3 | 4;
15
15
  output?: string;
16
16
  }): string;
17
17
  /** convert glsl type to suffix */
@@ -19,6 +19,6 @@ export declare function typeToChannelSuffix(type: string): 'x' | 'xy' | 'xyz' |
19
19
  /** convert glsl type to channel count */
20
20
  export declare function typeToChannelCount(type: string): 1 | 2 | 3 | 4;
21
21
  /** Returns glsl instruction for converting to vec4 */
22
- export declare function convertToVec4(variable: string, type: string): string;
22
+ export declare function convertToVec4(variable: string, channels: 1 | 2 | 3 | 4): string;
23
23
  export {};
24
24
  //# sourceMappingURL=shader-utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"shader-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/glsl-utils/shader-utils.ts"],"names":[],"mappings":"AAaA,KAAK,aAAa,GAAG;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAA;AAGD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,aAAa,GAAG,IAAI,CAUrG;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,CAAC,EAAE;IACzC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GAAG,MAAM,CAiCT;AAED,kCAAkC;AAClC,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAI,GAAG,GAAG,IAAI,GAAG,KAAK,GAAG,MAAM,CAU9E;AAED,yCAAyC;AACzC,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAU9D;AAED,sDAAsD;AACtD,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAUpE"}
1
+ {"version":3,"file":"shader-utils.d.ts","sourceRoot":"","sources":["../../../src/lib/glsl-utils/shader-utils.ts"],"names":[],"mappings":"AAaA,KAAK,aAAa,GAAG;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd,CAAA;AAGD,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,aAAa,GAAG,IAAI,CAUrG;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,CAAC,EAAE;IACzC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GAAG,MAAM,CAkCT;AAED,kCAAkC;AAClC,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAI,GAAG,GAAG,IAAI,GAAG,KAAK,GAAG,MAAM,CAU9E;AAED,yCAAyC;AACzC,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAU9D;AAaD,sDAAsD;AACtD,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,MAAM,CAU/E"}
@@ -24,7 +24,7 @@ export function getPassthroughFS(options) {
24
24
  const {
25
25
  version = 100,
26
26
  input,
27
- inputType,
27
+ inputChannels,
28
28
  output
29
29
  } = options || {};
30
30
  if (!input) {
@@ -35,10 +35,11 @@ export function getPassthroughFS(options) {
35
35
  }
36
36
  return FS100;
37
37
  }
38
- if (!inputType) {
39
- throw new Error('inputType');
38
+ if (!inputChannels) {
39
+ throw new Error('inputChannels');
40
40
  }
41
- const outputValue = convertToVec4(input, inputType);
41
+ const inputType = channelCountToType(inputChannels);
42
+ const outputValue = convertToVec4(input, inputChannels);
42
43
  if (version >= 300) {
43
44
  return `\
44
45
  #version ${version} ${version === 300 ? 'es' : ''}
@@ -82,18 +83,32 @@ export function typeToChannelCount(type) {
82
83
  throw new Error(type);
83
84
  }
84
85
  }
85
- export function convertToVec4(variable, type) {
86
- switch (type) {
87
- case 'float':
86
+ function channelCountToType(channels) {
87
+ switch (channels) {
88
+ case 1:
89
+ return 'float';
90
+ case 2:
91
+ return 'vec2';
92
+ case 3:
93
+ return 'vec3';
94
+ case 4:
95
+ return 'vec4';
96
+ default:
97
+ throw new Error(`invalid channels: ${channels}`);
98
+ }
99
+ }
100
+ export function convertToVec4(variable, channels) {
101
+ switch (channels) {
102
+ case 1:
88
103
  return `vec4(${variable}, 0.0, 0.0, 1.0)`;
89
- case 'vec2':
104
+ case 2:
90
105
  return `vec4(${variable}, 0.0, 1.0)`;
91
- case 'vec3':
106
+ case 3:
92
107
  return `vec4(${variable}, 1.0)`;
93
- case 'vec4':
108
+ case 4:
94
109
  return variable;
95
110
  default:
96
- throw new Error(type);
111
+ throw new Error(`invalid channels: ${channels}`);
97
112
  }
98
113
  }
99
114
  //# sourceMappingURL=shader-utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"shader-utils.js","names":["glsl","FS100","FS_GLES","FS300","getQualifierDetails","line","qualifiers","Array","isArray","words","replace","split","qualifier","type","definition","includes","name","getPassthroughFS","options","version","input","inputType","output","Error","outputValue","convertToVec4","typeToChannelSuffix","typeToChannelCount","variable"],"sources":["../../../src/lib/glsl-utils/shader-utils.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport {glsl} from './highlight';\n\nconst FS100 = glsl`void main() {gl_FragColor = vec4(0);}`;\nconst FS_GLES = glsl`\\\nout vec4 transform_output;\nvoid main() {\n transform_output = vec4(0);\n}`;\nconst FS300 = `#version 300 es\\n${FS_GLES}`;\n\ntype QualifierInfo = {\n qualifier: string;\n type: string;\n name: string;\n}\n\n// Prase given glsl line and return qualifier details or null\nexport function getQualifierDetails(line: string, qualifiers: string | string[]): QualifierInfo | null {\n qualifiers = Array.isArray(qualifiers) ? qualifiers : [qualifiers];\n const words = line.replace(/^\\s+/, '').split(/\\s+/);\n // TODO add support for precession qualifiers (highp, mediump and lowp)\n const [qualifier, type, definition] = words;\n if (!qualifiers.includes(qualifier) || !type || !definition) {\n return null;\n }\n const name = definition.split(';')[0];\n return {qualifier, type, name};\n}\n\n/**\n * Given the shader version, input and output variable names,\n * builds and return a pass through fragment shader.\n */\nexport function getPassthroughFS(options?: {\n version?: number;\n input?: string;\n inputType?: string;\n output?: string;\n}): string {\n const {version = 100, input, inputType, output} = options || {};\n if (!input) {\n if (version === 300) {\n // Fast-path for WebGL 2.0\n return FS300;\n } else if (version > 300) {\n // Use the supplied version for OpenGL/ES 3.2+\n return `#version ${version}\\n${FS_GLES}`;\n }\n // Fast-path for WebGL 1.0\n return FS100;\n }\n if (!inputType) {\n throw new Error('inputType');\n }\n const outputValue = convertToVec4(input, inputType);\n if (version >= 300) {\n // If version is 300, assume WebGL 2.0\n return `\\\n#version ${version} ${version === 300 ? 'es' : ''}\nin ${inputType} ${input};\nout vec4 ${output};\nvoid main() {\n ${output} = ${outputValue};\n}`;\n }\n // WebGL 1.0\n return `\\\nvarying ${inputType} ${input};\nvoid main() {\n gl_FragColor = ${outputValue};\n}`;\n}\n\n/** convert glsl type to suffix */\nexport function typeToChannelSuffix(type: string): 'x' | 'xy' | 'xyz' | 'xyzw' {\n // prettier-ignore\n switch (type) {\n case 'float': return 'x';\n case 'vec2': return 'xy';\n case 'vec3': return 'xyz';\n case 'vec4': return 'xyzw';\n default:\n throw new Error(type);\n }\n}\n\n/** convert glsl type to channel count */\nexport function typeToChannelCount(type: string): 1 | 2 | 3 | 4 {\n // prettier-ignore\n switch (type) {\n case 'float': return 1;\n case 'vec2': return 2;\n case 'vec3': return 3;\n case 'vec4': return 4;\n default:\n throw new Error(type);\n }\n}\n\n/** Returns glsl instruction for converting to vec4 */\nexport function convertToVec4(variable: string, type: string): string {\n // prettier-ignore\n switch (type) {\n case 'float': return `vec4(${variable}, 0.0, 0.0, 1.0)`;\n case 'vec2': return `vec4(${variable}, 0.0, 1.0)`;\n case 'vec3': return `vec4(${variable}, 1.0)`;\n case 'vec4': return variable;\n default:\n throw new Error(type);\n }\n}\n"],"mappings":"SAGQA,IAAI;AAEZ,MAAMC,KAAK,GAAGD,IAAK,uCAAsC;AACzD,MAAME,OAAO,GAAGF,IAAK;AACrB;AACA;AACA;AACA,EAAE;AACF,MAAMG,KAAK,GAAI,oBAAmBD,OAAQ,EAAC;AAS3C,OAAO,SAASE,mBAAmBA,CAACC,IAAY,EAAEC,UAA6B,EAAwB;EACrGA,UAAU,GAAGC,KAAK,CAACC,OAAO,CAACF,UAAU,CAAC,GAAGA,UAAU,GAAG,CAACA,UAAU,CAAC;EAClE,MAAMG,KAAK,GAAGJ,IAAI,CAACK,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAACC,KAAK,CAAC,KAAK,CAAC;EAEnD,MAAM,CAACC,SAAS,EAAEC,IAAI,EAAEC,UAAU,CAAC,GAAGL,KAAK;EAC3C,IAAI,CAACH,UAAU,CAACS,QAAQ,CAACH,SAAS,CAAC,IAAI,CAACC,IAAI,IAAI,CAACC,UAAU,EAAE;IAC3D,OAAO,IAAI;EACb;EACA,MAAME,IAAI,GAAGF,UAAU,CAACH,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;EACrC,OAAO;IAACC,SAAS;IAAEC,IAAI;IAAEG;EAAI,CAAC;AAChC;AAMA,OAAO,SAASC,gBAAgBA,CAACC,OAKhC,EAAU;EACT,MAAM;IAACC,OAAO,GAAG,GAAG;IAAEC,KAAK;IAAEC,SAAS;IAAEC;EAAM,CAAC,GAAGJ,OAAO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AACF;AAGA,OAAO,SAASY,aAAaA,CAACG,QAAgB,EAAEf,IAAY,EAAU;EAEpE,QAAQA,IAAI;IACV,KAAK,OAAO;MAAE,OAAQ,QAAOe,QAAS,kBAAiB;IACvD,KAAK,MAAM;MAAE,OAAQ,QAAOA,QAAS,aAAY;IACjD,KAAK,MAAM;MAAE,OAAQ,QAAOA,QAAS,QAAO;IAC5C,KAAK,MAAM;MAAE,OAAOA,QAAQ;IAC5B;MACE,MAAM,IAAIL,KAAK,CAACV,IAAI,CAAC;EACzB;AACF"}
1
+ {"version":3,"file":"shader-utils.js","names":["glsl","FS100","FS_GLES","FS300","getQualifierDetails","line","qualifiers","Array","isArray","words","replace","split","qualifier","type","definition","includes","name","getPassthroughFS","options","version","input","inputChannels","output","Error","inputType","channelCountToType","outputValue","convertToVec4","typeToChannelSuffix","typeToChannelCount","channels","variable"],"sources":["../../../src/lib/glsl-utils/shader-utils.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport {glsl} from './highlight';\n\nconst FS100 = glsl`void main() {gl_FragColor = vec4(0);}`;\nconst FS_GLES = glsl`\\\nout vec4 transform_output;\nvoid main() {\n transform_output = vec4(0);\n}`;\nconst FS300 = `#version 300 es\\n${FS_GLES}`;\n\ntype QualifierInfo = {\n qualifier: string;\n type: string;\n name: string;\n}\n\n// Prase given glsl line and return qualifier details or null\nexport function getQualifierDetails(line: string, qualifiers: string | string[]): QualifierInfo | null {\n qualifiers = Array.isArray(qualifiers) ? qualifiers : [qualifiers];\n const words = line.replace(/^\\s+/, '').split(/\\s+/);\n // TODO add support for precession qualifiers (highp, mediump and lowp)\n const [qualifier, type, definition] = words;\n if (!qualifiers.includes(qualifier) || !type || !definition) {\n return null;\n }\n const name = definition.split(';')[0];\n return {qualifier, type, name};\n}\n\n/**\n * Given the shader version, input and output variable names,\n * builds and return a pass through fragment shader.\n */\nexport function getPassthroughFS(options?: {\n version?: number;\n input?: string;\n inputChannels?: 1 | 2 | 3 | 4;\n output?: string;\n}): string {\n const {version = 100, input, inputChannels, output} = options || {};\n if (!input) {\n if (version === 300) {\n // Fast-path for WebGL 2.0\n return FS300;\n } else if (version > 300) {\n // Use the supplied version for OpenGL/ES 3.2+\n return `#version ${version}\\n${FS_GLES}`;\n }\n // Fast-path for WebGL 1.0\n return FS100;\n }\n if (!inputChannels) {\n throw new Error('inputChannels');\n }\n const inputType = channelCountToType(inputChannels);\n const outputValue = convertToVec4(input, inputChannels);\n if (version >= 300) {\n // If version is 300, assume WebGL 2.0\n return `\\\n#version ${version} ${version === 300 ? 'es' : ''}\nin ${inputType} ${input};\nout vec4 ${output};\nvoid main() {\n ${output} = ${outputValue};\n}`;\n }\n // WebGL 1.0\n return `\\\nvarying ${inputType} ${input};\nvoid main() {\n gl_FragColor = ${outputValue};\n}`;\n}\n\n/** convert glsl type to suffix */\nexport function typeToChannelSuffix(type: string): 'x' | 'xy' | 'xyz' | 'xyzw' {\n // prettier-ignore\n switch (type) {\n case 'float': return 'x';\n case 'vec2': return 'xy';\n case 'vec3': return 'xyz';\n case 'vec4': return 'xyzw';\n default:\n throw new Error(type);\n }\n}\n\n/** convert glsl type to channel count */\nexport function typeToChannelCount(type: string): 1 | 2 | 3 | 4 {\n // prettier-ignore\n switch (type) {\n case 'float': return 1;\n case 'vec2': return 2;\n case 'vec3': return 3;\n case 'vec4': return 4;\n default:\n throw new Error(type);\n }\n}\nfunction channelCountToType(channels: 1 | 2 | 3 |4): 'float' | 'vec2' | 'vec3' | 'vec4' {\n // prettier-ignore\n switch (channels) {\n case 1: return 'float';\n case 2: return 'vec2';\n case 3: return 'vec3';\n case 4: return 'vec4';\n default:\n throw new Error(`invalid channels: ${channels}`);\n }\n}\n\n/** Returns glsl instruction for converting to vec4 */\nexport function convertToVec4(variable: string, channels: 1 | 2 | 3 | 4): string {\n // prettier-ignore\n switch (channels) {\n case 1: return `vec4(${variable}, 0.0, 0.0, 1.0)`;\n case 2: return `vec4(${variable}, 0.0, 1.0)`;\n case 3: return `vec4(${variable}, 1.0)`;\n case 4: return variable;\n default:\n throw new Error(`invalid channels: ${channels}`);\n }\n}\n"],"mappings":"SAGQA,IAAI;AAEZ,MAAMC,KAAK,GAAGD,IAAK,uCAAsC;AACzD,MAAME,OAAO,GAAGF,IAAK;AACrB;AACA;AACA;AACA,EAAE;AACF,MAAMG,KAAK,GAAI,oBAAmBD,OAAQ,EAAC;AAS3C,OAAO,SAASE,mBAAmBA,CAACC,IAAY,EAAEC,UAA6B,EAAwB;EACrGA,UAAU,GAAGC,KAAK,CAACC,OAAO,CAACF,UAAU,CAAC,GAAGA,UAAU,GAAG,CAACA,UAAU,CAAC;EAClE,MAAMG,KAAK,GAAGJ,IAAI,CAACK,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAACC,KAAK,CAAC,KAAK,CAAC;EAEnD,MAAM,CAACC,SAAS,EAAEC,IAAI,EAAEC,UAAU,CAAC,GAAGL,KAAK;EAC3C,IAAI,CAACH,UAAU,CAACS,QAAQ,CAACH,SAAS,CAAC,IAAI,CAACC,IAAI,IAAI,CAACC,UAAU,EAAE;IAC3D,OAAO,IAAI;EACb;EACA,MAAME,IAAI,GAAGF,UAAU,CAACH,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;EACrC,OAAO;IAACC,SAAS;IAAEC,IAAI;IAAEG;EAAI,CAAC;AAChC;AAMA,OAAO,SAASC,gBAAgBA,CAACC,OAKhC,EAAU;EACT,MAAM;IAACC,OAAO,GAAG,GAAG;IAAEC,KAAK;IAAEC,aAAa;IAAEC;EAAM,CAAC,GAAGJ,OAAO,IAAI,CAAC,CAAC;EACnE,IAAI,CAACE,KAAK,EAAE;IACV,IAAID,OAAO,KAAK,GAAG,EAAE;MAEnB,OAAOhB,KAAK;IACd,CAAC,MAAM,IAAIgB,OAAO,GAAG,GAAG,EAAE;MAExB,OAAQ,YAAWA,OAAQ,KAAIjB,OAAQ,EAAC;IAC1C;IAEA,OAAOD,KAAK;EACd;EACA,IA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,CAAC;MAAE,OAAO,MAAM;IACrB;MACE,MAAM,IAAIP,KAAK,CAAE,qBAAoBO,QAAS,EAAC,CAAC;EACpD;AACF;AAGA,OAAO,SAASH,aAAaA,CAACI,QAAgB,EAAED,QAAuB,EAAU;EAE/E,QAAQA,QAAQ;IACd,KAAK,CAAC;MAAE,OAAQ,QAAOC,QAAS,kBAAiB;IACjD,KAAK,CAAC;MAAE,OAAQ,QAAOA,QAAS,aAAY;IAC5C,KAAK,CAAC;MAAE,OAAQ,QAAOA,QAAS,QAAO;IACvC,KAAK,CAAC;MAAE,OAAOA,QAAQ;IACvB;MACE,MAAM,IAAIR,KAAK,CAAE,qBAAoBO,QAAS,EAAC,CAAC;EACpD;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"shader-module-instance.d.ts","sourceRoot":"","sources":["../../../src/lib/shader-module/shader-module-instance.ts"],"names":[],"mappings":"AAIA,OAAO,EAA6C,aAAa,EAAC,MAAM,uBAAuB,CAAC;AAChG,OAAO,EAAC,YAAY,EAAE,uBAAuB,EAAC,MAAM,iBAAiB,CAAC;AACtE,OAAO,EAAE,eAAe,EAAuB,MAAM,sCAAsC,CAAC;AAI5F,yEAAyE;AACzE,qBAAa,oBAAoB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,iBAAiB,EAAE,QAAQ,CAAC;IAC5B,YAAY,EAAE,oBAAoB,EAAE,CAAC;IACrC,YAAY,EAAE,uBAAuB,EAAE,CAAC;IACxC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC;IACzC,UAAU,EAAE;QACV,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;QACxC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;KAC3C,CAAC;IACF,QAAQ,EAAE,MAAM,CAAC,MAAM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AAC;IACrC,YAAY,EAAE,uBAAuB,EAAE,CAAC;IACxC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC;IACzC,UAAU,EAAE;QACV,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;QACxC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;KAC3C,CAAC;IACF,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAM;IAC7C,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAM;IAEjD,MAAM,CAAC,kBAAkB,CACvB,OAAO,EAAE,CAAC,YAAY,GAAG,oBAAoB,CAAC,EAAE,GAC/C,oBAAoB,EAAE;gBAuBb,KAAK,EAAE,YAAY;IA6B/B,eAAe,CAAC,KAAK,EAAE,QAAQ,GAAG,UAAU,GAAG,MAAM;IAwBrD,WAAW,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAQ/F,UAAU,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IAK7C,iBAAiB,CAAC,YAAY,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,GAAG,IAAI;IAYvD,4BAA4B,CAAC,YAAY,EAAE,uBAAuB,EAAE;IAcpE,mBAAmB,CAAC,IAAI,GAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;CAkBzE"}
@@ -8,7 +8,7 @@ export class ShaderModuleInstance {
8
8
  if (module instanceof ShaderModuleInstance) {
9
9
  return module;
10
10
  }
11
- assert(typeof module !== 'string', `Shader module use by name is deprecated. Import shader module '${module}' and use it directly.`);
11
+ assert(typeof module !== 'string', `Shader module use by name is deprecated. Import shader module '${JSON.stringify(module)}' and use it directly.`);
12
12
  if (!module.name) {
13
13
  console.warn('shader module has no name');
14
14
  module.name = `shader-module-${index++}`;
@@ -1 +1 @@
1
- {"version":3,"file":"shader-module-instance.js","names":["assert","makePropValidators","getValidatedProperties","normalizeInjections","index","ShaderModuleInstance","instantiateModules","modules","map","module","name","console","warn","moduleObject","dependencies","constructor","props","vs","fs","getModuleUniforms","deprecations","defines","injections","uniforms","uniformTypes","uniformPropTypes","getUniforms","inject","_parseDeprecationDefinitions","getModuleSource","stage","moduleSource","moduleName","toUpperCase","replace","userProps","getDefines","checkDeprecations","shaderSource","log","forEach","def","_def$regex","regex","test","deprecated","old","new","removed","type","RegExp","_defaultGetUniforms","opts","arguments","length","undefined","propTypes","key","propDef","private","validate","value"],"sources":["../../../src/lib/shader-module/shader-module-instance.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport {assert} from '../utils/assert';\nimport {makePropValidators, getValidatedProperties, PropValidator} from '../filters/prop-types';\nimport {ShaderModule, ShaderModuleDeprecation} from './shader-module';\nimport { ShaderInjection, normalizeInjections } from '../shader-assembly/shader-injections';\n\nlet index = 1;\n\n/** An initialized ShaderModule, ready to use with `assembleShaders()` */\nexport class ShaderModuleInstance {\n name: string;\n vs?: string;\n fs?: string;\n getModuleUniforms: Function;\n dependencies: ShaderModuleInstance[];\n deprecations: ShaderModuleDeprecation[];\n defines: Record<string, string | number>;\n injections: {\n vertex: Record<string, ShaderInjection>;\n fragment: Record<string, ShaderInjection>;\n };\n uniforms: Record<string, PropValidator> = {};\n uniformTypes: Record<string, PropValidator> = {};\n\n static instantiateModules(\n modules: (ShaderModule | ShaderModuleInstance)[]\n ): ShaderModuleInstance[] {\n return modules.map((module: ShaderModule | ShaderModuleInstance) => {\n if (module instanceof ShaderModuleInstance) {\n return module;\n }\n\n assert(\n typeof module !== 'string',\n `Shader module use by name is deprecated. Import shader module '${module}' and use it directly.`\n );\n if (!module.name) {\n console.warn('shader module has no name');\n module.name = `shader-module-${index++}`;\n }\n\n const moduleObject = new ShaderModuleInstance(module);\n moduleObject.dependencies = ShaderModuleInstance.instantiateModules(module.dependencies || []);\n\n return moduleObject;\n });\n }\n\n constructor(props: ShaderModule) {\n const {\n name,\n vs,\n fs,\n dependencies = [],\n uniformPropTypes = {},\n getUniforms,\n deprecations = [],\n defines = {},\n inject = {}\n } = props;\n\n assert(typeof name === 'string');\n this.name = name;\n this.vs = vs;\n this.fs = fs;\n this.getModuleUniforms = getUniforms;\n this.dependencies = ShaderModuleInstance.instantiateModules(dependencies);\n this.deprecations = this._parseDeprecationDefinitions(deprecations);\n this.defines = defines;\n this.injections = normalizeInjections(inject);\n\n if (uniformPropTypes) {\n this.uniforms = makePropValidators(uniformPropTypes);\n }\n }\n\n // Extracts the source code chunk for the specified shader type from the named shader module\n getModuleSource(stage: 'vertex' | 'fragment'): string {\n let moduleSource;\n switch (stage) {\n case 'vertex':\n moduleSource = this.vs || '';\n break;\n case 'fragment':\n moduleSource = this.fs || '';\n break;\n default:\n assert(false);\n }\n\n const moduleName = this.name.toUpperCase().replace(/[^0-9a-z]/gi, '_');\n return `\\\n// ----- MODULE ${this.name} ---------------\n\n#define MODULE_${moduleName}\n${moduleSource}\\\n\n\n`;\n }\n\n getUniforms(userProps: Record<string, any>, uniforms: Record<string, any>): Record<string, any> {\n if (this.getModuleUniforms) {\n return this.getModuleUniforms(userProps, uniforms);\n }\n // Build uniforms from the uniforms array\n return getValidatedProperties(userProps, this.uniforms, this.name);\n }\n\n getDefines(): Record<string, string | number> {\n return this.defines;\n }\n\n // Warn about deprecated uniforms or functions\n checkDeprecations(shaderSource: string, log: any): void {\n this.deprecations.forEach(def => {\n if (def.regex?.test(shaderSource)) {\n if (def.deprecated) {\n log.deprecated(def.old, def.new)();\n } else {\n log.removed(def.old, def.new)();\n }\n }\n });\n }\n\n _parseDeprecationDefinitions(deprecations: ShaderModuleDeprecation[]) {\n deprecations.forEach(def => {\n switch (def.type) {\n case 'function':\n def.regex = new RegExp(`\\\\b${def.old}\\\\(`);\n break;\n default:\n def.regex = new RegExp(`${def.type} ${def.old};`);\n }\n });\n\n return deprecations;\n }\n\n _defaultGetUniforms(opts: Record<string, any> = {}): Record<string, any> {\n const uniforms: Record<string, any> = {};\n const propTypes = this.uniforms;\n\n for (const key in propTypes) {\n const propDef = propTypes[key];\n if (key in opts && !propDef.private) {\n if (propDef.validate) {\n assert(propDef.validate(opts[key], propDef), `${this.name}: invalid ${key}`);\n }\n uniforms[key] = opts[key];\n } else {\n uniforms[key] = propDef.value;\n }\n }\n\n return uniforms;\n }\n}\n"],"mappings":"SAGQA,MAAM;AAAA,SACNC,kBAAkB,EAAEC,sBAAsB;AAAA,SAExBC,mBAAmB;AAE7C,IAAIC,KAAK,GAAG,CAAC;AAGb,OAAO,MAAMC,oBAAoB,CAAC;EAehC,OAAOC,kBAAkBA,CACvBC,OAAgD,EACxB;IACxB,OAAOA,OAAO,CAACC,GAAG,CAAEC,MAA2C,IAAK;MAClE,IAAIA,MAAM,YAAYJ,oBAAoB,EAAE;QAC1C,OAAOI,MAAM;MACf;MAEAT,MAAM,CACJ,OAAOS,MAAM,KAAK,QAAQ,EACzB,kEAAiEA,MAAO,wBAC3E,CAAC;MACD,IAAI,CAACA,MAAM,CAACC,IAAI,EAAE;QAChBC,OAAO,CAACC,IAAI,CAAC,2BAA2B,CAAC;QACzCH,MAAM,CAACC,IAAI,GAAI,iBAAgBN,KAAK,EAAG,EAAC;MAC1C;MAEA,MAAMS,YAAY,GAAG,IAAIR,oBAAoB,CAACI,MAAM,CAAC;MACrDI,YAAY,CAACC,YAAY,GAAGT,oBAAoB,CAACC,kBAAkB,CAACG,MAAM,CAACK,YAAY,IAAI,EAAE,CAAC;MAE9F,OAAOD,YAAY;IACrB,CAAC,CAAC;EACJ;EAEAE,WAAWA,CAACC,KAAmB,EAAE;IAAA,KAtCjCN,IAAI;IAAA,KACJO,EAAE;IAAA,KACFC,E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AAE,MAAKT,GAAG,CAACK,GAAI,KAAI,CAAC;UAC1C;QACF;UACEL,GAAG,CAACE,KAAK,GAAG,IAAIO,MAAM,CAAE,GAAET,GAAG,CAACQ,IAAK,IAAGR,GAAG,CAACK,GAAI,GAAE,CAAC;MACrD;IACF,CAAC,CAAC;IAEF,OAAO1B,YAAY;EACrB;EAEA+B,mBAAmBA,CAAA,EAAsD;IAAA,IAArDC,IAAyB,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;IAChD,MAAM9B,QAA6B,GAAG,CAAC,CAAC;IACxC,MAAMiC,SAAS,GAAG,IAAI,CAACjC,QAAQ;IAE/B,KAAK,MAAMkC,GAAG,IAAID,SAAS,EAAE;MAC3B,MAAME,OAAO,GAAGF,SAAS,CAACC,GAAG,CAAC;MAC9B,IAAIA,GAAG,IAAIL,IAAI,IAAI,CAACM,OAAO,CAACC,OAAO,EAAE;QACnC,IAAID,OAAO,CAACE,QAAQ,EAAE;UACpB5D,MAAM,CAAC0D,OAAO,CAACE,QAAQ,CAACR,IAAI,CAACK,GAAG,CAAC,EAAEC,OAAO,CAAC,EAAG,GAAE,IAAI,CAAChD,IAAK,aAAY+C,GAAI,EAAC,CAAC;QAC9E;QACAlC,QAAQ,CAACkC,GAAG,CAAC,GAAGL,IAAI,CAACK,GAAG,CAAC;MAC3B,CAAC,MAAM;QACLlC,QAAQ,CAACkC,GAAG,CAAC,GAAGC,OAAO,CAACG,KAAK;MAC/B;IACF;IAEA,OAAOtC,QAAQ;EACjB;AACF"}
1
+ {"version":3,"file":"shader-module-instance.js","names":["assert","makePropValidators","getValidatedProperties","normalizeInjections","index","ShaderModuleInstance","instantiateModules","modules","map","module","JSON","stringify","name","console","warn","moduleObject","dependencies","constructor","props","vs","fs","getModuleUniforms","deprecations","defines","injections","uniforms","uniformTypes","uniformPropTypes","getUniforms","inject","_parseDeprecationDefinitions","getModuleSource","stage","moduleSource","moduleName","toUpperCase","replace","userProps","getDefines","checkDeprecations","shaderSource","log","forEach","def","_def$regex","regex","test","deprecated","old","new","removed","type","RegExp","_defaultGetUniforms","opts","arguments","length","undefined","propTypes","key","propDef","private","validate","value"],"sources":["../../../src/lib/shader-module/shader-module-instance.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport {assert} from '../utils/assert';\nimport {makePropValidators, getValidatedProperties, PropValidator} from '../filters/prop-types';\nimport {ShaderModule, ShaderModuleDeprecation} from './shader-module';\nimport { ShaderInjection, normalizeInjections } from '../shader-assembly/shader-injections';\n\nlet index = 1;\n\n/** An initialized ShaderModule, ready to use with `assembleShaders()` */\nexport class ShaderModuleInstance {\n name: string;\n vs?: string;\n fs?: string;\n getModuleUniforms: Function;\n dependencies: ShaderModuleInstance[];\n deprecations: ShaderModuleDeprecation[];\n defines: Record<string, string | number>;\n injections: {\n vertex: Record<string, ShaderInjection>;\n fragment: Record<string, ShaderInjection>;\n };\n uniforms: Record<string, PropValidator> = {};\n uniformTypes: Record<string, PropValidator> = {};\n\n static instantiateModules(\n modules: (ShaderModule | ShaderModuleInstance)[]\n ): ShaderModuleInstance[] {\n return modules.map((module: ShaderModule | ShaderModuleInstance) => {\n if (module instanceof ShaderModuleInstance) {\n return module;\n }\n\n assert(\n typeof module !== 'string',\n `Shader module use by name is deprecated. Import shader module '${JSON.stringify(module)}' and use it directly.`\n );\n if (!module.name) {\n // eslint-disable-next-line no-console\n console.warn('shader module has no name');\n module.name = `shader-module-${index++}`;\n }\n\n const moduleObject = new ShaderModuleInstance(module);\n moduleObject.dependencies = ShaderModuleInstance.instantiateModules(module.dependencies || []);\n\n return moduleObject;\n });\n }\n\n constructor(props: ShaderModule) {\n const {\n name,\n vs,\n fs,\n dependencies = [],\n uniformPropTypes = {},\n getUniforms,\n deprecations = [],\n defines = {},\n inject = {}\n } = props;\n\n assert(typeof name === 'string');\n this.name = name;\n this.vs = vs;\n this.fs = fs;\n this.getModuleUniforms = getUniforms;\n this.dependencies = ShaderModuleInstance.instantiateModules(dependencies);\n this.deprecations = this._parseDeprecationDefinitions(deprecations);\n this.defines = defines;\n this.injections = normalizeInjections(inject);\n\n if (uniformPropTypes) {\n this.uniforms = makePropValidators(uniformPropTypes);\n }\n }\n\n // Extracts the source code chunk for the specified shader type from the named shader module\n getModuleSource(stage: 'vertex' | 'fragment'): string {\n let moduleSource;\n switch (stage) {\n case 'vertex':\n moduleSource = this.vs || '';\n break;\n case 'fragment':\n moduleSource = this.fs || '';\n break;\n default:\n assert(false);\n }\n\n const moduleName = this.name.toUpperCase().replace(/[^0-9a-z]/gi, '_');\n return `\\\n// ----- MODULE ${this.name} ---------------\n\n#define MODULE_${moduleName}\n${moduleSource}\\\n\n\n`;\n }\n\n getUniforms(userProps: Record<string, any>, uniforms: Record<string, any>): Record<string, any> {\n if (this.getModuleUniforms) {\n return this.getModuleUniforms(userProps, uniforms);\n }\n // Build uniforms from the uniforms array\n return getValidatedProperties(userProps, this.uniforms, this.name);\n }\n\n getDefines(): Record<string, string | number> {\n return this.defines;\n }\n\n // Warn about deprecated uniforms or functions\n checkDeprecations(shaderSource: string, log: any): void {\n this.deprecations.forEach(def => {\n if (def.regex?.test(shaderSource)) {\n if (def.deprecated) {\n log.deprecated(def.old, def.new)();\n } else {\n log.removed(def.old, def.new)();\n }\n }\n });\n }\n\n _parseDeprecationDefinitions(deprecations: ShaderModuleDeprecation[]) {\n deprecations.forEach(def => {\n switch (def.type) {\n case 'function':\n def.regex = new RegExp(`\\\\b${def.old}\\\\(`);\n break;\n default:\n def.regex = new RegExp(`${def.type} ${def.old};`);\n }\n });\n\n return deprecations;\n }\n\n _defaultGetUniforms(opts: Record<string, any> = {}): Record<string, any> {\n const uniforms: Record<string, any> = {};\n const propTypes = this.uniforms;\n\n for (const key in propTypes) {\n const propDef = propTypes[key];\n if (key in opts && !propDef.private) {\n if (propDef.validate) {\n assert(propDef.validate(opts[key], propDef), `${this.name}: invalid ${key}`);\n }\n u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D,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;IAChD,MAAM9B,QAA6B,GAAG,CAAC,CAAC;IACxC,MAAMiC,SAAS,GAAG,IAAI,CAACjC,QAAQ;IAE/B,KAAK,MAAMkC,GAAG,IAAID,SAAS,EAAE;MAC3B,MAAME,OAAO,GAAGF,SAAS,CAACC,GAAG,CAAC;MAC9B,IAAIA,GAAG,IAAIL,IAAI,IAAI,CAACM,OAAO,CAACC,OAAO,EAAE;QACnC,IAAID,OAAO,CAACE,QAAQ,EAAE;UACpB9D,MAAM,CAAC4D,OAAO,CAACE,QAAQ,CAACR,IAAI,CAACK,GAAG,CAAC,EAAEC,OAAO,CAAC,EAAG,GAAE,IAAI,CAAChD,IAAK,aAAY+C,GAAI,EAAC,CAAC;QAC9E;QACAlC,QAAQ,CAACkC,GAAG,CAAC,GAAGL,IAAI,CAACK,GAAG,CAAC;MAC3B,CAAC,MAAM;QACLlC,QAAQ,CAACkC,GAAG,CAAC,GAAGC,OAAO,CAACG,KAAK;MAC/B;IACF;IAEA,OAAOtC,QAAQ;EACjB;AACF"}
@@ -138,16 +138,16 @@ export const picking = {
138
138
  uniformTypes: {
139
139
  isActive: 'f32',
140
140
  isAttribute: 'f32',
141
- useFloatColors: 'f32',
142
141
  isHighlightActive: 'f32',
142
+ useFloatColors: 'f32',
143
143
  highlightedObjectColor: 'vec3<f32>',
144
144
  highlightColor: 'vec4<f32>'
145
145
  },
146
146
  defaultUniforms: {
147
147
  isActive: false,
148
148
  isAttribute: false,
149
- useFloatColors: true,
150
149
  isHighlightActive: false,
150
+ useFloatColors: true,
151
151
  highlightedObjectColor: new Float32Array([0, 0, 0]),
152
152
  highlightColor: DEFAULT_HIGHLIGHT_COLOR
153
153
  },
@@ -156,12 +156,8 @@ export const picking = {
156
156
  function getUniforms() {
157
157
  let opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
158
158
  let prevUniforms = arguments.length > 1 ? arguments[1] : undefined;
159
- const uniforms = {
160
- ...picking.defaultUniforms
161
- };
162
- if (opts.highlightedObjectColor === undefined) {
163
- delete uniforms.highlightedObjectColor;
164
- } else if (opts.highlightedObjectColor === null) {
159
+ const uniforms = {};
160
+ if (opts.highlightedObjectColor === undefined) {} else if (opts.highlightedObjectColor === null) {
165
161
  uniforms.isHighlightActive = false;
166
162
  } else {
167
163
  uniforms.isHighlightActive = true;
@@ -1 +1 @@
1
- {"version":3,"file":"picking.js","names":["glsl","DEFAULT_HIGHLIGHT_COLOR","Float32Array","vs","fs","picking","name","uniformTypes","isActive","isAttribute","useFloatColors","isHighlightActive","highlightedObjectColor","highlightColor","defaultUniforms","getUniforms","opts","arguments","length","undefined","prevUniforms","uniforms","slice","color","Array","from","x","Number","isFinite","Boolean"],"sources":["../../../../src/modules/engine/picking/picking.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport {NumberArray} from '../../../types';\nimport {glsl} from '../../../lib/glsl-utils/highlight';\nimport {ShaderModule} from '../../../lib/shader-module/shader-module';\n\n// cyan color\nconst DEFAULT_HIGHLIGHT_COLOR = new Float32Array([0, 1, 1, 1]);\n\n/** \n * Props for the picking module, which depending on mode renders picking colors or highlighted item.\n * When active, renders picking colors, assumed to be rendered to off-screen \"picking\" buffer. \n * When inactive, renders normal colors, with the exception of selected object which is rendered with highlight \n */\nexport type PickingProps = {\n /** Are we picking? I.e. rendering picking colors? */\n isActive?: boolean;\n /** Do we have a highlighted item? */\n isHighlightActive?: boolean;\n /** Set to true when picking an attribute value instead of object index */\n isAttribute?: boolean;\n /** Set to a picking color to visually highlight that item, or `null` to explicitly clear **/\n highlightedObjectColor?: NumberArray | null;\n /** Color of visual highlight of \"selected\" item */\n highlightColor?: NumberArray;\n /** Color range 0-1 or 0-255 */\n useFloatColors?: boolean;\n};\n\n// TODO - \nexport type PickingSettings = Omit<PickingUniforms, 'isHighlightActive' | 'highlightedObjectColor'> & {\n /**\n * Set to a picking color to visually highlight that item.\n * The picking module will persist the last highlighted object, unless\n * `null` is passed to explicitly clear\n **/\n highlightedObjectColor?: NumberArray | null;\n /** Color of visual highlight of \"selected\" item */\n highlightColor?: NumberArray;\n};\n\n/** \n * Uniforms for the picking module, which renders picking colors and highlighted item. \n * When active, renders picking colors, assumed to be rendered to off-screen \"picking\" buffer. \n * When inactive, renders normal colors, with the exception of selected object which is rendered with highlight \n */\nexport type PickingUniforms = {\n /** \n * When true, renders picking colors. Set when rendering to off-screen \"picking\" buffer. \n * When false, renders normal colors, with the exception of selected object which is rendered with highlight \n */\n isActive?: boolean;\n /** Set to true when picking an attribute value instead of object index */\n isAttribute?: boolean;\n /** Color range 0-1 or 0-255 */\n useFloatColors?: boolean;\n /** Do we have a highlighted item? */\n isHighlightActive?: boolean;\n /** Set to a picking color to visually highlight that item */\n highlightedObjectColor?: NumberArray;\n /** Color of visual highlight of \"selected\" item */\n highlightColor?: NumberArray;\n};\n\nconst vs = glsl`\\\nuniform pickingUniforms {\n float isActive;\n float isAttribute;\n float isHighlightActive;\n float useFloatColors;\n vec3 highlightedObjectColor;\n vec4 highlightColor;\n} picking;\n\nout vec4 picking_vRGBcolor_Avalid;\n\n// Normalize unsigned byte color to 0-1 range\nvec3 picking_normalizeColor(vec3 color) {\n return picking.useFloatColors > 0.5 ? color : color / 255.0;\n}\n\n// Normalize unsigned byte color to 0-1 range\nvec4 picking_normalizeColor(vec4 color) {\n return picking.useFloatColors > 0.5 ? color : color / 255.0;\n}\n\nbool picking_isColorZero(vec3 color) {\n return dot(color, vec3(1.0)) < 0.00001;\n}\n\nbool picking_isColorValid(vec3 color) {\n return dot(color, vec3(1.0)) > 0.00001;\n}\n\n// Check if this vertex is highlighted \nbool isVertexHighlighted(vec3 vertexColor) {\n vec3 highlightedObjectColor = picking_normalizeColor(picking.highlightedObjectColor);\n return\n bool(picking.isHighlightActive) && picking_isColorZero(abs(vertexColor - highlightedObjectColor));\n}\n\n// Set the current picking color\nvoid picking_setPickingColor(vec3 pickingColor) {\n pickingColor = picking_normalizeColor(pickingColor);\n\n if (bool(picking.isActive)) {\n // Use alpha as the validity flag. If pickingColor is [0, 0, 0] fragment is non-pickable\n picking_vRGBcolor_Avalid.a = float(picking_isColorValid(pickingColor));\n\n // if (!bool(picking.isAttribute)) {\n // Stores the picking color so that the fragment shader can render it during picking\n picking_vRGBcolor_Avalid.rgb = pickingColor;\n // }\n } else {\n // Do the comparison with selected item color in vertex shader as it should mean fewer compares\n picking_vRGBcolor_Avalid.a = float(isVertexHighlighted(pickingColor));\n }\n}\n\nvoid picking_setPickingAttribute(float value) {\n if (bool(picking.isAttribute)) {\n picking_vRGBcolor_Avalid.r = value;\n }\n}\n\nvoid picking_setPickingAttribute(vec2 value) {\n if (bool(picking.isAttribute)) {\n picking_vRGBcolor_Avalid.rg = value;\n }\n}\n\nvoid picking_setPickingAttribute(vec3 value) {\n if (bool(picking.isAttribute)) {\n picking_vRGBcolor_Avalid.rgb = value;\n }\n}\n`;\n\nconst fs = glsl`\\\nuniform pickingUniforms {\n float isActive;\n float isAttribute;\n float isHighlightActive;\n float useFloatColors;\n vec3 highlightedObjectColor;\n vec4 highlightColor;\n} picking;\n\nin vec4 picking_vRGBcolor_Avalid;\n\n/*\n * Returns highlight color if this item is selected.\n */\nvec4 picking_filterHighlightColor(vec4 color) {\n // If we are still picking, we don't highlight\n if (picking.isActive > 0.5) {\n return color;\n }\n\n bool selected = bool(picking_vRGBcolor_Avalid.a);\n\n if (selected) {\n // Blend in highlight color based on its alpha value\n float highLightAlpha = picking.highlightColor.a;\n float blendedAlpha = highLightAlpha + color.a * (1.0 - highLightAlpha);\n float highLightRatio = highLightAlpha / blendedAlpha;\n\n vec3 blendedRGB = mix(color.rgb, picking.highlightColor.rgb, highLightRatio);\n return vec4(blendedRGB, blendedAlpha);\n } else {\n return color;\n }\n}\n\n/*\n * Returns picking color if picking enabled else unmodified argument.\n */\nvec4 picking_filterPickingColor(vec4 color) {\n if (bool(picking.isActive)) {\n if (picking_vRGBcolor_Avalid.a == 0.0) {\n discard;\n }\n return picking_vRGBcolor_Avalid;\n }\n return color;\n}\n\n/*\n * Returns picking color if picking is enabled if not\n * highlight color if this item is selected, otherwise unmodified argument.\n */\nvec4 picking_filterColor(vec4 color) {\n vec4 highlightColor = picking_filterHighlightColor(color);\n return picking_filterPickingColor(highlightColor);\n}\n`;\n\n/**\n * Provides support for color-coding-based picking and highlighting.\n * In particular, supports picking a specific instance in an instanced\n * draw call and highlighting an instance based on its picking color,\n * and correspondingly, supports picking and highlighting groups of\n * primitives with the same picking color in non-instanced draw-calls\n */\nexport const picking: ShaderModule<PickingProps, PickingUniforms> = {\n name: 'picking',\n vs,\n fs,\n uniformTypes: {\n isActive: 'f32',\n isAttribute: 'f32',\n useFloatColors: 'f32',\n isHighlightActive: 'f32',\n highlightedObjectColor: 'vec3<f32>',\n highlightColor: 'vec4<f32>'\n },\n defaultUniforms: {\n isActive: false,\n isAttribute: false,\n useFloatColors: true,\n isHighlightActive: false,\n highlightedObjectColor: new Float32Array([0, 0, 0]),\n highlightColor: DEFAULT_HIGHLIGHT_COLOR\n },\n getUniforms\n};\n\nfunction getUniforms(opts: PickingProps = {}, prevUniforms?: PickingUniforms): PickingUniforms {\n const uniforms = {...picking.defaultUniforms};\n\n if (opts.highlightedObjectColor === undefined) {\n delete uniforms.highlightedObjectColor;\n } else if (opts.highlightedObjectColor === null) {\n uniforms.isHighlightActive = false;\n } else {\n uniforms.isHighlightActive = true;\n const highlightedObjectColor = opts.highlightedObjectColor.slice(0, 3);\n uniforms.highlightedObjectColor = highlightedObjectColor;\n }\n\n if (opts.highlightColor) {\n const color = Array.from(opts.highlightColor, (x) => x / 255);\n if (!Number.isFinite(color[3])) {\n color[3] = 1;\n }\n uniforms.highlightColor = color;\n }\n\n if (opts.isActive !== undefined) {\n uniforms.isActive = Boolean(opts.isActive);\n uniforms.isAttribute = Boolean(opts.isAttribute);\n }\n\n if (opts.useFloatColors !== undefined) {\n uniforms.useFloatColors = Boolean(opts.useFloatColors);\n }\n\n return uniforms;\n}\n"],"mappings":"SAIQA,IAAI;AAIZ,MAAMC,uBAAuB,GAAG,IAAIC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAyD9D,MAAMC,EAAE,GAAGH,IAAK;AAChB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AAED,MAAMI,EAAE,GAAGJ,IAAK;AAChB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AASD,OAAO,MAAMK,OAAoD,GAAG;EAClEC,IAAI,EAAE,SAAS;EACfH,EAAE;EACFC,EAAE;EACFG,YAAY,EAAE;IACZC,QAAQ,EAAE,KAAK;IACfC,WAAW,EAAE,KAAK;IAClBC,cAAc,EAAE,KAAK;IACrBC,iBAAiB,EAAE,KAAK;IACxBC,sBAAsB,EAAE,WAAW;IACnCC,cAAc,EAAE;EAClB,CAAC;EACDC,eAAe,EAAE;IACfN,QAAQ,EAAE,KAAK;IACfC,WAAW,EAAE,KAAK;IAClBC,cAAc,EAAE,IAAI;IACpBC,iBAAiB,EAAE,K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AAO,CAACb,IAAI,CAACR,QAAQ,CAAC;IAC1Ca,QAAQ,CAACZ,WAAW,GAAGoB,OAAO,CAACb,IAAI,CAACP,WAAW,CAAC;EAClD;EAEA,IAAIO,IAAI,CAACN,cAAc,KAAKS,SAAS,EAAE;IACrCE,QAAQ,CAACX,cAAc,GAAGmB,OAAO,CAACb,IAAI,CAACN,cAAc,CAAC;EACxD;EAEA,OAAOW,QAAQ;AACjB"}
1
+ {"version":3,"file":"picking.js","names":["glsl","DEFAULT_HIGHLIGHT_COLOR","Float32Array","vs","fs","picking","name","uniformTypes","isActive","isAttribute","isHighlightActive","useFloatColors","highlightedObjectColor","highlightColor","defaultUniforms","getUniforms","opts","arguments","length","undefined","prevUniforms","uniforms","slice","color","Array","from","x","Number","isFinite","Boolean"],"sources":["../../../../src/modules/engine/picking/picking.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport {NumberArray} from '../../../types';\nimport {glsl} from '../../../lib/glsl-utils/highlight';\nimport {ShaderModule} from '../../../lib/shader-module/shader-module';\n\n// cyan color\nconst DEFAULT_HIGHLIGHT_COLOR = new Float32Array([0, 1, 1, 1]);\n\n/** \n * Props for the picking module, which depending on mode renders picking colors or highlighted item.\n * When active, renders picking colors, assumed to be rendered to off-screen \"picking\" buffer. \n * When inactive, renders normal colors, with the exception of selected object which is rendered with highlight \n */\nexport type PickingProps = {\n /** Are we picking? I.e. rendering picking colors? */\n isActive?: boolean;\n /** Do we have a highlighted item? */\n isHighlightActive?: boolean;\n /** Set to true when picking an attribute value instead of object index */\n isAttribute?: boolean;\n /** Set to a picking color to visually highlight that item, or `null` to explicitly clear **/\n highlightedObjectColor?: NumberArray | null;\n /** Color of visual highlight of \"selected\" item */\n highlightColor?: NumberArray;\n /** Color range 0-1 or 0-255 */\n useFloatColors?: boolean;\n};\n\n// TODO - \nexport type PickingSettings = Omit<PickingUniforms, 'isHighlightActive' | 'highlightedObjectColor'> & {\n /**\n * Set to a picking color to visually highlight that item.\n * The picking module will persist the last highlighted object, unless\n * `null` is passed to explicitly clear\n **/\n highlightedObjectColor?: NumberArray | null;\n /** Color of visual highlight of \"selected\" item */\n highlightColor?: NumberArray;\n};\n\n/** \n * Uniforms for the picking module, which renders picking colors and highlighted item. \n * When active, renders picking colors, assumed to be rendered to off-screen \"picking\" buffer. \n * When inactive, renders normal colors, with the exception of selected object which is rendered with highlight \n */\nexport type PickingUniforms = {\n /** \n * When true, renders picking colors. Set when rendering to off-screen \"picking\" buffer. \n * When false, renders normal colors, with the exception of selected object which is rendered with highlight \n */\n isActive?: boolean;\n /** Set to true when picking an attribute value instead of object index */\n isAttribute?: boolean;\n /** Color range 0-1 or 0-255 */\n useFloatColors?: boolean;\n /** Do we have a highlighted item? */\n isHighlightActive?: boolean;\n /** Set to a picking color to visually highlight that item */\n highlightedObjectColor?: NumberArray;\n /** Color of visual highlight of \"selected\" item */\n highlightColor?: NumberArray;\n};\n\nconst vs = glsl`\\\nuniform pickingUniforms {\n float isActive;\n float isAttribute;\n float isHighlightActive;\n float useFloatColors;\n vec3 highlightedObjectColor;\n vec4 highlightColor;\n} picking;\n\nout vec4 picking_vRGBcolor_Avalid;\n\n// Normalize unsigned byte color to 0-1 range\nvec3 picking_normalizeColor(vec3 color) {\n return picking.useFloatColors > 0.5 ? color : color / 255.0;\n}\n\n// Normalize unsigned byte color to 0-1 range\nvec4 picking_normalizeColor(vec4 color) {\n return picking.useFloatColors > 0.5 ? color : color / 255.0;\n}\n\nbool picking_isColorZero(vec3 color) {\n return dot(color, vec3(1.0)) < 0.00001;\n}\n\nbool picking_isColorValid(vec3 color) {\n return dot(color, vec3(1.0)) > 0.00001;\n}\n\n// Check if this vertex is highlighted \nbool isVertexHighlighted(vec3 vertexColor) {\n vec3 highlightedObjectColor = picking_normalizeColor(picking.highlightedObjectColor);\n return\n bool(picking.isHighlightActive) && picking_isColorZero(abs(vertexColor - highlightedObjectColor));\n}\n\n// Set the current picking color\nvoid picking_setPickingColor(vec3 pickingColor) {\n pickingColor = picking_normalizeColor(pickingColor);\n\n if (bool(picking.isActive)) {\n // Use alpha as the validity flag. If pickingColor is [0, 0, 0] fragment is non-pickable\n picking_vRGBcolor_Avalid.a = float(picking_isColorValid(pickingColor));\n\n // if (!bool(picking.isAttribute)) {\n // Stores the picking color so that the fragment shader can render it during picking\n picking_vRGBcolor_Avalid.rgb = pickingColor;\n // }\n } else {\n // Do the comparison with selected item color in vertex shader as it should mean fewer compares\n picking_vRGBcolor_Avalid.a = float(isVertexHighlighted(pickingColor));\n }\n}\n\nvoid picking_setPickingAttribute(float value) {\n if (bool(picking.isAttribute)) {\n picking_vRGBcolor_Avalid.r = value;\n }\n}\n\nvoid picking_setPickingAttribute(vec2 value) {\n if (bool(picking.isAttribute)) {\n picking_vRGBcolor_Avalid.rg = value;\n }\n}\n\nvoid picking_setPickingAttribute(vec3 value) {\n if (bool(picking.isAttribute)) {\n picking_vRGBcolor_Avalid.rgb = value;\n }\n}\n`;\n\nconst fs = glsl`\\\nuniform pickingUniforms {\n float isActive;\n float isAttribute;\n float isHighlightActive;\n float useFloatColors;\n vec3 highlightedObjectColor;\n vec4 highlightColor;\n} picking;\n\nin vec4 picking_vRGBcolor_Avalid;\n\n/*\n * Returns highlight color if this item is selected.\n */\nvec4 picking_filterHighlightColor(vec4 color) {\n // If we are still picking, we don't highlight\n if (picking.isActive > 0.5) {\n return color;\n }\n\n bool selected = bool(picking_vRGBcolor_Avalid.a);\n\n if (selected) {\n // Blend in highlight color based on its alpha value\n float highLightAlpha = picking.highlightColor.a;\n float blendedAlpha = highLightAlpha + color.a * (1.0 - highLightAlpha);\n float highLightRatio = highLightAlpha / blendedAlpha;\n\n vec3 blendedRGB = mix(color.rgb, picking.highlightColor.rgb, highLightRatio);\n return vec4(blendedRGB, blendedAlpha);\n } else {\n return color;\n }\n}\n\n/*\n * Returns picking color if picking enabled else unmodified argument.\n */\nvec4 picking_filterPickingColor(vec4 color) {\n if (bool(picking.isActive)) {\n if (picking_vRGBcolor_Avalid.a == 0.0) {\n discard;\n }\n return picking_vRGBcolor_Avalid;\n }\n return color;\n}\n\n/*\n * Returns picking color if picking is enabled if not\n * highlight color if this item is selected, otherwise unmodified argument.\n */\nvec4 picking_filterColor(vec4 color) {\n vec4 highlightColor = picking_filterHighlightColor(color);\n return picking_filterPickingColor(highlightColor);\n}\n`;\n\n/**\n * Provides support for color-coding-based picking and highlighting.\n * In particular, supports picking a specific instance in an instanced\n * draw call and highlighting an instance based on its picking color,\n * and correspondingly, supports picking and highlighting groups of\n * primitives with the same picking color in non-instanced draw-calls\n */\nexport const picking: ShaderModule<PickingProps, PickingUniforms> = {\n name: 'picking',\n vs,\n fs,\n uniformTypes: {\n isActive: 'f32',\n isAttribute: 'f32',\n isHighlightActive: 'f32',\n useFloatColors: 'f32',\n highlightedObjectColor: 'vec3<f32>',\n highlightColor: 'vec4<f32>'\n },\n defaultUniforms: {\n isActive: false,\n isAttribute: false,\n isHighlightActive: false,\n useFloatColors: true,\n highlightedObjectColor: new Float32Array([0, 0, 0]),\n highlightColor: DEFAULT_HIGHLIGHT_COLOR\n },\n getUniforms\n};\n\nfunction getUniforms(opts: PickingProps = {}, prevUniforms?: PickingUniforms): PickingUniforms {\n const uniforms = {} as PickingUniforms;\n\n if (opts.highlightedObjectColor === undefined) {\n // Unless highlightedObjectColor explicitly null or set, do not update state\n } else if (opts.highlightedObjectColor === null) {\n uniforms.isHighlightActive = false;\n } else {\n uniforms.isHighlightActive = true;\n const highlightedObjectColor = opts.highlightedObjectColor.slice(0, 3);\n uniforms.highlightedObjectColor = highlightedObjectColor;\n }\n\n if (opts.highlightColor) {\n const color = Array.from(opts.highlightColor, (x) => x / 255);\n if (!Number.isFinite(color[3])) {\n color[3] = 1;\n }\n uniforms.highlightColor = color;\n }\n\n if (opts.isActive !== undefined) {\n uniforms.isActive = Boolean(opts.isActive);\n uniforms.isAttribute = Boolean(opts.isAttribute);\n }\n\n if (opts.useFloatColors !== undefined) {\n uniforms.useFloatColors = Boolean(opts.useFloatColors);\n }\n\n return uniforms;\n}\n"],"mappings":"SAIQA,IAAI;AAIZ,MAAMC,uBAAuB,GAAG,IAAIC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAyD9D,MAAMC,EAAE,GAAGH,IAAK;AAChB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AAED,MAAMI,EAAE,GAAGJ,IAAK;AAChB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AASD,OAAO,MAAMK,OAAoD,GAAG;EAClEC,IAAI,EAAE,SAAS;EACfH,EAAE;EACFC,EAAE;EACFG,YAAY,EAAE;IACZC,QAAQ,EAAE,KAAK;IACfC,WAAW,EAAE,KAAK;IAClBC,iBAAiB,EAAE,KAAK;IACxBC,cAAc,EAAE,KAAK;IACrBC,sBAAsB,EAAE,WAAW;IACnCC,cAAc,EAAE;EAClB,CAAC;EACDC,eAAe,EAAE;IACfN,QAAQ,EAAE,KAAK;IACfC,WAAW,EAAE,KAAK;IAClBC,iBAAiB,EAAE,KAAK;I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Ca,QAAQ,CAACZ,WAAW,GAAGoB,OAAO,CAACb,IAAI,CAACP,WAAW,CAAC;EAClD;EAEA,IAAIO,IAAI,CAACL,cAAc,KAAKQ,SAAS,EAAE;IACrCE,QAAQ,CAACV,cAAc,GAAGkB,OAAO,CAACb,IAAI,CAACL,cAAc,CAAC;EACxD;EAEA,OAAOU,QAAQ;AACjB"}
@@ -78,7 +78,6 @@ function getUniforms(props) {
78
78
  if (props.enabled !== undefined) {
79
79
  uniforms.enabled = props.enabled ? 1 : 0;
80
80
  }
81
- console.error(uniforms);
82
81
  return uniforms;
83
82
  }
84
83
  function getLightSourceUniforms(_ref) {
@@ -1 +1 @@
1
- {"version":3,"file":"lighting-uniforms.js","names":["lightingUniforms","MAX_LIGHTS","COLOR_FACTOR","LIGHT_TYPE","lighting","name","vs","fs","getUniforms","props","prevUniforms","defines","uniformTypes","enabled","ambientLightColor","numberOfLights","lightType","lightColor","lightPosition","lightDirection","lightAttenuation","defaultUniforms","POINT","arguments","length","undefined","lights","extractLightTypes","ambientLight","pointLights","directionalLights","hasLights","uniforms","getLightSourceUniforms","console","error","_ref","lightSourceUniforms","convertColor","currentLight","pointLight","position","attenuation","directionalLight","DIRECTIONAL","direction","_lightSources$directi","_lightSources$pointLi","lightSources","light","type","push","colorDef","color","intensity","map","component"],"sources":["../../../../src/modules/lighting/lights/lighting-uniforms.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport type {NumberArray} from '@math.gl/types';\nimport {ShaderModule} from '../../../lib/shader-module/shader-module';\nimport {lightingUniforms} from './lighting-uniforms.glsl';\n\n/** Max number of supported lights (in addition to ambient light */\nconst MAX_LIGHTS = 5;\n\n/** Whether to divide */\nconst COLOR_FACTOR = 255.0;\n\n/** Shader type field for lights */\nenum LIGHT_TYPE {\n POINT = 0,\n DIRECTIONAL = 1\n}\n\n/** Lighting helper types */\n\nexport type Light = AmbientLight | PointLight | DirectionalLight;\n\nexport type AmbientLight = {\n type: 'ambient';\n color?: Readonly<NumberArray>;\n intensity?: number;\n}\n\nexport type PointLight = {\n type: 'point';\n position: Readonly<NumberArray>;\n color?: Readonly<NumberArray>;\n intensity?: number;\n attenuation?: number;\n}\n\nexport type DirectionalLight = {\n type: 'directional';\n position: Readonly<NumberArray>;\n direction: Readonly<NumberArray>;\n color?: Readonly<NumberArray>;\n intensity?: number;\n}\n\nexport type LightingProps = {\n enabled?: boolean;\n lights?: Light[];\n /** @deprecated */\n ambientLight?: AmbientLight;\n /** @deprecated */\n pointLights?: PointLight[];\n /** @deprecated */\n directionalLights?: DirectionalLight[];\n};\n\nexport type LightingUniforms = {\n enabled: number;\n ambientLightColor: Readonly<NumberArray>;\n numberOfLights: number;\n lightType: number; // [];\n lightColor: Readonly<NumberArray>; // [];\n lightPosition: Readonly<NumberArray>; // [];\n lightDirection: Readonly<NumberArray>; // [];\n lightAttenuation: Readonly<NumberArray>; // [];\n};\n\n/** UBO ready lighting module */\nexport const lighting: ShaderModule<LightingProps, LightingUniforms> = {\n name: 'lighting',\n vs: lightingUniforms,\n fs: lightingUniforms,\n\n getUniforms(props?: LightingProps, prevUniforms?: LightingUniforms): LightingUniforms {\n return getUniforms(props);\n },\n\n defines: {\n MAX_LIGHTS\n },\n\n uniformTypes: {\n enabled: 'i32',\n ambientLightColor: 'vec3<f32>',\n numberOfLights: 'i32', // , array: MAX_LIGHTS,\n lightType: 'i32', // , array: MAX_LIGHTS,\n lightColor: 'vec3<f32>', // , array: MAX_LIGHTS,\n lightPosition: 'vec3<f32>', // , array: MAX_LIGHTS,\n // TODO - could combine direction and attenuation\n lightDirection: 'vec3<f32>', // , array: MAX_LIGHTS,\n lightAttenuation: 'vec3<f32>' // , array: MAX_LIGHTS},\n },\n\n defaultUniforms: { \n enabled: 1,\n ambientLightColor: [0.1, 0.1, 0.1],\n numberOfLights: 0,\n lightType: LIGHT_TYPE.POINT,\n lightColor: [1, 1, 1],\n lightPosition: [1, 1, 2],\n // TODO - could combine direction and attenuation\n lightDirection: [1, 1, 1],\n lightAttenuation: [1, 1, 1],\n }\n};\n\nfunction getUniforms(props?: LightingProps, prevUniforms: Partial<LightingUniforms> = {}): LightingUniforms {\n // Copy props so we can modify \n props = props ? {...props} : props;\n\n // TODO legacy\n if (!props) {\n return {...lighting.defaultUniforms};\n }\n // Support for array of lights. Type of light is detected by type field\n if (props.lights) {\n props = {...props, ...extractLightTypes(props.lights), lights: undefined};\n }\n\n // Specify lights separately\n const {ambientLight, pointLights, directionalLights} = props || {};\n const hasLights =\n ambientLight ||\n (pointLights && pointLights.length > 0) ||\n (directionalLights && directionalLights.length > 0);\n\n // TODO - this may not be the correct decision\n if (!hasLights) {\n return {...lighting.defaultUniforms, enabled: 0};\n }\n\n const uniforms = {\n ...lighting.defaultUniforms,\n ...prevUniforms,\n ...getLightSourceUniforms({ambientLight, pointLights, directionalLights}),\n };\n\n if (props.enabled !== undefined) {\n uniforms.enabled = props.enabled ? 1 : 0;\n }\n\n console.error(uniforms)\n return uniforms;\n}\n\nfunction getLightSourceUniforms({\n ambientLight,\n pointLights = [],\n directionalLights = []\n}: LightingProps): Partial<LightingUniforms> {\n const lightSourceUniforms: Partial<LightingUniforms> = {\n // lightType: new Array(MAX_LIGHTS).fill(0),\n // lightColor: new Array(MAX_LIGHTS).fill([0, 0, 0]),\n // lightPosition: new Array(MAX_LIGHTS).fill([0, 0, 0]),\n // lightDirection: new Array(MAX_LIGHTS).fill([0, 0, 0]),\n // lightAttenuation: new Array(MAX_LIGHTS).fill([0, 0, 0])\n };\n\n lightSourceUniforms.ambientLightColor = convertColor(ambientLight);\n\n let currentLight = 0;\n\n for (const pointLight of pointLights) {\n // lightSourceUniforms.lightType[currentLight] = LIGHT_TYPE.POINT;\n // lightSourceUniforms.lightColor[currentLight] = convertColor(pointLight);\n // lightSourceUniforms.lightPosition[currentLight] = pointLight.position;\n // lightSourceUniforms.lightAttenuation[currentLight] = [pointLight.attenuation || 1, 0, 0];\n lightSourceUniforms.lightType = LIGHT_TYPE.POINT;\n lightSourceUniforms.lightColor = convertColor(pointLight);\n lightSourceUniforms.lightPosition = pointLight.position;\n lightSourceUniforms.lightAttenuation = [pointLight.attenuation || 1, 0, 0];\n currentLight++;\n }\n\n for (const directionalLight of directionalLights) {\n // lightSourceUniforms.lightType[currentLight] = LIGHT_TYPE.DIRECTIONAL;\n // lightSourceUniforms.lightColor[currentLight] = convertColor(directionalLight);\n // lightSourceUniforms.lightPosition[currentLight] = directionalLight.position;\n // lightSourceUniforms.lightDirection[currentLight] = directionalLight.direction;\n lightSourceUniforms.lightType = LIGHT_TYPE.DIRECTIONAL;\n lightSourceUniforms.lightColor = convertColor(directionalLight);\n lightSourceUniforms.lightPosition = directionalLight.position;\n lightSourceUniforms.lightDirection = directionalLight.direction;\n currentLight++;\n }\n\n lightSourceUniforms.numberOfLights = currentLight;\n\n return lightSourceUniforms;\n}\n\nfunction extractLightTypes(lights: Light[]): LightingProps {\n const lightSources: LightingProps = {pointLights: [], directionalLights: []};\n for (const light of lights || []) {\n switch (light.type) {\n case 'ambient':\n // Note: Only uses last ambient light\n // TODO - add ambient light sources on CPU?\n lightSources.ambientLight = light;\n break;\n case 'directional':\n lightSources.directionalLights?.push(light);\n break;\n case 'point':\n lightSources.pointLights?.push(light);\n break;\n default:\n // eslint-disable-next-line\n // console.warn(light.type);\n }\n }\n return lightSources;\n}\n\n/** Take color 0-255 and intensity as input and output 0.0-1.0 range */\nfunction convertColor(colorDef: {color?: Readonly<NumberArray>, intensity?: number} = {}): NumberArray {\n const {color = [0, 0, 0], intensity = 1.0} = colorDef;\n return color.map((component) => (component * intensity) / COLOR_FACTOR);\n}\n"],"mappings":"SAKQA,gBAAgB;AAGxB,MAAMC,UAAU,GAAG,CAAC;AAGpB,MAAMC,YAAY,GAAG,KAAK;AAAC,IAGtBC,UAAU,aAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAA,OAAVA,UAAU;AAAA,EAAVA,UAAU;AAsD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CAACF,KAAK,CAAC;QACrC;MACF;IAGF;EACF;EACA,OAAOD,YAAY;AACrB;AAGA,SAASV,YAAYA,CAAA,EAAkF;EAAA,IAAjFc,QAA6D,GAAA7B,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EACtF,MAAM;IAAC8B,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IAAEC,SAAS,GAAG;EAAG,CAAC,GAAGF,QAAQ;EACrD,OAAOC,KAAK,CAACE,GAAG,CAAEC,SAAS,IAAMA,SAAS,GAAGF,SAAS,GAAIpD,YAAY,CAAC;AACzE"}
1
+ {"version":3,"file":"lighting-uniforms.js","names":["lightingUniforms","MAX_LIGHTS","COLOR_FACTOR","LIGHT_TYPE","lighting","name","vs","fs","getUniforms","props","prevUniforms","defines","uniformTypes","enabled","ambientLightColor","numberOfLights","lightType","lightColor","lightPosition","lightDirection","lightAttenuation","defaultUniforms","POINT","arguments","length","undefined","lights","extractLightTypes","ambientLight","pointLights","directionalLights","hasLights","uniforms","getLightSourceUniforms","_ref","lightSourceUniforms","convertColor","currentLight","pointLight","position","attenuation","directionalLight","DIRECTIONAL","direction","_lightSources$directi","_lightSources$pointLi","lightSources","light","type","push","colorDef","color","intensity","map","component"],"sources":["../../../../src/modules/lighting/lights/lighting-uniforms.ts"],"sourcesContent":["// luma.gl, MIT license\n// Copyright (c) vis.gl contributors\n\nimport type {NumberArray} from '@math.gl/types';\nimport {ShaderModule} from '../../../lib/shader-module/shader-module';\nimport {lightingUniforms} from './lighting-uniforms.glsl';\n\n/** Max number of supported lights (in addition to ambient light */\nconst MAX_LIGHTS = 5;\n\n/** Whether to divide */\nconst COLOR_FACTOR = 255.0;\n\n/** Shader type field for lights */\nenum LIGHT_TYPE {\n POINT = 0,\n DIRECTIONAL = 1\n}\n\n/** Lighting helper types */\n\nexport type Light = AmbientLight | PointLight | DirectionalLight;\n\nexport type AmbientLight = {\n type: 'ambient';\n color?: Readonly<NumberArray>;\n intensity?: number;\n}\n\nexport type PointLight = {\n type: 'point';\n position: Readonly<NumberArray>;\n color?: Readonly<NumberArray>;\n intensity?: number;\n attenuation?: number;\n}\n\nexport type DirectionalLight = {\n type: 'directional';\n position: Readonly<NumberArray>;\n direction: Readonly<NumberArray>;\n color?: Readonly<NumberArray>;\n intensity?: number;\n}\n\nexport type LightingProps = {\n enabled?: boolean;\n lights?: Light[];\n /** @deprecated */\n ambientLight?: AmbientLight;\n /** @deprecated */\n pointLights?: PointLight[];\n /** @deprecated */\n directionalLights?: DirectionalLight[];\n};\n\nexport type LightingUniforms = {\n enabled: number;\n ambientLightColor: Readonly<NumberArray>;\n numberOfLights: number;\n lightType: number; // [];\n lightColor: Readonly<NumberArray>; // [];\n lightPosition: Readonly<NumberArray>; // [];\n lightDirection: Readonly<NumberArray>; // [];\n lightAttenuation: Readonly<NumberArray>; // [];\n};\n\n/** UBO ready lighting module */\nexport const lighting: ShaderModule<LightingProps, LightingUniforms> = {\n name: 'lighting',\n vs: lightingUniforms,\n fs: lightingUniforms,\n\n getUniforms(props?: LightingProps, prevUniforms?: LightingUniforms): LightingUniforms {\n return getUniforms(props);\n },\n\n defines: {\n MAX_LIGHTS\n },\n\n uniformTypes: {\n enabled: 'i32',\n ambientLightColor: 'vec3<f32>',\n numberOfLights: 'i32', // , array: MAX_LIGHTS,\n lightType: 'i32', // , array: MAX_LIGHTS,\n lightColor: 'vec3<f32>', // , array: MAX_LIGHTS,\n lightPosition: 'vec3<f32>', // , array: MAX_LIGHTS,\n // TODO - could combine direction and attenuation\n lightDirection: 'vec3<f32>', // , array: MAX_LIGHTS,\n lightAttenuation: 'vec3<f32>' // , array: MAX_LIGHTS},\n },\n\n defaultUniforms: { \n enabled: 1,\n ambientLightColor: [0.1, 0.1, 0.1],\n numberOfLights: 0,\n lightType: LIGHT_TYPE.POINT,\n lightColor: [1, 1, 1],\n lightPosition: [1, 1, 2],\n // TODO - could combine direction and attenuation\n lightDirection: [1, 1, 1],\n lightAttenuation: [1, 1, 1],\n }\n};\n\nfunction getUniforms(props?: LightingProps, prevUniforms: Partial<LightingUniforms> = {}): LightingUniforms {\n // Copy props so we can modify \n props = props ? {...props} : props;\n\n // TODO legacy\n if (!props) {\n return {...lighting.defaultUniforms};\n }\n // Support for array of lights. Type of light is detected by type field\n if (props.lights) {\n props = {...props, ...extractLightTypes(props.lights), lights: undefined};\n }\n\n // Specify lights separately\n const {ambientLight, pointLights, directionalLights} = props || {};\n const hasLights =\n ambientLight ||\n (pointLights && pointLights.length > 0) ||\n (directionalLights && directionalLights.length > 0);\n\n // TODO - this may not be the correct decision\n if (!hasLights) {\n return {...lighting.defaultUniforms, enabled: 0};\n }\n\n const uniforms = {\n ...lighting.defaultUniforms,\n ...prevUniforms,\n ...getLightSourceUniforms({ambientLight, pointLights, directionalLights}),\n };\n\n if (props.enabled !== undefined) {\n uniforms.enabled = props.enabled ? 1 : 0;\n }\n\n return uniforms;\n}\n\nfunction getLightSourceUniforms({\n ambientLight,\n pointLights = [],\n directionalLights = []\n}: LightingProps): Partial<LightingUniforms> {\n const lightSourceUniforms: Partial<LightingUniforms> = {\n // lightType: new Array(MAX_LIGHTS).fill(0),\n // lightColor: new Array(MAX_LIGHTS).fill([0, 0, 0]),\n // lightPosition: new Array(MAX_LIGHTS).fill([0, 0, 0]),\n // lightDirection: new Array(MAX_LIGHTS).fill([0, 0, 0]),\n // lightAttenuation: new Array(MAX_LIGHTS).fill([0, 0, 0])\n };\n\n lightSourceUniforms.ambientLightColor = convertColor(ambientLight);\n\n let currentLight = 0;\n\n for (const pointLight of pointLights) {\n // lightSourceUniforms.lightType[currentLight] = LIGHT_TYPE.POINT;\n // lightSourceUniforms.lightColor[currentLight] = convertColor(pointLight);\n // lightSourceUniforms.lightPosition[currentLight] = pointLight.position;\n // lightSourceUniforms.lightAttenuation[currentLight] = [pointLight.attenuation || 1, 0, 0];\n lightSourceUniforms.lightType = LIGHT_TYPE.POINT;\n lightSourceUniforms.lightColor = convertColor(pointLight);\n lightSourceUniforms.lightPosition = pointLight.position;\n lightSourceUniforms.lightAttenuation = [pointLight.attenuation || 1, 0, 0];\n currentLight++;\n }\n\n for (const directionalLight of directionalLights) {\n // lightSourceUniforms.lightType[currentLight] = LIGHT_TYPE.DIRECTIONAL;\n // lightSourceUniforms.lightColor[currentLight] = convertColor(directionalLight);\n // lightSourceUniforms.lightPosition[currentLight] = directionalLight.position;\n // lightSourceUniforms.lightDirection[currentLight] = directionalLight.direction;\n lightSourceUniforms.lightType = LIGHT_TYPE.DIRECTIONAL;\n lightSourceUniforms.lightColor = convertColor(directionalLight);\n lightSourceUniforms.lightPosition = directionalLight.position;\n lightSourceUniforms.lightDirection = directionalLight.direction;\n currentLight++;\n }\n\n lightSourceUniforms.numberOfLights = currentLight;\n\n return lightSourceUniforms;\n}\n\nfunction extractLightTypes(lights: Light[]): LightingProps {\n const lightSources: LightingProps = {pointLights: [], directionalLights: []};\n for (const light of lights || []) {\n switch (light.type) {\n case 'ambient':\n // Note: Only uses last ambient light\n // TODO - add ambient light sources on CPU?\n lightSources.ambientLight = light;\n break;\n case 'directional':\n lightSources.directionalLights?.push(light);\n break;\n case 'point':\n lightSources.pointLights?.push(light);\n break;\n default:\n // eslint-disable-next-line\n // console.warn(light.type);\n }\n }\n return lightSources;\n}\n\n/** Take color 0-255 and intensity as input and output 0.0-1.0 range */\nfunction convertColor(colorDef: {color?: Readonly<NumberArray>, intensity?: number} = {}): NumberArray {\n const {color = [0, 0, 0], intensity = 1.0} = colorDef;\n return color.map((component) => (component * intensity) / COLOR_FACTOR);\n}\n"],"mappings":"SAKQA,gBAAgB;AAGxB,MAAMC,UAAU,GAAG,CAAC;AAGpB,MAAMC,YAAY,GAAG,KAAK;AAAC,IAGtBC,UAAU,aAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAVA,UAAU,CAAVA,UAAU;EAAA,OAAVA,UAAU;AAAA,EAAVA,UAAU;AAsDf,OAAO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