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

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 (89) hide show
  1. package/dist/dist.dev.js +1776 -58
  2. package/dist/dist.min.js +1394 -147
  3. package/dist/index.cjs +35 -0
  4. package/dist/index.cjs.map +3 -3
  5. package/dist/index.d.ts +17 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +9 -0
  8. package/dist/index.js.map +1 -1
  9. package/dist/modules/lighting/clustered-light-grid/clustered-light-grid.cjs +40 -0
  10. package/dist/modules/lighting/clustered-light-grid/clustered-light-grid.d.ts +6 -0
  11. package/dist/modules/lighting/clustered-light-grid/clustered-light-grid.d.ts.map +1 -0
  12. package/dist/modules/lighting/clustered-light-grid/clustered-light-grid.js +15 -0
  13. package/dist/modules/lighting/clustered-light-grid/clustered-light-grid.js.map +1 -0
  14. package/dist/modules/lighting/contact-shadow/contact-shadow.cjs +348 -0
  15. package/dist/modules/lighting/contact-shadow/contact-shadow.d.ts +188 -0
  16. package/dist/modules/lighting/contact-shadow/contact-shadow.d.ts.map +1 -0
  17. package/dist/modules/lighting/contact-shadow/contact-shadow.js +307 -0
  18. package/dist/modules/lighting/contact-shadow/contact-shadow.js.map +1 -0
  19. package/dist/modules/lighting/pbr-ambient-occlusion/pbr-ambient-occlusion.cjs +87 -0
  20. package/dist/modules/lighting/pbr-ambient-occlusion/pbr-ambient-occlusion.d.ts +21 -0
  21. package/dist/modules/lighting/pbr-ambient-occlusion/pbr-ambient-occlusion.d.ts.map +1 -0
  22. package/dist/modules/lighting/pbr-ambient-occlusion/pbr-ambient-occlusion.js +61 -0
  23. package/dist/modules/lighting/pbr-ambient-occlusion/pbr-ambient-occlusion.js.map +1 -0
  24. package/dist/modules/lighting/pbr-contact-shadow/pbr-contact-shadow.cjs +87 -0
  25. package/dist/modules/lighting/pbr-contact-shadow/pbr-contact-shadow.d.ts +21 -0
  26. package/dist/modules/lighting/pbr-contact-shadow/pbr-contact-shadow.d.ts.map +1 -0
  27. package/dist/modules/lighting/pbr-contact-shadow/pbr-contact-shadow.js +61 -0
  28. package/dist/modules/lighting/pbr-contact-shadow/pbr-contact-shadow.js.map +1 -0
  29. package/dist/modules/lighting/pbr-material/pbr-material-glsl.cjs +33 -11
  30. package/dist/modules/lighting/pbr-material/pbr-material-glsl.d.ts +2 -2
  31. package/dist/modules/lighting/pbr-material/pbr-material-glsl.d.ts.map +1 -1
  32. package/dist/modules/lighting/pbr-material/pbr-material-glsl.js +33 -11
  33. package/dist/modules/lighting/pbr-material/pbr-material-glsl.js.map +1 -1
  34. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.cjs +33 -11
  35. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.d.ts +1 -1
  36. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.d.ts.map +1 -1
  37. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js +33 -11
  38. package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js.map +1 -1
  39. package/dist/modules/lighting/pbr-material/pbr-material.d.ts +3 -3
  40. package/dist/modules/lighting/pbr-shadow/pbr-shadow.cjs +97 -0
  41. package/dist/modules/lighting/pbr-shadow/pbr-shadow.d.ts +15 -0
  42. package/dist/modules/lighting/pbr-shadow/pbr-shadow.d.ts.map +1 -0
  43. package/dist/modules/lighting/pbr-shadow/pbr-shadow.js +69 -0
  44. package/dist/modules/lighting/pbr-shadow/pbr-shadow.js.map +1 -0
  45. package/dist/modules/lighting/pbr-surface/pbr-surface.cjs +114 -0
  46. package/dist/modules/lighting/pbr-surface/pbr-surface.d.ts +15 -0
  47. package/dist/modules/lighting/pbr-surface/pbr-surface.d.ts.map +1 -0
  48. package/dist/modules/lighting/pbr-surface/pbr-surface.js +88 -0
  49. package/dist/modules/lighting/pbr-surface/pbr-surface.js.map +1 -0
  50. package/dist/modules/lighting/prefiltered-environment/prefiltered-environment.cjs +379 -0
  51. package/dist/modules/lighting/prefiltered-environment/prefiltered-environment.d.ts +41 -0
  52. package/dist/modules/lighting/prefiltered-environment/prefiltered-environment.d.ts.map +1 -0
  53. package/dist/modules/lighting/prefiltered-environment/prefiltered-environment.js +345 -0
  54. package/dist/modules/lighting/prefiltered-environment/prefiltered-environment.js.map +1 -0
  55. package/dist/modules/lighting/shadow/shadow-glsl.cjs +228 -0
  56. package/dist/modules/lighting/shadow/shadow-glsl.d.ts +3 -0
  57. package/dist/modules/lighting/shadow/shadow-glsl.d.ts.map +1 -0
  58. package/dist/modules/lighting/shadow/shadow-glsl.js +204 -0
  59. package/dist/modules/lighting/shadow/shadow-glsl.js.map +1 -0
  60. package/dist/modules/lighting/shadow/shadow-types.cjs +15 -0
  61. package/dist/modules/lighting/shadow/shadow-types.d.ts +63 -0
  62. package/dist/modules/lighting/shadow/shadow-types.d.ts.map +1 -0
  63. package/dist/modules/lighting/shadow/shadow-types.js +5 -0
  64. package/dist/modules/lighting/shadow/shadow-types.js.map +1 -0
  65. package/dist/modules/lighting/shadow/shadow.cjs +458 -0
  66. package/dist/modules/lighting/shadow/shadow.d.ts +117 -0
  67. package/dist/modules/lighting/shadow/shadow.d.ts.map +1 -0
  68. package/dist/modules/lighting/shadow/shadow.js +450 -0
  69. package/dist/modules/lighting/shadow/shadow.js.map +1 -0
  70. package/dist/modules/lighting/unlit-material/unlit-material.cjs +60 -0
  71. package/dist/modules/lighting/unlit-material/unlit-material.d.ts +9 -0
  72. package/dist/modules/lighting/unlit-material/unlit-material.d.ts.map +1 -0
  73. package/dist/modules/lighting/unlit-material/unlit-material.js +40 -0
  74. package/dist/modules/lighting/unlit-material/unlit-material.js.map +1 -0
  75. package/package.json +3 -3
  76. package/src/index.ts +48 -0
  77. package/src/modules/lighting/clustered-light-grid/clustered-light-grid.ts +17 -0
  78. package/src/modules/lighting/contact-shadow/contact-shadow.ts +365 -0
  79. package/src/modules/lighting/pbr-ambient-occlusion/pbr-ambient-occlusion.ts +78 -0
  80. package/src/modules/lighting/pbr-contact-shadow/pbr-contact-shadow.ts +78 -0
  81. package/src/modules/lighting/pbr-material/pbr-material-glsl.ts +33 -11
  82. package/src/modules/lighting/pbr-material/pbr-material-wgsl.ts +33 -11
  83. package/src/modules/lighting/pbr-shadow/pbr-shadow.ts +85 -0
  84. package/src/modules/lighting/pbr-surface/pbr-surface.ts +103 -0
  85. package/src/modules/lighting/prefiltered-environment/prefiltered-environment.ts +370 -0
  86. package/src/modules/lighting/shadow/shadow-glsl.ts +204 -0
  87. package/src/modules/lighting/shadow/shadow-types.ts +68 -0
  88. package/src/modules/lighting/shadow/shadow.ts +536 -0
  89. package/src/modules/lighting/unlit-material/unlit-material.ts +44 -0
