@luma.gl/shadertools 9.0.19 → 9.0.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/dist/dist.dev.js +107 -206
  2. package/dist/dist.min.js +92 -148
  3. package/dist/index.cjs +105 -148
  4. package/dist/index.cjs.map +4 -4
  5. package/dist/index.d.ts +2 -2
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts +2 -3
  8. package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts.map +1 -1
  9. package/dist/modules/lighting/gouraud-material/gouraud-material.js +7 -3
  10. package/dist/modules/lighting/lights/lighting-uniforms-glsl.d.ts.map +1 -1
  11. package/dist/modules/lighting/lights/lighting-uniforms-glsl.js +30 -6
  12. package/dist/modules/lighting/lights/lighting-uniforms.d.ts +13 -6
  13. package/dist/modules/lighting/lights/lighting-uniforms.d.ts.map +1 -1
  14. package/dist/modules/lighting/lights/lighting-uniforms.js +41 -33
  15. package/dist/modules/lighting/phong-material/phong-material.d.ts +4 -4
  16. package/dist/modules/lighting/phong-material/phong-material.d.ts.map +1 -1
  17. package/dist/modules/lighting/phong-material/phong-material.js +4 -0
  18. package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts +0 -39
  19. package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts.map +1 -1
  20. package/dist/modules/lighting/phong-material/phong-shaders-glsl.js +7 -65
  21. package/package.json +2 -2
  22. package/src/index.ts +2 -2
  23. package/src/modules/lighting/gouraud-material/gouraud-material.ts +11 -8
  24. package/src/modules/lighting/lights/lighting-uniforms-glsl.ts +32 -10
  25. package/src/modules/lighting/lights/lighting-uniforms.ts +61 -40
  26. package/src/modules/lighting/phong-material/phong-material.ts +9 -6
  27. package/src/modules/lighting/phong-material/phong-shaders-glsl.ts +8 -89
  28. package/dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.d.ts +0 -42
  29. package/dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.d.ts.map +0 -1
  30. package/dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.js +0 -110
  31. package/src/modules/lighting/gouraud-material/gouraud-shaders-glsl.ts +0 -144
package/dist/index.d.ts CHANGED
@@ -29,9 +29,9 @@ export { picking } from "./modules/engine/picking/picking.js";
29
29
  export type { LightingProps } from "./modules/lighting/lights/lighting-uniforms.js";
30
30
  export { lighting } from "./modules/lighting/lights/lighting-uniforms.js";
31
31
  export { dirlight } from "./modules/lighting/no-material/dirlight.js";
32
- export type { PhongMaterialUniforms as GouraudMaterialUniforms } from "./modules/lighting/phong-material/phong-material.js";
32
+ export type { GouraudMaterialProps } from "./modules/lighting/gouraud-material/gouraud-material.js";
33
33
  export { gouraudMaterial } from "./modules/lighting/gouraud-material/gouraud-material.js";
34
- export type { PhongMaterialUniforms } from "./modules/lighting/phong-material/phong-material.js";
34
+ export type { PhongMaterialProps } from "./modules/lighting/phong-material/phong-material.js";
35
35
  export { phongMaterial } from "./modules/lighting/phong-material/phong-material.js";
36
36
  export { pbrMaterial } from "./modules/lighting/pbr-material/pbr-material.js";
37
37
  export type { BrightnessContrastProps } from "./modules/postprocessing/image-adjust-filters/brightnesscontrast.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,OAAO,EAAC,IAAI,EAAC,sCAAmC;AAEhD,YAAY,EAAC,YAAY,EAAC,+CAA4C;AAEtE,YAAY,EAAC,YAAY,EAAC,6CAA0C;AACpE,YAAY,EAAC,UAAU,EAAC,2CAAwC;AAChE,YAAY,EAAC,UAAU,EAAC,8CAA2C;AACnE,YAAY,EAAC,eAAe,EAAC,mDAAgD;AAC7E,OAAO,EAAC,oBAAoB,EAAC,sDAAmD;AAGhF,OAAO,EAAC,eAAe,EAAC,kCAA+B;AAEvD,OAAO,EAAC,qBAAqB,EAAC,uDAAoD;AAKlF,OAAO,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AO,EAAC,QAAQ,IAAI,SAAS,EAAC,uDAAoD;AAClF,OAAO,EACL,eAAe,EACf,aAAa,EACd,mEAAgE;AACjE,OAAO,EAAC,GAAG,EAAC,6CAA0C"}
