@luma.gl/shaders 10.0.0-alpha.11 → 10.0.0-alpha.13

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 (35) hide show
  1. package/LICENSE +4 -4
  2. package/THIRD-PARTY-NOTICES.md +31 -0
  3. package/dist/dist.dev.js +147 -2
  4. package/dist/dist.min.js +235 -131
  5. package/dist/glsl.cjs.map +1 -1
  6. package/dist/index.cjs +6 -0
  7. package/dist/index.cjs.map +2 -2
  8. package/dist/index.d.ts +3 -0
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +2 -0
  11. package/dist/index.js.map +1 -1
  12. package/dist/modules/lighting/lightmap/lightmap-filter.cjs +93 -0
  13. package/dist/modules/lighting/lightmap/lightmap-filter.d.ts +35 -0
  14. package/dist/modules/lighting/lightmap/lightmap-filter.d.ts.map +1 -0
  15. package/dist/modules/lighting/lightmap/lightmap-filter.js +71 -0
  16. package/dist/modules/lighting/lightmap/lightmap-filter.js.map +1 -0
  17. package/dist/modules/lighting/lightmap/lightmap.cjs +89 -0
  18. package/dist/modules/lighting/lightmap/lightmap.d.ts +405 -0
  19. package/dist/modules/lighting/lightmap/lightmap.d.ts.map +1 -0
  20. package/dist/modules/lighting/lightmap/lightmap.js +67 -0
  21. package/dist/modules/lighting/lightmap/lightmap.js.map +1 -0
  22. package/dist/types/shader-type-decoder.cjs +12 -2
  23. package/dist/types/shader-type-decoder.d.ts +7 -7
  24. package/dist/types/shader-type-decoder.d.ts.map +1 -1
  25. package/dist/types/shader-type-decoder.js +13 -2
  26. package/dist/types/shader-type-decoder.js.map +1 -1
  27. package/dist/types.cjs.map +1 -1
  28. package/dist/wgsl.cjs.map +1 -1
  29. package/licenses/pbr.txt +58 -0
  30. package/licenses/three.txt +21 -0
  31. package/package.json +7 -4
  32. package/src/index.ts +4 -0
  33. package/src/modules/lighting/lightmap/lightmap-filter.ts +73 -0
  34. package/src/modules/lighting/lightmap/lightmap.ts +76 -0
  35. package/src/types/shader-type-decoder.ts +22 -9
@@ -0,0 +1,58 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2016-2017 Mohamad Moneimne and Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10
+
11
+ Third-Party Code
12
+ =============================
13
+
14
+ ## glMatrix
15
+
16
+ https://github.com/toji/gl-matrix
17
+
18
+ Matrix calculations are handled using glMatrix.
19
+
20
+ > Copyright (c) 2015, Brandon Jones, Colin MacKenzie IV.
21
+ >
22
+ > Permission is hereby granted, free of charge, to any person obtaining a copy
23
+ of this software and associated documentation files (the "Software"), to deal
24
+ in the Software without restriction, including without limitation the rights
25
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
26
+ copies of the Software, and to permit persons to whom the Software is
27
+ furnished to do so, subject to the following conditions:
28
+ >
29
+ > The above copyright notice and this permission notice shall be included in
30
+ all copies or substantial portions of the Software.
31
+ >
32
+ > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
38
+ THE SOFTWARE.
39
+
40
+ ## dat.gui
41
+
42
+ https://github.com/dataarts/dat.gui
43
+
44
+ The GUI is handled by dat.gui.
45
+
46
+ >Copyright 2014, Google Inc.
47
+ >
48
+ >Licensed under the Apache License, Version 2.0 (the "License");
49
+ you may not use this file except in compliance with the License.
50
+ You may obtain a copy of the License at
51
+
52
+ > http://www.apache.org/licenses/LICENSE-2.0
53
+
54
+ >Unless required by applicable law or agreed to in writing, software
55
+ distributed under the License is distributed on an "AS IS" BASIS,
56
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
57
+ See the License for the specific language governing permissions and
58
+ limitations under the License.
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright © 2010-2026 three.js authors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luma.gl/shaders",
3
- "version": "10.0.0-alpha.11",
3
+ "version": "10.0.0-alpha.13",
4
4
  "description": "Shader module system for luma.gl",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -52,7 +52,10 @@
52
52
  "src",
53
53
  "dist",
54
54
  "dist.min.js",
55
- "README.md"
55
+ "README.md",
56
+ "LICENSE",
57
+ "THIRD-PARTY-NOTICES.md",
58
+ "licenses"
56
59
  ],
57
60
  "sideEffects": false,