@@ -0,0 +1,97 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var pbr_shadow_exports = {};
19
+ __export(pbr_shadow_exports, {
20
+ pbrShadow: () => pbrShadow
21
+ });
22
+ module.exports = __toCommonJS(pbr_shadow_exports);
23
+ var import_pbr_material = require("../pbr-material/pbr-material.cjs");
24
+ var import_shadow = require("../shadow/shadow.cjs");
25
+ const pbrShadow = {
26
+ name: "pbrShadow",
27
+ dependencies: [import_pbr_material.pbrMaterial, import_shadow.shadow],
28
+ bindingLayout: [{ name: "pbrShadow", group: 0 }],
29
+ uniformTypes: { viewMatrix: "mat4x4<f32>", enabled: "i32" },
30
+ defaultUniforms: {
31
+ viewMatrix: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1],
32
+ enabled: 1
33
+ },
34
+ getUniforms(properties = {}) {
35
+ return {
36
+ ...properties.viewMatrix ? { viewMatrix: properties.viewMatrix } : {},
37
+ ...properties.enabled === void 0 ? {} : { enabled: Number(properties.enabled) }
38
+ };
39
+ },
40
+ source: (
41
+ /* wgsl */
42
+ `
43
+ struct PBRShadowUniforms {
44
+ viewMatrix: mat4x4f,
45
+ enabled: i32,
46
+ };
47
+ @group(0) @binding(auto) var<uniform> pbrShadow: PBRShadowUniforms;
48
+ fn pbrShadow_filterColorWithDirectionalContact(vertexColor: vec4f, worldPosition: vec3f, worldNormal: vec3f, contactVisibility: f32) -> vec4f {
49
+ var directionalVisibility = 1.0;
50
+ var pointVisibility = vec4f(1.0);
51
+ var spotVisibility = vec4f(1.0);
52
+ if (pbrShadow.enabled != 0) {
53
+ let normal = normalize(worldNormal);
54
+ let viewDepth = -(pbrShadow.viewMatrix * vec4f(worldPosition, 1.0)).z;
55
+ directionalVisibility = shadow_getDirectionalFactor(worldPosition, normal, viewDepth);
56
+ for (var index = 0; index < 4; index++) {
57
+ pointVisibility[index] = shadow_getPointFactor(index, worldPosition, normal);
58
+ spotVisibility[index] = shadow_getSpotFactor(index, worldPosition, normal);
59
+ }
60
+ }
61
+ return pbr_filterColorWithShadows(vertexColor, min(directionalVisibility, contactVisibility), pointVisibility, spotVisibility);
62
+ }
63
+ fn pbrShadow_filterColor(vertexColor: vec4f, worldPosition: vec3f, worldNormal: vec3f) -> vec4f {
64
+ return pbrShadow_filterColorWithDirectionalContact(vertexColor, worldPosition, worldNormal, 1.0);
65
+ }`
66
+ ),
67
+ fs: (
68
+ /* glsl */
69
+ `
70
+ layout(std140) uniform pbrShadowUniforms {
71
+ mat4 viewMatrix;
72
+ int enabled;
73
+ } pbrShadow;
74
+ vec4 pbrShadow_filterColorWithDirectionalContact(vec4 vertexColor, vec3 worldPosition, vec3 worldNormal, float contactVisibility) {
75
+ float directionalVisibility = 1.0;
76
+ vec4 pointVisibility = vec4(1.0);
77
+ vec4 spotVisibility = vec4(1.0);
78
+ if (pbrShadow.enabled != 0) {
79
+ vec3 normal = normalize(worldNormal);
80
+ float viewDepth = -(pbrShadow.viewMatrix * vec4(worldPosition, 1.0)).z;
81
+ directionalVisibility = shadow_getDirectionalFactor(worldPosition, normal, viewDepth);
82
+ for (int index = 0; index < 4; index++) {
83
+ pointVisibility[index] = shadow_getPointFactor(index, worldPosition, normal);
84
+ spotVisibility[index] = shadow_getSpotFactor(index, worldPosition, normal);
85
+ }
86
+ }
87
+ return pbr_filterColorWithShadows(vertexColor, min(directionalVisibility, contactVisibility), pointVisibility, spotVisibility);
88
+ }
89
+ vec4 pbrShadow_filterColor(vec4 vertexColor, vec3 worldPosition, vec3 worldNormal) {
90
+ return pbrShadow_filterColorWithDirectionalContact(vertexColor, worldPosition, worldNormal, 1.0);
91
+ }`
92
+ )
93
+ };
94
+ // Annotate the CommonJS export names for ESM import in node:
95
+ 0 && (module.exports = {
96
+ pbrShadow
97
+ });
@@ -0,0 +1,15 @@
1
+ import type { NumberArray16 } from '@math.gl/core';
2
+ import type { ShaderModule } from "../../../lib/shader-module/shader-module.js";
3
+ export type PBRShadowProps = {
4
+ /** Receiver camera view matrix, used for directional cascade selection. */
5
+ viewMatrix?: Readonly<NumberArray16>;
6
+ /** Toggle receiving while retaining allocated maps and bindings. Defaults to true. */
7
+ enabled?: boolean;
8
+ };
9
+ export type PBRShadowUniforms = {
10
+ viewMatrix: Readonly<NumberArray16>;
11
+ enabled: number;
12
+ };
13
+ /** Applies shadow visibility to matching direct-light slots in the canonical PBR shader. */
14
+ export declare const pbrShadow: ShaderModule<PBRShadowProps, PBRShadowUniforms>;
15
+ //# sourceMappingURL=pbr-shadow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pbr-shadow.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/pbr-shadow/pbr-shadow.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAC,YAAY,EAAC,oDAAiD;AAI3E,MAAM,MAAM,cAAc,GAAG;IAC3B,2EAA2E;IAC3E,UAAU,CAAC,EAAE,QAAQ,CAAC,aAAa,CAAC,CAAC;IACrC,sFAAsF;IACtF,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,UAAU,EAAE,QAAQ,CAAC,aAAa,CAAC,CAAC;IACpC,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,4FAA4F;AAC5F,eAAO,MAAM,SAAS,EAAE,YAAY,CAAC,cAAc,EAAE,iBAAiB,CA+DrE,CAAC"}
@@ -0,0 +1,69 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
3
+ import { pbrMaterial } from "../pbr-material/pbr-material.js";
4
+ import { shadow } from "../shadow/shadow.js";
5
+ /** Applies shadow visibility to matching direct-light slots in the canonical PBR shader. */
6
+ export const pbrShadow = {
7
+ name: 'pbrShadow',
8
+ dependencies: [pbrMaterial, shadow],
9
+ bindingLayout: [{ name: 'pbrShadow', group: 0 }],
10
+ uniformTypes: { viewMatrix: 'mat4x4<f32>', enabled: 'i32' },
11
+ defaultUniforms: {
12
+ viewMatrix: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1],
13
+ enabled: 1
14
+ },
15
+ getUniforms(properties = {}) {
16
+ return {
17
+ ...(properties.viewMatrix ? { viewMatrix: properties.viewMatrix } : {}),
18
+ ...(properties.enabled === undefined ? {} : { enabled: Number(properties.enabled) })
19
+ };
20
+ },
21
+ source: /* wgsl */ `
22
+ struct PBRShadowUniforms {
23
+ viewMatrix: mat4x4f,
24
+ enabled: i32,
25
+ };
26
+ @group(0) @binding(auto) var<uniform> pbrShadow: PBRShadowUniforms;
27
+ fn pbrShadow_filterColorWithDirectionalContact(vertexColor: vec4f, worldPosition: vec3f, worldNormal: vec3f, contactVisibility: f32) -> vec4f {
28
+ var directionalVisibility = 1.0;
29
+ var pointVisibility = vec4f(1.0);
30
+ var spotVisibility = vec4f(1.0);
31
+ if (pbrShadow.enabled != 0) {
32
+ let normal = normalize(worldNormal);
33
+ let viewDepth = -(pbrShadow.viewMatrix * vec4f(worldPosition, 1.0)).z;
34
+ directionalVisibility = shadow_getDirectionalFactor(worldPosition, normal, viewDepth);
35
+ for (var index = 0; index < 4; index++) {
36
+ pointVisibility[index] = shadow_getPointFactor(index, worldPosition, normal);
37
+ spotVisibility[index] = shadow_getSpotFactor(index, worldPosition, normal);
38
+ }
39
+ }
40
+ return pbr_filterColorWithShadows(vertexColor, min(directionalVisibility, contactVisibility), pointVisibility, spotVisibility);
41
+ }
42
+ fn pbrShadow_filterColor(vertexColor: vec4f, worldPosition: vec3f, worldNormal: vec3f) -> vec4f {
43
+ return pbrShadow_filterColorWithDirectionalContact(vertexColor, worldPosition, worldNormal, 1.0);
44
+ }`,
45
+ fs: /* glsl */ `
46
+ layout(std140) uniform pbrShadowUniforms {
47
+ mat4 viewMatrix;
48
+ int enabled;
49
+ } pbrShadow;
50
+ vec4 pbrShadow_filterColorWithDirectionalContact(vec4 vertexColor, vec3 worldPosition, vec3 worldNormal, float contactVisibility) {
51
+ float directionalVisibility = 1.0;
52
+ vec4 pointVisibility = vec4(1.0);
53
+ vec4 spotVisibility = vec4(1.0);
54
+ if (pbrShadow.enabled != 0) {
55
+ vec3 normal = normalize(worldNormal);
56
+ float viewDepth = -(pbrShadow.viewMatrix * vec4(worldPosition, 1.0)).z;
57
+ directionalVisibility = shadow_getDirectionalFactor(worldPosition, normal, viewDepth);
58
+ for (int index = 0; index < 4; index++) {
59
+ pointVisibility[index] = shadow_getPointFactor(index, worldPosition, normal);
60
+ spotVisibility[index] = shadow_getSpotFactor(index, worldPosition, normal);
61
+ }
62
+ }
63
+ return pbr_filterColorWithShadows(vertexColor, min(directionalVisibility, contactVisibility), pointVisibility, spotVisibility);
64
+ }
65
+ vec4 pbrShadow_filterColor(vec4 vertexColor, vec3 worldPosition, vec3 worldNormal) {
66
+ return pbrShadow_filterColorWithDirectionalContact(vertexColor, worldPosition, worldNormal, 1.0);
67
+ }`
68
+ };
69
+ //# sourceMappingURL=pbr-shadow.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pbr-shadow.js","sourceRoot":"","sources":["../../../../src/modules/lighting/pbr-shadow/pbr-shadow.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,4DAA4D;AAI5D,OAAO,EAAC,WAAW,EAAC,wCAAqC;AACzD,OAAO,EAAC,MAAM,EAAC,4BAAyB;AAcxC,4FAA4F;AAC5F,MAAM,CAAC,MAAM,SAAS,GAAoD;IACxE,IAAI,EAAE,WAAW;IACjB,YAAY,EAAE,CAAC,WAAW,EAAE,MAAM,CAAC;IACnC,aAAa,EAAE,CAAC,EAAC,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC,EAAC,CAAC;IAC9C,YAAY,EAAE,EAAC,UAAU,EAAE,aAAa,EAAE,OAAO,EAAE,KAAK,EAAC;IACzD,eAAe,EAAE;QACf,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QAC5D,OAAO,EAAE,CAAC;KACX;IACD,WAAW,CAAC,UAAU,GAAG,EAAE;QACzB,OAAO;YACL,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,EAAC,UAAU,EAAE,UAAU,CAAC,UAAU,EAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YACrE,GAAG,CAAC,UAAU,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAC,OAAO,EAAE,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,EAAC,CAAC;SACnF,CAAC;IACJ,CAAC;IACD,MAAM,EAAE,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;EAuBnB;IAEA,EAAE,EAAE,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;EAsBf;CACD,CAAC"}
@@ -0,0 +1,114 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var pbr_surface_exports = {};
19
+ __export(pbr_surface_exports, {
20
+ pbrSurface: () => pbrSurface
21
+ });
22
+ module.exports = __toCommonJS(pbr_surface_exports);
23
+ var import_pbr_material = require("../pbr-material/pbr-material.cjs");
24
+ const pbrSurface = {
25
+ name: "pbrSurface",
26
+ dependencies: [import_pbr_material.pbrMaterial],
27
+ bindingLayout: [{ name: "pbrSurface", group: 0 }],
28
+ uniformTypes: { viewMatrix: "mat4x4<f32>", useMaterialNormals: "i32" },
29
+ defaultUniforms: {
30
+ viewMatrix: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1],
31
+ useMaterialNormals: 0
32
+ },
33
+ getUniforms(properties = {}) {
34
+ return {
35
+ ...properties.viewMatrix ? { viewMatrix: properties.viewMatrix } : {},
36
+ ...properties.useMaterialNormals === void 0 ? {} : { useMaterialNormals: Number(properties.useMaterialNormals) }
37
+ };
38
+ },
39
+ source: (
40
+ /* wgsl */
41
+ `
42
+ struct PBRSurfaceUniforms {
43
+ viewMatrix: mat4x4f,
44
+ useMaterialNormals: i32,
45
+ };
46
+ @group(0) @binding(auto) var<uniform> pbrSurface: PBRSurfaceUniforms;
47
+ fn pbrSurface_getColor() -> vec4f {
48
+ #ifdef HAS_NORMALS
49
+ var normal = normalize(fragmentInputs.pbr_vNormal);
50
+ #ifdef DOUBLE_SIDED
51
+ if (!pbr_frontFacing) {normal = -normal;}
52
+ #endif
53
+ #else
54
+ var normal = normalize(cross(dpdy(fragmentInputs.pbr_vPosition), dpdx(fragmentInputs.pbr_vPosition)));
55
+ #endif
56
+ #ifdef HAS_NORMALMAP
57
+ if (pbrSurface.useMaterialNormals != 0) {
58
+ let coordinates = getMaterialUV(pbrMaterial.normalUVSet, pbrMaterial.normalUVTransform);
59
+ normal = getNormal(getTBN(coordinates), coordinates);
60
+ }
61
+ #else
62
+ #ifdef HAS_BUMPMAP
63
+ if (pbrSurface.useMaterialNormals != 0) {
64
+ let coordinates = getMaterialUV(pbrMaterial.normalUVSet, pbrMaterial.normalUVTransform);
65
+ normal = getNormal(getTBN(coordinates), coordinates);
66
+ }
67
+ #endif
68
+ #endif
69
+ let viewNormal = normalize((pbrSurface.viewMatrix * vec4f(normal, 0.0)).xyz);
70
+ return vec4f(viewNormal * 0.5 + vec3f(0.5), 1.0);
71
+ }`
72
+ ),
73
+ fs: (
74
+ /* glsl */
75
+ `
76
+ layout(std140) uniform pbrSurfaceUniforms {
77
+ mat4 viewMatrix;
78
+ int useMaterialNormals;
79
+ } pbrSurface;
80
+ vec4 pbrSurface_getColor() {
81
+ #ifdef HAS_NORMALS
82
+ #ifdef HAS_TANGENTS
83
+ vec3 normal = normalize(pbr_vTBN[2]);
84
+ #else
85
+ vec3 normal = normalize(pbr_vNormal);
86
+ #endif
87
+ #ifdef DOUBLE_SIDED
88
+ if (!gl_FrontFacing) normal = -normal;
89
+ #endif
90
+ #else
91
+ vec3 normal = normalize(cross(dFdx(pbr_vPosition), dFdy(pbr_vPosition)));
92
+ #endif
93
+ #ifdef HAS_NORMALMAP
94
+ if (pbrSurface.useMaterialNormals != 0) {
95
+ vec2 coordinates = getMaterialUV(pbrMaterial.normalUVSet, pbrMaterial.normalUVTransform);
96
+ normal = getNormal(getTBN(coordinates), coordinates);
97
+ }
98
+ #else
99
+ #ifdef HAS_BUMPMAP
100
+ if (pbrSurface.useMaterialNormals != 0) {
101
+ vec2 coordinates = getMaterialUV(pbrMaterial.normalUVSet, pbrMaterial.normalUVTransform);
102
+ normal = getNormal(getTBN(coordinates), coordinates);
103
+ }
104
+ #endif
105
+ #endif
106
+ vec3 viewNormal = normalize((pbrSurface.viewMatrix * vec4(normal, 0.0)).xyz);
107
+ return vec4(viewNormal * 0.5 + 0.5, 1.0);
108
+ }`
109
+ )
110
+ };
111
+ // Annotate the CommonJS export names for ESM import in node:
112
+ 0 && (module.exports = {
113
+ pbrSurface
114
+ });
@@ -0,0 +1,15 @@
1
+ import type { NumberArray16 } from '@math.gl/core';
2
+ import type { ShaderModule } from "../../../lib/shader-module/shader-module.js";
3
+ export type PBRSurfaceProps = {
4
+ /** Rigid world-to-view camera transform. Defaults to identity. */
5
+ viewMatrix?: Readonly<NumberArray16>;
6
+ /** Include canonical normal/bump maps instead of geometric normals. Defaults to false. */
7
+ useMaterialNormals?: boolean;
8
+ };
9
+ export type PBRSurfaceUniforms = {
10
+ viewMatrix: Readonly<NumberArray16>;
11
+ useMaterialNormals: number;
12
+ };
13
+ /** Encodes view-space PBR normals in RGB; alpha one marks covered surface pixels. */
14
+ export declare const pbrSurface: ShaderModule<PBRSurfaceProps, PBRSurfaceUniforms>;
15
+ //# sourceMappingURL=pbr-surface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pbr-surface.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/pbr-surface/pbr-surface.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAC,YAAY,EAAC,oDAAiD;AAG3E,MAAM,MAAM,eAAe,GAAG;IAC5B,kEAAkE;IAClE,UAAU,CAAC,EAAE,QAAQ,CAAC,aAAa,CAAC,CAAC;IACrC,0FAA0F;IAC1F,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,UAAU,EAAE,QAAQ,CAAC,aAAa,CAAC,CAAC;IACpC,kBAAkB,EAAE,MAAM,CAAC;CAC5B,CAAC;AAEF,qFAAqF;AACrF,eAAO,MAAM,UAAU,EAAE,YAAY,CAAC,eAAe,EAAE,kBAAkB,CAkFxE,CAAC"}
@@ -0,0 +1,88 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
3
+ import { pbrMaterial } from "../pbr-material/pbr-material.js";
4
+ /** Encodes view-space PBR normals in RGB; alpha one marks covered surface pixels. */
5
+ export const pbrSurface = {
6
+ name: 'pbrSurface',
7
+ dependencies: [pbrMaterial],
8
+ bindingLayout: [{ name: 'pbrSurface', group: 0 }],
9
+ uniformTypes: { viewMatrix: 'mat4x4<f32>', useMaterialNormals: 'i32' },
10
+ defaultUniforms: {
11
+ viewMatrix: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1],
12
+ useMaterialNormals: 0
13
+ },
14
+ getUniforms(properties = {}) {
15
+ return {
16
+ ...(properties.viewMatrix ? { viewMatrix: properties.viewMatrix } : {}),
17
+ ...(properties.useMaterialNormals === undefined
18
+ ? {}
19
+ : { useMaterialNormals: Number(properties.useMaterialNormals) })
20
+ };
21
+ },
22
+ source: /* wgsl */ `
23
+ struct PBRSurfaceUniforms {
24
+ viewMatrix: mat4x4f,
25
+ useMaterialNormals: i32,
26
+ };
27
+ @group(0) @binding(auto) var<uniform> pbrSurface: PBRSurfaceUniforms;
28
+ fn pbrSurface_getColor() -> vec4f {
29
+ #ifdef HAS_NORMALS
30
+ var normal = normalize(fragmentInputs.pbr_vNormal);
31
+ #ifdef DOUBLE_SIDED
32
+ if (!pbr_frontFacing) {normal = -normal;}
33
+ #endif
34
+ #else
35
+ var normal = normalize(cross(dpdy(fragmentInputs.pbr_vPosition), dpdx(fragmentInputs.pbr_vPosition)));
36
+ #endif
37
+ #ifdef HAS_NORMALMAP
38
+ if (pbrSurface.useMaterialNormals != 0) {
39
+ let coordinates = getMaterialUV(pbrMaterial.normalUVSet, pbrMaterial.normalUVTransform);
40
+ normal = getNormal(getTBN(coordinates), coordinates);
41
+ }
42
+ #else
43
+ #ifdef HAS_BUMPMAP
44
+ if (pbrSurface.useMaterialNormals != 0) {
45
+ let coordinates = getMaterialUV(pbrMaterial.normalUVSet, pbrMaterial.normalUVTransform);
46
+ normal = getNormal(getTBN(coordinates), coordinates);
47
+ }
48
+ #endif
49
+ #endif
50
+ let viewNormal = normalize((pbrSurface.viewMatrix * vec4f(normal, 0.0)).xyz);
51
+ return vec4f(viewNormal * 0.5 + vec3f(0.5), 1.0);
52
+ }`,
53
+ fs: /* glsl */ `
54
+ layout(std140) uniform pbrSurfaceUniforms {
55
+ mat4 viewMatrix;
56
+ int useMaterialNormals;
57
+ } pbrSurface;
58
+ vec4 pbrSurface_getColor() {
59
+ #ifdef HAS_NORMALS
60
+ #ifdef HAS_TANGENTS
61
+ vec3 normal = normalize(pbr_vTBN[2]);
62
+ #else
63
+ vec3 normal = normalize(pbr_vNormal);
64
+ #endif
65
+ #ifdef DOUBLE_SIDED
66
+ if (!gl_FrontFacing) normal = -normal;
67
+ #endif
68
+ #else
69
+ vec3 normal = normalize(cross(dFdx(pbr_vPosition), dFdy(pbr_vPosition)));
70
+ #endif
71
+ #ifdef HAS_NORMALMAP
72
+ if (pbrSurface.useMaterialNormals != 0) {
73
+ vec2 coordinates = getMaterialUV(pbrMaterial.normalUVSet, pbrMaterial.normalUVTransform);
74
+ normal = getNormal(getTBN(coordinates), coordinates);
75
+ }
76
+ #else
77
+ #ifdef HAS_BUMPMAP
78
+ if (pbrSurface.useMaterialNormals != 0) {
79
+ vec2 coordinates = getMaterialUV(pbrMaterial.normalUVSet, pbrMaterial.normalUVTransform);
80
+ normal = getNormal(getTBN(coordinates), coordinates);
81
+ }
82
+ #endif
83
+ #endif
84
+ vec3 viewNormal = normalize((pbrSurface.viewMatrix * vec4(normal, 0.0)).xyz);
85
+ return vec4(viewNormal * 0.5 + 0.5, 1.0);
86
+ }`
87
+ };
88
+ //# sourceMappingURL=pbr-surface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pbr-surface.js","sourceRoot":"","sources":["../../../../src/modules/lighting/pbr-surface/pbr-surface.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,4DAA4D;AAI5D,OAAO,EAAC,WAAW,EAAC,wCAAqC;AAczD,qFAAqF;AACrF,MAAM,CAAC,MAAM,UAAU,GAAsD;IAC3E,IAAI,EAAE,YAAY;IAClB,YAAY,EAAE,CAAC,WAAW,CAAC;IAC3B,aAAa,EAAE,CAAC,EAAC,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,CAAC,EAAC,CAAC;IAC/C,YAAY,EAAE,EAAC,UAAU,EAAE,aAAa,EAAE,kBAAkB,EAAE,KAAK,EAAC;IACpE,eAAe,EAAE;QACf,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QAC5D,kBAAkB,EAAE,CAAC;KACtB;IACD,WAAW,CAAC,UAAU,GAAG,EAAE;QACzB,OAAO;YACL,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,EAAC,UAAU,EAAE,UAAU,CAAC,UAAU,EAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YACrE,GAAG,CAAC,UAAU,CAAC,kBAAkB,KAAK,SAAS;gBAC7C,CAAC,CAAC,EAAE;gBACJ,CAAC,CAAC,EAAC,kBAAkB,EAAE,MAAM,CAAC,UAAU,CAAC,kBAAkB,CAAC,EAAC,CAAC;SACjE,CAAC;IACJ,CAAC;IACD,MAAM,EAAE,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8BnB;IACA,EAAE,EAAE,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiCf;CACD,CAAC"}