@@ -1,6 +1,5 @@
1
1
  import { ShaderModule } from "../../../lib/shader-module/shader-module.js";
2
- export type GouraudMaterialProps = GouraudMaterialUniforms;
3
- export type GouraudMaterialUniforms = {
2
+ export type GouraudMaterialProps = {
4
3
  ambient?: number;
5
4
  diffuse?: number;
6
5
  /** Specularity exponent */
@@ -8,5 +7,5 @@ export type GouraudMaterialUniforms = {
8
7
  specularColor?: [number, number, number];
9
8
  };
10
9
  /** In Gouraud shading, color is calculated for each triangle vertex normal, and then color is interpolated colors across the triangle */
11
- export declare const gouraudMaterial: ShaderModule<GouraudMaterialProps, GouraudMaterialUniforms>;
10
+ export declare const gouraudMaterial: ShaderModule<GouraudMaterialProps>;
12
11
  //# sourceMappingURL=gouraud-material.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"gouraud-material.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/gouraud-material/gouraud-material.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,YAAY,EAAC,oDAAiD;AAItE,MAAM,MAAM,oBAAoB,GAAG,uBAAuB,CAAC;AAE3D,MAAM,MAAM,uBAAuB,GAAG;IACpC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2BAA2B;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;CAC1C,CAAC;AAEF,yIAAyI;AACzI,eAAO,MAAM,eAAe,EAAE,YAAY,CAAC,oBAAoB,EAAE,uBAAuB,CAwBvF,CAAC"}
1
+ {"version":3,"file":"gouraud-material.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/gouraud-material/gouraud-material.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,YAAY,EAAC,oDAAiD;AAKtE,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2BAA2B;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;CAC1C,CAAC;AAEF,yIAAyI;AACzI,eAAO,MAAM,eAAe,EAAE,YAAY,CAAC,oBAAoB,CA4B9D,CAAC"}
@@ -2,13 +2,13 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
4
  import { lighting } from "../lights/lighting-uniforms.js";
5
- import { GOURAUD_VS, GOURAUD_FS } from "./gouraud-shaders-glsl.js";
5
+ import { PHONG_VS, PHONG_FS } from "../phong-material/phong-shaders-glsl.js";
6
6
  /** In Gouraud shading, color is calculated for each triangle vertex normal, and then color is interpolated colors across the triangle */
7
7
  export const gouraudMaterial = {
8
8
  name: 'gouraudMaterial',
9
9
  // Note these are switched between phong and gouraud
10
- vs: GOURAUD_VS,
11
- fs: GOURAUD_FS,
10
+ vs: PHONG_FS.replace('phongMaterial', 'gouraudMaterial'),
11
+ fs: PHONG_VS.replace('phongMaterial', 'gouraudMaterial'),
12
12
  defines: {
13
13
  LIGHTING_VERTEX: 1
14
14
  },
@@ -26,6 +26,10 @@ export const gouraudMaterial = {
26
26
  specularColor: [0.15, 0.15, 0.15]
27
27
  },
28
28
  getUniforms(props) {
29
+ const uniforms = { ...props };
30
+ if (uniforms.specularColor) {
31
+ uniforms.specularColor = uniforms.specularColor.map(x => x / 255);
32
+ }
29
33
  return { ...gouraudMaterial.defaultUniforms, ...props };
30
34
  }
31
35
  };
@@ -1 +1 @@
1
- {"version":3,"file":"lighting-uniforms-glsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/lights/lighting-uniforms-glsl.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,gBAAgB,QAqD5B,CAAC"}
1
+ {"version":3,"file":"lighting-uniforms-glsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/lights/lighting-uniforms-glsl.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,gBAAgB,QA2E5B,CAAC"}
@@ -22,16 +22,40 @@ int lightType;
22
22
  int directionalLightCount;
23
23
  int pointLightCount;
24
24
  vec3 ambientColor;
25
- vec3 lightColor;
26
- vec3 lightPosition;
27
- vec3 lightDirection;
28
- vec3 lightAttenuation;
25
+ vec3 lightColor0;
26
+ vec3 lightPosition0;
27
+ vec3 lightDirection0;
28
+ vec3 lightAttenuation0;
29
+ vec3 lightColor1;
30
+ vec3 lightPosition1;
31
+ vec3 lightDirection1;
32
+ vec3 lightAttenuation1;
33
+ vec3 lightColor2;
34
+ vec3 lightPosition2;
35
+ vec3 lightDirection2;
36
+ vec3 lightAttenuation2;
29
37
  } lighting;
30
38
  PointLight lighting_getPointLight(int index) {
31
- return PointLight(lighting.lightColor, lighting.lightPosition, lighting.lightAttenuation);
39
+ switch (index) {
40
+ case 0:
41
+ return PointLight(lighting.lightColor0, lighting.lightPosition0, lighting.lightAttenuation0);
42
+ case 1:
43
+ return PointLight(lighting.lightColor1, lighting.lightPosition1, lighting.lightAttenuation1);
44
+ case 2:
45
+ default:
46
+ return PointLight(lighting.lightColor2, lighting.lightPosition2, lighting.lightAttenuation2);
47
+ }
32
48
  }
33
49
  DirectionalLight lighting_getDirectionalLight(int index) {
34
- return DirectionalLight(lighting.lightColor, lighting.lightDirection);
50
+ switch (index) {
51
+ case 0:
52
+ return DirectionalLight(lighting.lightColor0, lighting.lightDirection0);
53
+ case 1:
54
+ return DirectionalLight(lighting.lightColor1, lighting.lightDirection1);
55
+ case 2:
56
+ default:
57
+ return DirectionalLight(lighting.lightColor2, lighting.lightDirection2);
58
+ }
35
59
  }
36
60
  float getPointLightAttenuation(PointLight pointLight, float distance) {
37
61
  return pointLight.attenuation.x
@@ -12,11 +12,10 @@ export type PointLight = {
12
12
  position: Readonly<NumberArray3>;
13
13
  color?: Readonly<NumberArray3>;
14
14
  intensity?: number;
15
- attenuation?: number;
15
+ attenuation?: Readonly<NumberArray3>;
16
16
  };
17
17
  export type DirectionalLight = {
18
18
  type: 'directional';
19
- position: Readonly<NumberArray3>;
20
19
  direction: Readonly<NumberArray3>;
21
20
  color?: Readonly<NumberArray3>;
22
21
  intensity?: number;
@@ -37,10 +36,18 @@ export type LightingUniforms = {
37
36
  directionalLightCount: number;
38
37
  pointLightCount: number;
39
38
  lightType: number;
40
- lightColor: Readonly<NumberArray3>;
41
- lightPosition: Readonly<NumberArray3>;
42
- lightDirection: Readonly<NumberArray3>;
43
- lightAttenuation: Readonly<NumberArray3>;
39
+ lightColor0: Readonly<NumberArray3>;
40
+ lightPosition0: Readonly<NumberArray3>;
41
+ lightDirection0: Readonly<NumberArray3>;
42
+ lightAttenuation0: Readonly<NumberArray3>;
43
+ lightColor1: Readonly<NumberArray3>;
44
+ lightPosition1: Readonly<NumberArray3>;
45
+ lightDirection1: Readonly<NumberArray3>;
46
+ lightAttenuation1: Readonly<NumberArray3>;
47
+ lightColor2: Readonly<NumberArray3>;
48
+ lightPosition2: Readonly<NumberArray3>;
49
+ lightDirection2: Readonly<NumberArray3>;
50
+ lightAttenuation2: Readonly<NumberArray3>;
44
51
  };
45
52
  /** UBO ready lighting module */
46
53
  export declare const lighting: ShaderModule<LightingProps, LightingUniforms, {}>;
@@ -1 +1 @@
1
- {"version":3,"file":"lighting-uniforms.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/lights/lighting-uniforms.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,YAAY,EAAC,oDAAiD;AAEtE,OAAO,KAAK,EAAC,YAAY,EAAC,4CAAyC;AAcnE,4BAA4B;AAE5B,MAAM,MAAM,KAAK,GAAG,YAAY,GAAG,UAAU,GAAG,gBAAgB,CAAC;AAEjE,MAAM,MAAM,YAAY,GAAG;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
  import { lightingUniforms } from "./lighting-uniforms-glsl.js";
5
+ import { log } from '@luma.gl/core';
5
6
  /** Max number of supported lights (in addition to ambient light */
6
- const MAX_LIGHTS = 5;
7
+ const MAX_LIGHTS = 3;
7
8
  /** Whether to divide */
8
9
  const COLOR_FACTOR = 255.0;
9
10
  /** Shader type field for lights */
@@ -25,15 +26,24 @@ export const lighting = {
25
26
  },
26
27
  uniformTypes: {
27
28
  enabled: 'i32',
28
- lightType: 'i32', // , array: MAX_LIGHTS,
29
- directionalLightCount: 'i32', // , array: MAX_LIGHTS,
30
- pointLightCount: 'i32', // , array: MAX_LIGHTS,
29
+ lightType: 'i32',
30
+ directionalLightCount: 'i32',
31
+ pointLightCount: 'i32',
31
32
  ambientLightColor: 'vec3<f32>',
32
- lightColor: 'vec3<f32>', // , array: MAX_LIGHTS,
33
- lightPosition: 'vec3<f32>', // , array: MAX_LIGHTS,
33
+ // TODO define as arrays once we have appropriate uniformTypes
34
+ lightColor0: 'vec3<f32>',
35
+ lightPosition0: 'vec3<f32>',
34
36
  // TODO - could combine direction and attenuation
35
- lightDirection: 'vec3<f32>', // , array: MAX_LIGHTS,
36
- lightAttenuation: 'vec3<f32>' // , array: MAX_LIGHTS},
37
+ lightDirection0: 'vec3<f32>',
38
+ lightAttenuation0: 'vec3<f32>',
39
+ lightColor1: 'vec3<f32>',
40
+ lightPosition1: 'vec3<f32>',
41
+ lightDirection1: 'vec3<f32>',
42
+ lightAttenuation1: 'vec3<f32>',
43
+ lightColor2: 'vec3<f32>',
44
+ lightPosition2: 'vec3<f32>',
45
+ lightDirection2: 'vec3<f32>',
46
+ lightAttenuation2: 'vec3<f32>'
37
47
  },
38
48
  defaultUniforms: {
39
49
  enabled: 1,
@@ -41,11 +51,19 @@ export const lighting = {
41
51
  directionalLightCount: 0,
42
52
  pointLightCount: 0,
43
53
  ambientLightColor: [0.1, 0.1, 0.1],
44
- lightColor: [1, 1, 1],
45
- lightPosition: [1, 1, 2],
54
+ lightColor0: [1, 1, 1],
55
+ lightPosition0: [1, 1, 2],
46
56
  // TODO - could combine direction and attenuation
47
- lightDirection: [1, 1, 1],
48
- lightAttenuation: [1, 1, 1]
57
+ lightDirection0: [1, 1, 1],
58
+ lightAttenuation0: [1, 0, 0],
59
+ lightColor1: [1, 1, 1],
60
+ lightPosition1: [1, 1, 2],
61
+ lightDirection1: [1, 1, 1],
62
+ lightAttenuation1: [1, 0, 0],
63
+ lightColor2: [1, 1, 1],
64
+ lightPosition2: [1, 1, 2],
65
+ lightDirection2: [1, 1, 1],
66
+ lightAttenuation2: [1, 0, 0]
49
67
  }
50
68
  };
51
69
  function getUniforms(props, prevUniforms = {}) {
@@ -79,37 +97,27 @@ function getUniforms(props, prevUniforms = {}) {
79
97
  return uniforms;
80
98
  }
81
99
  function getLightSourceUniforms({ ambientLight, pointLights = [], directionalLights = [] }) {
82
- const lightSourceUniforms = {
83
- // lightType: new Array(MAX_LIGHTS).fill(0),
84
- // lightColor: new Array(MAX_LIGHTS).fill([0, 0, 0]),
85
- // lightPosition: new Array(MAX_LIGHTS).fill([0, 0, 0]),
86
- // lightDirection: new Array(MAX_LIGHTS).fill([0, 0, 0]),
87
- // lightAttenuation: new Array(MAX_LIGHTS).fill([0, 0, 0])
88
- };
100
+ const lightSourceUniforms = {};
89
101
  lightSourceUniforms.ambientLightColor = convertColor(ambientLight);
90
102
  let currentLight = 0;
91
103
  for (const pointLight of pointLights) {
92
- // lightSourceUniforms.lightType[currentLight] = LIGHT_TYPE.POINT;
93
- // lightSourceUniforms.lightColor[currentLight] = convertColor(pointLight);
94
- // lightSourceUniforms.lightPosition[currentLight] = pointLight.position;
95
- // lightSourceUniforms.lightAttenuation[currentLight] = [pointLight.attenuation || 1, 0, 0];
96
104
  lightSourceUniforms.lightType = LIGHT_TYPE.POINT;
97
- lightSourceUniforms.lightColor = convertColor(pointLight);
98
- lightSourceUniforms.lightPosition = pointLight.position;
99
- lightSourceUniforms.lightAttenuation = [pointLight.attenuation || 1, 0, 0];
105
+ const i = currentLight;
106
+ lightSourceUniforms[`lightColor${i}`] = convertColor(pointLight);
107
+ lightSourceUniforms[`lightPosition${i}`] = pointLight.position;
108
+ lightSourceUniforms[`lightAttenuation${i}`] = pointLight.attenuation || [1, 0, 0];
100
109
  currentLight++;
101
110
  }
102
111
  for (const directionalLight of directionalLights) {
103
- // lightSourceUniforms.lightType[currentLight] = LIGHT_TYPE.DIRECTIONAL;
104
- // lightSourceUniforms.lightColor[currentLight] = convertColor(directionalLight);
105
- // lightSourceUniforms.lightPosition[currentLight] = directionalLight.position;
106
- // lightSourceUniforms.lightDirection[currentLight] = directionalLight.direction;
107
112
  lightSourceUniforms.lightType = LIGHT_TYPE.DIRECTIONAL;
108
- lightSourceUniforms.lightColor = convertColor(directionalLight);
109
- lightSourceUniforms.lightPosition = directionalLight.position;
110
- lightSourceUniforms.lightDirection = directionalLight.direction;
113
+ const i = currentLight;
114
+ lightSourceUniforms[`lightColor${i}`] = convertColor(directionalLight);
115
+ lightSourceUniforms[`lightDirection${i}`] = directionalLight.direction;
111
116
  currentLight++;
112
117
  }
118
+ if (currentLight > MAX_LIGHTS) {
119
+ log.warn('MAX_LIGHTS exceeded')();
120
+ }
113
121
  lightSourceUniforms.directionalLightCount = directionalLights.length;
114
122
  lightSourceUniforms.pointLightCount = pointLights.length;
115
123
  return lightSourceUniforms;
@@ -1,12 +1,12 @@
1
1
  import { ShaderModule } from "../../../lib/shader-module/shader-module.js";
2
- export type PhongMaterialProps = PhongMaterialUniforms;
3
- export type PhongMaterialUniforms = {
2
+ import type { NumberArray3 } from "../../../lib/utils/uniform-types.js";
3
+ export type PhongMaterialProps = {
4
4
  ambient?: number;
5
5
  diffuse?: number;
6
6
  /** Specularity exponent */
7
7
  shininess?: number;
8
- specularColor?: [number, number, number];
8
+ specularColor?: NumberArray3;
9
9
  };
10
10
  /** In Phong shading, the normal vector is linearly interpolated across the surface of the polygon from the polygon's vertex normals. */
11
- export declare const phongMaterial: ShaderModule<PhongMaterialProps, PhongMaterialUniforms>;
11
+ export declare const phongMaterial: ShaderModule<PhongMaterialProps>;
12
12
  //# sourceMappingURL=phong-material.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"phong-material.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/phong-material/phong-material.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,YAAY,EAAC,oDAAiD;AAItE,MAAM,MAAM,kBAAkB,GAAG,qBAAqB,CAAC;AAEvD,MAAM,MAAM,qBAAqB,GAAG;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2BAA2B;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;CAC1C,CAAC;AAEF,wIAAwI;AACxI,eAAO,MAAM,aAAa,EAAE,YAAY,CAAC,kBAAkB,EAAE,qBAAqB,CAwBjF,CAAC"}
1
+ {"version":3,"file":"phong-material.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/phong-material/phong-material.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,YAAY,EAAC,oDAAiD;AAGtE,OAAO,KAAK,EAAC,YAAY,EAAC,4CAAyC;AAEnE,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2BAA2B;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,YAAY,CAAC;CAC9B,CAAC;AAEF,wIAAwI;AACxI,eAAO,MAAM,aAAa,EAAE,YAAY,CAAC,kBAAkB,CA4B1D,CAAC"}
@@ -26,6 +26,10 @@ export const phongMaterial = {
26
26
  specularColor: [0.15, 0.15, 0.15]
27
27
  },
28
28
  getUniforms(props) {
29
+ const uniforms = { ...props };
30
+ if (uniforms.specularColor) {
31
+ uniforms.specularColor = uniforms.specularColor.map(x => x / 255);
32
+ }
29
33
  return { ...phongMaterial.defaultUniforms, ...props };
30
34
  }
31
35
  };
@@ -1,42 +1,3 @@
1
1
  export declare const PHONG_VS: string;
2
2
  export declare const PHONG_FS: string;
3
- /**
4
- for (int i = 0; i < MAX_LIGHTS; i++) {
5
- if (i >= lighting.pointLightCount) {
6
- break;
7
- }
8
- PointLight pointLight = lighting_getPointLight(i);
9
- vec3 light_position_worldspace = pointLight.position;
10
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
11
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
12
- }
13
-
14
- for (int i = 0; i < MAX_LIGHTS; i++) {
15
- if (i >= lighting.directionalLightCount) {
16
- break;
17
- }
18
- PointLight pointLight = lighting_getDirectionalLight(i);
19
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
20
- }
21
- }
22
- /**
23
- for (int i = 0; i < MAX_LIGHTS; i++) {
24
- if (i >= lighting.pointLightCount) {
25
- break;
26
- }
27
- PointLight pointLight = lighting_getPointLight(i);
28
- vec3 light_position_worldspace = pointLight.position;
29
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
30
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
31
- }
32
-
33
- for (int i = 0; i < MAX_LIGHTS; i++) {
34
- if (i >= lighting.directionalLightCount) {
35
- break;
36
- }
37
- PointLight pointLight = lighting_getDirectionalLight(i);
38
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
39
- }
40
- }
41
- */
42
3
  //# sourceMappingURL=phong-shaders-glsl.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"phong-shaders-glsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/phong-material/phong-shaders-glsl.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,QAAQ,QAOpB,CAAC;AAEF,eAAO,MAAM,QAAQ,QAuFpB,CAAC;AAGF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAsCI"}
1
+ {"version":3,"file":"phong-shaders-glsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/phong-material/phong-shaders-glsl.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,QAAQ,QAOpB,CAAC;AAEF,eAAO,MAAM,QAAQ,QA+CpB,CAAC"}
@@ -35,76 +35,18 @@ return lightColor;
35
35
  }
36
36
  vec3 view_direction = normalize(cameraPosition - position_worldspace);
37
37
  lightColor = material.ambient * surfaceColor * lighting.ambientColor;
38
- if (lighting.lightType == 0) {
39
- PointLight pointLight = lighting_getPointLight(0);
38
+ for (int i = 0; i < lighting.pointLightCount; i++) {
39
+ PointLight pointLight = lighting_getPointLight(i);
40
40
  vec3 light_position_worldspace = pointLight.position;
41
41
  vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
42
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
43
- } else if (lighting.lightType == 1) {
44
- DirectionalLight directionalLight = lighting_getDirectionalLight(0);
45
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
46
- }
47
- return lightColor;
42
+ float light_attenuation = getPointLightAttenuation(pointLight, distance(light_position_worldspace, position_worldspace));
43
+ lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color / light_attenuation);
48
44
  }
49
- vec3 lighting_getSpecularLightColor(vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
50
- vec3 lightColor = vec3(0, 0, 0);
51
- vec3 surfaceColor = vec3(0, 0, 0);
52
- if (lighting.enabled == 0) {
53
- return lightColor;
54
- }
55
- vec3 view_direction = normalize(cameraPosition - position_worldspace);
56
- switch (lighting.lightType) {
57
- case 0:
58
- PointLight pointLight = lighting_getPointLight(0);
59
- vec3 light_position_worldspace = pointLight.position;
60
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
61
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
62
- break;
63
- case 1:
64
- DirectionalLight directionalLight = lighting_getDirectionalLight(0);
45
+ int totalLights = min(MAX_LIGHTS, lighting.pointLightCount + lighting.directionalLightCount);
46
+ for (int i = lighting.pointLightCount; i < totalLights; i++) {
47
+ DirectionalLight directionalLight = lighting_getDirectionalLight(i);
65
48
  lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
66
- break;
67
49
  }
68
50
  return lightColor;
69
51
  }
70
52
  `;
71
- // TODO - handle multiple lights
72
- /**
73
- for (int i = 0; i < MAX_LIGHTS; i++) {
74
- if (i >= lighting.pointLightCount) {
75
- break;
76
- }
77
- PointLight pointLight = lighting_getPointLight(i);
78
- vec3 light_position_worldspace = pointLight.position;
79
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
80
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
81
- }
82
-
83
- for (int i = 0; i < MAX_LIGHTS; i++) {
84
- if (i >= lighting.directionalLightCount) {
85
- break;
86
- }
87
- PointLight pointLight = lighting_getDirectionalLight(i);
88
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
89
- }
90
- }
91
- /**
92
- for (int i = 0; i < MAX_LIGHTS; i++) {
93
- if (i >= lighting.pointLightCount) {
94
- break;
95
- }
96
- PointLight pointLight = lighting_getPointLight(i);
97
- vec3 light_position_worldspace = pointLight.position;
98
- vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
99
- lightColor += lighting_getLightColor(surfaceColor, light_direction, view_direction, normal_worldspace, pointLight.color);
100
- }
101
-
102
- for (int i = 0; i < MAX_LIGHTS; i++) {
103
- if (i >= lighting.directionalLightCount) {
104
- break;
105
- }
106
- PointLight pointLight = lighting_getDirectionalLight(i);
107
- lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, view_direction, normal_worldspace, directionalLight.color);
108
- }
109
- }
110
- */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luma.gl/shadertools",
3
- "version": "9.0.19",
3
+ "version": "9.0.21",
4
4
  "description": "Shader module system for luma.gl",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -53,5 +53,5 @@
53
53
  "@math.gl/types": "^4.0.0",
54
54
  "wgsl_reflect": "^1.0.1"
55
55
  },
56
- "gitHead": "5e1ede7bdaf2c9ccdbd167804601537e93dc4225"
56
+ "gitHead": "9d7d29778581c2408fc3f37723f6868983d0dab2"
57
57
  }
package/src/index.ts CHANGED
@@ -71,9 +71,9 @@ export {picking} from './modules/engine/picking/picking';
71
71
  export type {LightingProps} from './modules/lighting/lights/lighting-uniforms';
72
72
  export {lighting} from './modules/lighting/lights/lighting-uniforms';
73
73
  export {dirlight} from './modules/lighting/no-material/dirlight';
74
- export type {PhongMaterialUniforms as GouraudMaterialUniforms} from './modules/lighting/phong-material/phong-material';
74
+ export type {GouraudMaterialProps} from './modules/lighting/gouraud-material/gouraud-material';
75
75
  export {gouraudMaterial} from './modules/lighting/gouraud-material/gouraud-material';
76
- export type {PhongMaterialUniforms} from './modules/lighting/phong-material/phong-material';
76
+ export type {PhongMaterialProps} from './modules/lighting/phong-material/phong-material';
77
77
  export {phongMaterial} from './modules/lighting/phong-material/phong-material';
78
78
  // export type {PBRMaterialSettings, PBRMaterialUniforms} from './modules/lighting/pbr-material/pbr';
79
79
  export {pbrMaterial} from './modules/lighting/pbr-material/pbr-material';
@@ -4,11 +4,10 @@
4
4
 
5
5
  import {ShaderModule} from '../../../lib/shader-module/shader-module';
6
6
  import {lighting} from '../lights/lighting-uniforms';
7
- import {GOURAUD_VS, GOURAUD_FS} from './gouraud-shaders-glsl';
7
+ import {PHONG_VS, PHONG_FS} from '../phong-material/phong-shaders-glsl';
8
+ import type {NumberArray3} from '../../../lib/utils/uniform-types';
8
9
 
9
- export type GouraudMaterialProps = GouraudMaterialUniforms;
10
-
11
- export type GouraudMaterialUniforms = {
10
+ export type GouraudMaterialProps = {
12
11
  ambient?: number;
13
12
  diffuse?: number;
14
13
  /** Specularity exponent */
@@ -17,11 +16,11 @@ export type GouraudMaterialUniforms = {
17
16
  };
18
17
 
19
18
  /** In Gouraud shading, color is calculated for each triangle vertex normal, and then color is interpolated colors across the triangle */
20
- export const gouraudMaterial: ShaderModule<GouraudMaterialProps, GouraudMaterialUniforms> = {
19
+ export const gouraudMaterial: ShaderModule<GouraudMaterialProps> = {
21
20
  name: 'gouraudMaterial',
22
21
  // Note these are switched between phong and gouraud
23
- vs: GOURAUD_VS,
24
- fs: GOURAUD_FS,
22
+ vs: PHONG_FS.replace('phongMaterial', 'gouraudMaterial'),
23
+ fs: PHONG_VS.replace('phongMaterial', 'gouraudMaterial'),
25
24
  defines: {
26
25
  LIGHTING_VERTEX: 1
27
26
  },
@@ -38,7 +37,11 @@ export const gouraudMaterial: ShaderModule<GouraudMaterialProps, GouraudMaterial
38
37
  shininess: 32,
39
38
  specularColor: [0.15, 0.15, 0.15]
40
39
  },
41
- getUniforms(props: GouraudMaterialProps): GouraudMaterialUniforms {
40
+ getUniforms(props: GouraudMaterialProps) {
41
+ const uniforms = {...props};
42
+ if (uniforms.specularColor) {
43
+ uniforms.specularColor = uniforms.specularColor.map(x => x / 255) as NumberArray3;
44
+ }
42
45
  return {...gouraudMaterial.defaultUniforms, ...props};
43
46
  }
44
47
  };
@@ -32,22 +32,44 @@ uniform lightingUniforms {
32
32
 
33
33
  vec3 ambientColor;
34
34
 
35
- vec3 lightColor;
36
- vec3 lightPosition;
37
- vec3 lightDirection;
38
- vec3 lightAttenuation;
39
-
40
- // AmbientLight ambientLight;
41
- // PointLight pointLight[MAX_LIGHTS];
42
- // DirectionalLight directionalLight[MAX_LIGHTS];
35
+ vec3 lightColor0;
36
+ vec3 lightPosition0;
37
+ vec3 lightDirection0;
38
+ vec3 lightAttenuation0;
39
+
40
+ vec3 lightColor1;
41
+ vec3 lightPosition1;
42
+ vec3 lightDirection1;
43
+ vec3 lightAttenuation1;
44
+
45
+ vec3 lightColor2;
46
+ vec3 lightPosition2;
47
+ vec3 lightDirection2;
48
+ vec3 lightAttenuation2;
43
49
  } lighting;
44
50
 
45
51
  PointLight lighting_getPointLight(int index) {
46
- return PointLight(lighting.lightColor, lighting.lightPosition, lighting.lightAttenuation);
52
+ switch (index) {
53
+ case 0:
54
+ return PointLight(lighting.lightColor0, lighting.lightPosition0, lighting.lightAttenuation0);
55
+ case 1:
56
+ return PointLight(lighting.lightColor1, lighting.lightPosition1, lighting.lightAttenuation1);
57
+ case 2:
58
+ default:
59
+ return PointLight(lighting.lightColor2, lighting.lightPosition2, lighting.lightAttenuation2);
60
+ }
47
61
  }
48
62
 
49
63
  DirectionalLight lighting_getDirectionalLight(int index) {
50
- return DirectionalLight(lighting.lightColor, lighting.lightDirection);
64
+ switch (index) {
65
+ case 0:
66
+ return DirectionalLight(lighting.lightColor0, lighting.lightDirection0);
67
+ case 1:
68
+ return DirectionalLight(lighting.lightColor1, lighting.lightDirection1);
69
+ case 2:
70
+ default:
71
+ return DirectionalLight(lighting.lightColor2, lighting.lightDirection2);
72
+ }
51
73
  }
52
74
 
53
75
  float getPointLightAttenuation(PointLight pointLight, float distance) {