58
61
  "scripts": {
@@ -61,7 +64,7 @@
61
64
  "prepublishOnly": "npm run build-minified-bundle && npm run build-dev-bundle"
62
65
  },
63
66
  "dependencies": {
64
- "@math.gl/core": "~5.0.0-beta.5"
67
+ "@math.gl/core": "~5.0.0-beta.7"
65
68
  },
66
- "gitHead": "abf0b44182fb51a73368e71f1166ca1cf4de63d6"
69
+ "gitHead": "0e04045e4ca306793aa2b6f86065b0560e30967e"
67
70
  }
package/src/index.ts CHANGED
@@ -305,3 +305,7 @@ export type {PBRContactShadowProps} from './modules/lighting/pbr-contact-shadow/
305
305
  export {clusteredLightGrid} from './modules/lighting/clustered-light-grid/clustered-light-grid';
306
306
  export {pbrAmbientOcclusion} from './modules/lighting/pbr-ambient-occlusion/pbr-ambient-occlusion';
307
307
  export type {PBRAmbientOcclusionProps} from './modules/lighting/pbr-ambient-occlusion/pbr-ambient-occlusion';
308
+
309
+ export {lightmapBake} from './modules/lighting/lightmap/lightmap';
310
+ export type {LightmapBakeUniforms} from './modules/lighting/lightmap/lightmap';
311
+ export {lightmapFilter} from './modules/lighting/lightmap/lightmap-filter';
@@ -0,0 +1,73 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
3
+
4
+ import type {ShaderModule} from '../../../lib/shader-module/shader-module';
5
+
6
+ /** Internal accumulation/copy/dilation shader shared by the engine baker. */
7
+ export const lightmapFilter = {
8
+ name: 'lightmapFilter',
9
+ bindingLayout: [
10
+ {name: 'lightmapFilter', group: 0},
11
+ {name: 'currentTexture', group: 0},
12
+ {name: 'previousTexture', group: 0},
13
+ {name: 'chartTexture', group: 0}
14
+ ],
15
+ uniformTypes: {weight: 'f32', mode: 'i32'},
16
+ defaultUniforms: {weight: 1, mode: 0},
17
+ getUniforms: (props: {weight?: number; mode?: number}) => props,
18
+ source: `
19
+ struct LightmapFilterUniforms {weight: f32, mode: i32};
20
+ @group(0) @binding(auto) var<uniform> lightmapFilter: LightmapFilterUniforms;
21
+ @group(0) @binding(auto) var currentTexture: texture_2d<f32>;
22
+ @group(0) @binding(auto) var previousTexture: texture_2d<f32>;
23
+ @group(0) @binding(auto) var chartTexture: texture_2d<f32>;
24
+ fn lightmapFilter_getColor(coordinates: vec2i) -> vec4f {
25
+ let current = textureLoad(currentTexture, coordinates, 0);
26
+ if (lightmapFilter.mode == 0) {
27
+ let previous = textureLoad(previousTexture, coordinates, 0);
28
+ return vec4f(mix(previous.rgb, current.rgb, lightmapFilter.weight), current.a);
29
+ }
30
+ if (lightmapFilter.mode == 2 || current.a > 0.0) {return current;}
31
+ let chart = textureLoad(chartTexture, coordinates, 0).r;
32
+ if (chart <= 0.0) {return current;}
33
+ let size = vec2i(textureDimensions(currentTexture));
34
+ for (var y = -1; y <= 1; y++) {
35
+ for (var x = -1; x <= 1; x++) {
36
+ let neighbor = coordinates + vec2i(x, y);
37
+ if (all(neighbor >= vec2i(0)) && all(neighbor < size)) {
38
+ let candidate = textureLoad(currentTexture, neighbor, 0);
39
+ if (candidate.a == chart) {return candidate;}
40
+ }
41
+ }
42
+ }
43
+ return current;
44
+ }`,
45
+ fs: `
46
+ layout(std140) uniform lightmapFilterUniforms {
47
+ float weight;
48
+ int mode;
49
+ } lightmapFilter;
50
+ uniform sampler2D currentTexture;
51
+ uniform sampler2D previousTexture;
52
+ uniform sampler2D chartTexture;
53
+ vec4 lightmapFilter_getColor(ivec2 coordinates) {
54
+ vec4 current = texelFetch(currentTexture, coordinates, 0);
55
+ if (lightmapFilter.mode == 0) {
56
+ return vec4(mix(texelFetch(previousTexture, coordinates, 0).rgb, current.rgb, lightmapFilter.weight), current.a);
57
+ }
58
+ if (lightmapFilter.mode == 2 || current.a > 0.0) {return current;}
59
+ float chart = texelFetch(chartTexture, coordinates, 0).r;
60
+ ivec2 size = textureSize(currentTexture, 0);
61
+ if (chart <= 0.0) return current;
62
+ for (int y = -1; y <= 1; y++) {
63
+ for (int x = -1; x <= 1; x++) {
64
+ ivec2 neighbor = coordinates + ivec2(x,y);
65
+ if (all(greaterThanEqual(neighbor, ivec2(0))) && all(lessThan(neighbor,size))) {
66
+ vec4 candidate = texelFetch(currentTexture, neighbor, 0);
67
+ if (candidate.a == chart) {return candidate;}
68
+ }
69
+ }
70
+ }
71
+ return current;
72
+ }`
73
+ } as const satisfies ShaderModule<{weight?: number; mode?: number}, {weight: number; mode: number}>;
@@ -0,0 +1,76 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
3
+
4
+ import type {NumberArray9} from '@math.gl/core';
5
+ import type {ShaderModule} from '../../../lib/shader-module/shader-module';
6
+ import {pbrMaterial} from '../pbr-material/pbr-material';
7
+
8
+ export type LightmapBakeUniforms = {
9
+ uvSet: number;
10
+ uvTransform: Readonly<NumberArray9>;
11
+ chartId: number;
12
+ };
13
+
14
+ /** Texture-space rasterization controls. Chart IDs are positive integers exactly representable in the target format. */
15
+ export const lightmapBake = {
16
+ name: 'lightmapBake',
17
+ dependencies: [pbrMaterial],
18
+ bindingLayout: [{name: 'lightmapBake', group: 0}],
19
+ uniformTypes: {uvSet: 'i32', uvTransform: 'mat3x3<f32>', chartId: 'f32'},
20
+ defaultUniforms: {uvSet: 1, uvTransform: [1, 0, 0, 0, 1, 0, 0, 0, 1], chartId: 1},
21
+ getUniforms: (props: Partial<LightmapBakeUniforms>) => props,
22
+ source: `
23
+ struct LightmapBakeUniforms {uvSet: i32, uvTransform: mat3x3f, chartId: f32};
24
+ @group(0) @binding(auto) var<uniform> lightmapBake: LightmapBakeUniforms;
25
+
26
+ fn lightmap_getIrradiance(position: vec3f, normal: vec3f, directionalVisibility: f32, pointVisibility: vec4f, spotVisibility: vec4f) -> vec3f {
27
+ if (lighting.enabled == 0) {return vec3f(0.0);}
28
+ var irradiance = lighting.ambientColor;
29
+ for (var index = 0; index < lighting.directionalLightCount; index++) {
30
+ let light = lighting_getDirectionalLight(index);
31
+ irradiance += light.color * max(dot(normal, -normalize(light.direction)), 0.0) * select(1.0, directionalVisibility, index == 0);
32
+ }
33
+ for (var index = 0; index < lighting.pointLightCount; index++) {
34
+ let light = lighting_getPointLight(index);
35
+ let offset = light.position - position;
36
+ let visibility = select(1.0, pointVisibility[min(index, 3)], index < 4);
37
+ irradiance += light.color * max(dot(normal, normalize(offset)), 0.0) * visibility / max(getPointLightAttenuation(light, length(offset)), 0.0001);
38
+ }
39
+ for (var index = 0; index < lighting.spotLightCount; index++) {
40
+ let light = lighting_getSpotLight(index);
41
+ irradiance += light.color * max(dot(normal, normalize(light.position - position)), 0.0) * select(1.0, spotVisibility[min(index, 3)], index < 4) / max(getSpotLightAttenuation(light, position), 0.0001);
42
+ }
43
+ return irradiance;
44
+ }
45
+ `,
46
+ vs: `layout(std140) uniform lightmapBakeUniforms {
47
+ int uvSet;
48
+ mat3 uvTransform;
49
+ float chartId;
50
+ } lightmapBake;`,
51
+ fs: `layout(std140) uniform lightmapBakeUniforms {
52
+ int uvSet;
53
+ mat3 uvTransform;
54
+ float chartId;
55
+ } lightmapBake;
56
+
57
+ vec3 lightmap_getIrradiance(vec3 position, vec3 normal, float directionalVisibility, vec4 pointVisibility, vec4 spotVisibility) {
58
+ if (lighting.enabled == 0) {return vec3(0.0);}
59
+ vec3 irradiance = lighting.ambientColor;
60
+ for (int index = 0; index < lighting.directionalLightCount; index++) {
61
+ DirectionalLight light = lighting_getDirectionalLight(index);
62
+ irradiance += light.color * max(dot(normal, -normalize(light.direction)), 0.0) * (index == 0 ? directionalVisibility : 1.0);
63
+ }
64
+ for (int index = 0; index < lighting.pointLightCount; index++) {
65
+ PointLight light = lighting_getPointLight(index);
66
+ vec3 offset = light.position - position;
67
+ irradiance += light.color * max(dot(normal, normalize(offset)), 0.0) * (index < 4 ? pointVisibility[index] : 1.0) / max(getPointLightAttenuation(light, length(offset)), 0.0001);
68
+ }
69
+ for (int index = 0; index < lighting.spotLightCount; index++) {
70
+ SpotLight light = lighting_getSpotLight(index);
71
+ irradiance += light.color * max(dot(normal, normalize(light.position - position)), 0.0) * (index < 4 ? spotVisibility[index] : 1.0) / max(getSpotLightAttenuation(light, position), 0.0001);
72
+ }
73
+ return irradiance;
74
+ }
75
+ `
76
+ } as const satisfies ShaderModule<Partial<LightmapBakeUniforms>, LightmapBakeUniforms>;
@@ -12,22 +12,22 @@ import {
12
12
 
13
13
  /** Information extracted from a VariableShaderType constant */
14
14
  export type VariableShaderTypeInfo = {
15
- type: PrimitiveDataType;
16
- components: number;
15
+ readonly type: PrimitiveDataType;
16
+ readonly components: number;
17
17
  };
18
18
 
19
19
  /** Information extracted from a AttributeShaderType constant */
20
20
  export type AttributeShaderTypeInfo = {
21
21
  /** WGSL-style primitive data type, f32, i32, u32 */
22
- primitiveType: PrimitiveDataType;
22
+ readonly primitiveType: PrimitiveDataType;
23
23
  /** Whether this is a normalized integer (that must be used as float) */
24
- components: 1 | 2 | 3 | 4;
24
+ readonly components: 1 | 2 | 3 | 4;
25
25
  /** Length in bytes of the data for one vertex */
26
- byteLength?: number;
26
+ readonly byteLength?: number;
27
27
  /** Whether this is for integer or float vert */
28
- integer: boolean;
28
+ readonly integer: boolean;
29
29
  /** Whether this data type is signed */
30
- signed: boolean;
30
+ readonly signed: boolean;
31
31
  };
32
32
 
33
33
  /** Split a uniform type string into type and components */
@@ -42,11 +42,17 @@ export function getVariableShaderTypeInfo(
42
42
  return decoded;
43
43
  }
44
44
 
45
+ const attributeShaderTypeInfoCache = new Map<AttributeShaderType, AttributeShaderTypeInfo>();
46
+
45
47
  /** Decodes a vertex type, returning byte length and flags (integer, signed, normalized) */
46
48
  export function getAttributeShaderTypeInfo(
47
49
  attributeType: AttributeShaderType | AttributeShaderTypeAlias
48
50
  ): AttributeShaderTypeInfo {
49
51
  const resolvedAttributeType = resolveAttributeShaderTypeAlias(attributeType);
52
+ const cached = attributeShaderTypeInfoCache.get(resolvedAttributeType);
53
+ if (cached) {
54
+ return cached;
55
+ }
50
56
  const decoded = TYPE_INFO[resolvedAttributeType];
51
57
  if (!decoded) {
52
58
  throw new Error(`Unsupported attribute shader type: ${attributeType}`);
@@ -56,13 +62,15 @@ export function getAttributeShaderTypeInfo(
56
62
  const signed: boolean = primitiveType !== 'u32';
57
63
 
58
64
  const byteLength = PRIMITIVE_TYPE_SIZES[primitiveType] * components;
59
- return {
65
+ const result = Object.freeze({
60
66
  primitiveType,
61
67
  components,
62
68
  byteLength,
63
69
  integer,
64
70
  signed
65
- };
71
+ });
72
+ attributeShaderTypeInfoCache.set(resolvedAttributeType, result);
73
+ return result;
66
74
  }
67
75
 
68
76
  export class ShaderTypeDecoder {
@@ -211,6 +219,11 @@ const UNIFORM_FORMATS: Record<VariableShaderType, {type: PrimitiveDataType; comp
211
219
  'mat4x4<u32>': {type: 'u32', components: 16}
212
220
  };
213
221
 
222
+ // Variable metadata is already allocated in the table; freeze it once, without another cache.
223
+ for (const info of Object.values(UNIFORM_FORMATS)) {
224
+ Object.freeze(info);
225
+ }
226
+
214
227
  /** Predeclared aliases @see https://www.w3.org/TR/WGSL/#vector-types */
215
228
  export const WGSL_ATTRIBUTE_TYPE_ALIAS_MAP: Record<AttributeShaderTypeAlias, AttributeShaderType> =
216
229
  {