@luma.gl/shadertools 9.1.0-alpha.1 → 9.1.0-alpha.10
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 +816 -483
- package/dist/dist.min.js +2325 -1622
- package/dist/index.cjs +2669 -1808
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +29 -28
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -12
- package/dist/lib/glsl-utils/shader-utils.d.ts.map +1 -1
- package/dist/lib/glsl-utils/shader-utils.js +2 -3
- package/dist/lib/shader-assembler.d.ts +3 -4
- package/dist/lib/shader-assembler.d.ts.map +1 -1
- package/dist/lib/shader-assembler.js +3 -2
- package/dist/lib/shader-assembly/assemble-shaders.d.ts +4 -3
- package/dist/lib/shader-assembly/assemble-shaders.d.ts.map +1 -1
- package/dist/lib/shader-assembly/assemble-shaders.js +43 -16
- package/dist/lib/shader-assembly/platform-defines.d.ts.map +1 -1
- package/dist/lib/shader-assembly/platform-defines.js +14 -6
- package/dist/lib/shader-module/shader-module-dependencies.d.ts +53 -0
- package/dist/lib/shader-module/shader-module-dependencies.d.ts.map +1 -0
- package/dist/lib/{shader-assembly/resolve-modules.js → shader-module/shader-module-dependencies.js} +38 -14
- package/dist/lib/shader-module/shader-module.d.ts +29 -11
- package/dist/lib/shader-module/shader-module.d.ts.map +1 -1
- package/dist/lib/shader-module/shader-module.js +76 -6
- package/dist/lib/shader-module/shader-pass.d.ts +3 -2
- package/dist/lib/shader-module/shader-pass.d.ts.map +1 -1
- package/dist/module-injectors.d.ts +2 -2
- package/dist/module-injectors.d.ts.map +1 -1
- package/dist/module-injectors.js +13 -10
- package/dist/modules/engine/geometry/geometry.d.ts.map +1 -1
- package/dist/modules/engine/geometry/geometry.js +12 -8
- package/dist/modules/engine/picking/picking.d.ts +4 -4
- package/dist/modules/engine/picking/picking.d.ts.map +1 -1
- package/dist/modules/engine/picking/picking.js +103 -66
- package/dist/modules/engine/project/project.d.ts +2 -2
- package/dist/modules/engine/project/project.d.ts.map +1 -1
- package/dist/modules/engine/project/project.js +36 -22
- package/dist/modules/engine/transform/transform.d.ts.map +1 -1
- package/dist/modules/engine/transform/transform.js +28 -16
- package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts +9 -7
- package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts.map +1 -1
- package/dist/modules/lighting/gouraud-material/gouraud-material.js +2 -0
- package/dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.d.ts +2 -2
- package/dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.js +79 -53
- package/dist/modules/lighting/lights/lighting-uniforms-glsl.d.ts +1 -1
- package/dist/modules/lighting/lights/lighting-uniforms-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting-uniforms-glsl.js +38 -23
- package/dist/modules/lighting/lights/lighting.d.ts +4 -4
- package/dist/modules/lighting/lights/lighting.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting.js +2 -2
- package/dist/modules/lighting/no-material/dirlight.d.ts +4 -4
- package/dist/modules/lighting/no-material/dirlight.d.ts.map +1 -1
- package/dist/modules/lighting/no-material/dirlight.js +12 -9
- package/dist/modules/lighting/pbr-material/pbr-fragment-glsl.d.ts +1 -1
- package/dist/modules/lighting/pbr-material/pbr-fragment-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-fragment-glsl.js +304 -181
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts +71 -69
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material.js +4 -2
- package/dist/modules/lighting/pbr-material/pbr-uniforms-glsl.d.ts +1 -1
- package/dist/modules/lighting/pbr-material/pbr-uniforms-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-uniforms-glsl.js +38 -20
- package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.d.ts +1 -1
- package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-vertex-glsl.js +21 -16
- package/dist/modules/lighting/phong-material/phong-material.d.ts +12 -12
- package/dist/modules/lighting/phong-material/phong-material.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-material.js +3 -3
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts +2 -2
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.js +82 -54
- package/dist/modules/math/fp32/fp32.d.ts.map +1 -1
- package/dist/modules/math/fp32/fp32.js +127 -100
- package/dist/modules/math/random/random.d.ts +1 -1
- package/dist/modules/math/random/random.d.ts.map +1 -1
- package/dist/modules/math/random/random.js +3 -3
- package/dist/modules/module-injectors.d.ts +2 -2
- package/dist/modules/module-injectors.d.ts.map +1 -1
- package/dist/modules/module-injectors.js +13 -10
- package/dist/modules/postprocessing/image-adjust-filters/brightnesscontrast.d.ts +4 -1
- package/dist/modules/postprocessing/image-adjust-filters/brightnesscontrast.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-adjust-filters/brightnesscontrast.js +16 -12
- package/dist/modules/postprocessing/image-adjust-filters/denoise.d.ts +4 -1
- package/dist/modules/postprocessing/image-adjust-filters/denoise.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-adjust-filters/denoise.js +21 -17
- package/dist/modules/postprocessing/image-adjust-filters/huesaturation.d.ts +5 -2
- package/dist/modules/postprocessing/image-adjust-filters/huesaturation.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-adjust-filters/huesaturation.js +29 -22
- package/dist/modules/postprocessing/image-adjust-filters/noise.d.ts +4 -1
- package/dist/modules/postprocessing/image-adjust-filters/noise.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-adjust-filters/noise.js +14 -10
- package/dist/modules/postprocessing/image-adjust-filters/sepia.d.ts +4 -1
- package/dist/modules/postprocessing/image-adjust-filters/sepia.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-adjust-filters/sepia.js +17 -12
- package/dist/modules/postprocessing/image-adjust-filters/vibrance.d.ts +4 -1
- package/dist/modules/postprocessing/image-adjust-filters/vibrance.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-adjust-filters/vibrance.js +12 -9
- package/dist/modules/postprocessing/image-adjust-filters/vignette.d.ts +4 -1
- package/dist/modules/postprocessing/image-adjust-filters/vignette.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-adjust-filters/vignette.js +13 -10
- package/dist/modules/postprocessing/image-blur-filters/tiltshift.d.ts +5 -2
- package/dist/modules/postprocessing/image-blur-filters/tiltshift.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-blur-filters/tiltshift.js +40 -26
- package/dist/modules/postprocessing/image-blur-filters/triangleblur.d.ts +5 -2
- package/dist/modules/postprocessing/image-blur-filters/triangleblur.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-blur-filters/triangleblur.js +32 -19
- package/dist/modules/postprocessing/image-blur-filters/zoomblur.d.ts +4 -1
- package/dist/modules/postprocessing/image-blur-filters/zoomblur.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-blur-filters/zoomblur.js +2 -0
- package/dist/modules/postprocessing/image-fun-filters/colorhalftone.d.ts +4 -1
- package/dist/modules/postprocessing/image-fun-filters/colorhalftone.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-fun-filters/colorhalftone.js +31 -27
- package/dist/modules/postprocessing/image-fun-filters/dotscreen.d.ts +4 -1
- package/dist/modules/postprocessing/image-fun-filters/dotscreen.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-fun-filters/dotscreen.js +19 -15
- package/dist/modules/postprocessing/image-fun-filters/edgework.d.ts +8 -5
- package/dist/modules/postprocessing/image-fun-filters/edgework.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-fun-filters/edgework.js +53 -42
- package/dist/modules/postprocessing/image-fun-filters/hexagonalpixelate.d.ts +4 -1
- package/dist/modules/postprocessing/image-fun-filters/hexagonalpixelate.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-fun-filters/hexagonalpixelate.js +41 -33
- package/dist/modules/postprocessing/image-fun-filters/ink.d.ts +4 -1
- package/dist/modules/postprocessing/image-fun-filters/ink.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-fun-filters/ink.js +27 -25
- package/dist/modules/postprocessing/image-fun-filters/magnify.d.ts +2 -1
- package/dist/modules/postprocessing/image-fun-filters/magnify.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-fun-filters/magnify.js +17 -16
- package/dist/modules/postprocessing/image-warp-filters/bulgepinch.d.ts +5 -2
- package/dist/modules/postprocessing/image-warp-filters/bulgepinch.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-warp-filters/bulgepinch.js +24 -20
- package/dist/modules/postprocessing/image-warp-filters/swirl.d.ts +5 -2
- package/dist/modules/postprocessing/image-warp-filters/swirl.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-warp-filters/swirl.js +26 -22
- package/dist/modules/postprocessing/image-warp-filters/warp.d.ts +2 -1
- package/dist/modules/postprocessing/image-warp-filters/warp.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-warp-filters/warp.js +9 -8
- package/dist/modules-webgl1/geometry/geometry.d.ts.map +1 -1
- package/dist/modules-webgl1/geometry/geometry.js +12 -8
- package/dist/modules-webgl1/lighting/dirlight/dirlight.d.ts.map +1 -1
- package/dist/modules-webgl1/lighting/dirlight/dirlight.js +8 -5
- package/dist/modules-webgl1/lighting/lights/lights-glsl.d.ts +1 -1
- package/dist/modules-webgl1/lighting/lights/lights-glsl.d.ts.map +1 -1
- package/dist/modules-webgl1/lighting/lights/lights-glsl.js +19 -11
- package/dist/modules-webgl1/lighting/pbr/pbr-fragment-glsl.d.ts +1 -1
- package/dist/modules-webgl1/lighting/pbr/pbr-fragment-glsl.d.ts.map +1 -1
- package/dist/modules-webgl1/lighting/pbr/pbr-fragment-glsl.js +268 -157
- package/dist/modules-webgl1/lighting/pbr/pbr-vertex-glsl.d.ts +1 -1
- package/dist/modules-webgl1/lighting/pbr/pbr-vertex-glsl.d.ts.map +1 -1
- package/dist/modules-webgl1/lighting/pbr/pbr-vertex-glsl.js +16 -12
- package/dist/modules-webgl1/lighting/phong-lighting/phong-lighting-glsl.d.ts +1 -1
- package/dist/modules-webgl1/lighting/phong-lighting/phong-lighting-glsl.d.ts.map +1 -1
- package/dist/modules-webgl1/lighting/phong-lighting/phong-lighting-glsl.js +64 -55
- package/dist/modules-webgl1/math/fp64/fp64-arithmetic-glsl.d.ts +1 -1
- package/dist/modules-webgl1/math/fp64/fp64-arithmetic-glsl.d.ts.map +1 -1
- package/dist/modules-webgl1/math/fp64/fp64-arithmetic-glsl.js +113 -81
- package/dist/modules-webgl1/math/fp64/fp64-functions-glsl.d.ts +1 -1
- package/dist/modules-webgl1/math/fp64/fp64-functions-glsl.d.ts.map +1 -1
- package/dist/modules-webgl1/math/fp64/fp64-functions-glsl.js +588 -433
- package/dist/modules-webgl1/project/project.d.ts +2 -2
- package/dist/modules-webgl1/project/project.d.ts.map +1 -1
- package/dist/modules-webgl1/project/project.js +5 -4
- package/package.json +2 -2
- package/src/index.ts +78 -32
- package/src/lib/glsl-utils/shader-utils.ts +1 -3
- package/src/lib/shader-assembler.ts +7 -8
- package/src/lib/shader-assembly/assemble-shaders.ts +52 -20
- package/src/lib/shader-assembly/platform-defines.ts +5 -6
- package/src/lib/shader-module/shader-module-dependencies.ts +112 -0
- package/src/lib/shader-module/shader-module.ts +129 -18
- package/src/lib/shader-module/shader-pass.ts +3 -2
- package/src/module-injectors.ts +2 -4
- package/src/modules/engine/geometry/geometry.ts +2 -3
- package/src/modules/engine/picking/picking.ts +7 -5
- package/src/modules/engine/project/project.ts +2 -3
- package/src/modules/engine/transform/transform.ts +1 -3
- package/src/modules/lighting/gouraud-material/gouraud-material.ts +4 -0
- package/src/modules/lighting/gouraud-material/gouraud-shaders-glsl.ts +2 -4
- package/src/modules/lighting/lights/lighting-uniforms-glsl.ts +1 -3
- package/src/modules/lighting/lights/lighting.ts +4 -2
- package/src/modules/lighting/no-material/dirlight.ts +6 -5
- package/src/modules/lighting/pbr-material/pbr-fragment-glsl.ts +1 -2
- package/src/modules/lighting/pbr-material/pbr-material.ts +44 -38
- package/src/modules/lighting/pbr-material/pbr-uniforms-glsl.ts +1 -3
- package/src/modules/lighting/pbr-material/pbr-vertex-glsl.ts +1 -3
- package/src/modules/lighting/phong-material/phong-material.ts +4 -3
- package/src/modules/lighting/phong-material/phong-shaders-glsl.ts +2 -4
- package/src/modules/math/fp32/fp32.ts +1 -2
- package/src/modules/math/random/random.ts +1 -2
- package/src/modules/module-injectors.ts +2 -4
- package/src/modules/postprocessing/image-adjust-filters/brightnesscontrast.ts +6 -2
- package/src/modules/postprocessing/image-adjust-filters/denoise.ts +7 -3
- package/src/modules/postprocessing/image-adjust-filters/huesaturation.ts +9 -4
- package/src/modules/postprocessing/image-adjust-filters/noise.ts +6 -2
- package/src/modules/postprocessing/image-adjust-filters/sepia.ts +6 -2
- package/src/modules/postprocessing/image-adjust-filters/vibrance.ts +5 -2
- package/src/modules/postprocessing/image-adjust-filters/vignette.ts +11 -4
- package/src/modules/postprocessing/image-blur-filters/tiltshift.ts +6 -2
- package/src/modules/postprocessing/image-blur-filters/triangleblur.ts +6 -2
- package/src/modules/postprocessing/image-blur-filters/zoomblur.ts +5 -0
- package/src/modules/postprocessing/image-fun-filters/colorhalftone.ts +6 -2
- package/src/modules/postprocessing/image-fun-filters/dotscreen.ts +6 -2
- package/src/modules/postprocessing/image-fun-filters/edgework.ts +10 -4
- package/src/modules/postprocessing/image-fun-filters/hexagonalpixelate.ts +6 -2
- package/src/modules/postprocessing/image-fun-filters/ink.ts +8 -3
- package/src/modules/postprocessing/image-fun-filters/magnify.ts +3 -2
- package/src/modules/postprocessing/image-warp-filters/bulgepinch.ts +6 -2
- package/src/modules/postprocessing/image-warp-filters/swirl.ts +8 -2
- package/src/modules/postprocessing/image-warp-filters/warp.ts +3 -2
- package/src/modules-webgl1/geometry/geometry.ts +2 -3
- package/src/modules-webgl1/lighting/dirlight/dirlight.ts +1 -2
- package/src/modules-webgl1/lighting/lights/lights-glsl.ts +1 -3
- package/src/modules-webgl1/lighting/pbr/pbr-fragment-glsl.ts +1 -2
- package/src/modules-webgl1/lighting/pbr/pbr-vertex-glsl.ts +1 -3
- package/src/modules-webgl1/lighting/phong-lighting/phong-lighting-glsl.ts +1 -3
- package/src/modules-webgl1/math/fp64/fp64-arithmetic-glsl.ts +1 -3
- package/src/modules-webgl1/math/fp64/fp64-functions-glsl.ts +1 -3
- package/src/modules-webgl1/project/project.ts +1 -2
- package/dist/lib/glsl-utils/highlight.d.ts +0 -6
- package/dist/lib/glsl-utils/highlight.d.ts.map +0 -1
- package/dist/lib/glsl-utils/highlight.js +0 -9
- package/dist/lib/shader-assembly/resolve-modules.d.ts +0 -40
- package/dist/lib/shader-assembly/resolve-modules.d.ts.map +0 -1
- package/dist/lib/shader-module/normalize-shader-module.d.ts +0 -3
- package/dist/lib/shader-module/normalize-shader-module.d.ts.map +0 -1
- package/dist/lib/shader-module/normalize-shader-module.js +0 -14
- package/dist/lib/shader-module/shader-module-instance.d.ts +0 -28
- package/dist/lib/shader-module/shader-module-instance.d.ts.map +0 -1
- package/dist/lib/shader-module/shader-module-instance.js +0 -126
- package/src/lib/glsl-utils/highlight.ts +0 -11
- package/src/lib/shader-assembly/resolve-modules.ts +0 -81
- package/src/lib/shader-module/normalize-shader-module.ts +0 -17
- package/src/lib/shader-module/shader-module-instance.ts +0 -167
|
@@ -11,8 +11,8 @@ declare function getUniforms(opts?: ProjectionProps, prevUniforms?: {}): Record<
|
|
|
11
11
|
export declare const project: {
|
|
12
12
|
readonly name: "project";
|
|
13
13
|
readonly getUniforms: typeof getUniforms;
|
|
14
|
-
readonly vs:
|
|
15
|
-
readonly fs:
|
|
14
|
+
readonly vs: "varying vec4 project_vPositionWorld;\nvarying vec3 project_vNormalWorld;\n\nvec4 project_getPosition_World() {\n return project_vPositionWorld;\n}\n\nvec3 project_getNormal_World() {\n return project_vNormalWorld;\n}\n\n\n// Unprefixed uniforms\nuniform mat4 modelMatrix;\nuniform mat4 viewMatrix;\nuniform mat4 projectionMatrix;\nuniform mat4 viewProjectionMatrix;\nuniform vec3 cameraPositionWorld;\n\nstruct World {\n vec3 position;\n vec3 normal;\n};\n\nWorld world;\n\nvoid project_setPosition(vec4 position) {\n project_vPositionWorld = position;\n}\n\nvoid project_setNormal(vec3 normal) {\n project_vNormalWorld = normal;\n}\n\nvoid project_setPositionAndNormal_World(vec3 position, vec3 normal) {\n world.position = position;\n world.normal = normal;\n}\n\nvoid project_setPositionAndNormal_Model(vec3 position, vec3 normal) {\n world.position = (modelMatrix * vec4(position, 1.)).xyz;\n world.normal = mat3(modelMatrix) * normal;\n}\n\nvec4 project_model_to_clipspace(vec4 position) {\n return viewProjectionMatrix * modelMatrix * position;\n}\n\nvec4 project_model_to_clipspace(vec3 position) {\n return viewProjectionMatrix * modelMatrix * vec4(position, 1.);\n}\n\nvec4 project_world_to_clipspace(vec3 position) {\n return viewProjectionMatrix * vec4(position, 1.);\n}\n\nvec4 project_view_to_clipspace(vec3 position) {\n return projectionMatrix * vec4(position, 1.);\n}\n\nvec4 project_to_clipspace(vec3 position) {\n return viewProjectionMatrix * vec4(position, 1.);\n}\n";
|
|
15
|
+
readonly fs: "\nvarying vec4 project_vPositionWorld;\nvarying vec3 project_vNormalWorld;\n\nvec4 project_getPosition_World() {\n return project_vPositionWorld;\n}\n\nvec3 project_getNormal_World() {\n return project_vNormalWorld;\n}\n";
|
|
16
16
|
};
|
|
17
17
|
export {};
|
|
18
18
|
//# sourceMappingURL=project.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../../src/modules-webgl1/project/project.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../../src/modules-webgl1/project/project.ts"],"names":[],"mappings":"AAOA,KAAK,eAAe,GAAG;IACrB,WAAW,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAChC,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/B,gBAAgB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACrC,mBAAmB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACzC,CAAC;AAWF,iBAAS,WAAW,CAAC,IAAI,GAAE,eAAwC,EAAE,YAAY,KAAK,uBA2BrF;AA2ED;;GAEG;AACH,eAAO,MAAM,OAAO;;;;;CAK+C,CAAC"}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
import { Matrix4 } from '@math.gl/core';
|
|
5
|
-
import { glsl } from "../../lib/glsl-utils/highlight.js";
|
|
6
5
|
const IDENTITY_MATRIX = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
7
6
|
const DEFAULT_MODULE_OPTIONS = {
|
|
8
7
|
modelMatrix: IDENTITY_MATRIX,
|
|
@@ -33,14 +32,16 @@ function getUniforms(opts = DEFAULT_MODULE_OPTIONS, prevUniforms = {}) {
|
|
|
33
32
|
}
|
|
34
33
|
return uniforms;
|
|
35
34
|
}
|
|
36
|
-
const common = `\
|
|
35
|
+
const common = /* glsl */ `\
|
|
37
36
|
varying vec4 project_vPositionWorld;
|
|
38
37
|
varying vec3 project_vNormalWorld;
|
|
38
|
+
|
|
39
39
|
vec4 project_getPosition_World() {
|
|
40
|
-
return project_vPositionWorld;
|
|
40
|
+
return project_vPositionWorld;
|
|
41
41
|
}
|
|
42
|
+
|
|
42
43
|
vec3 project_getNormal_World() {
|
|
43
|
-
return project_vNormalWorld;
|
|
44
|
+
return project_vNormalWorld;
|
|
44
45
|
}
|
|
45
46
|
`;
|
|
46
47
|
const vs = `\
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luma.gl/shadertools",
|
|
3
|
-
"version": "9.1.0-alpha.
|
|
3
|
+
"version": "9.1.0-alpha.10",
|
|
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": "
|
|
56
|
+
"gitHead": "f419cdc284e87b553df60af49d2888ac7dbbf288"
|
|
57
57
|
}
|
package/src/index.ts
CHANGED
|
@@ -8,20 +8,27 @@
|
|
|
8
8
|
* Marks GLSL shaders for syntax highlighting: glsl`...`
|
|
9
9
|
* Install https://marketplace.visualstudio.com/items?itemName=boyswan.glsl-literal
|
|
10
10
|
*/
|
|
11
|
-
export {glsl} from './lib/glsl-utils/highlight';
|
|
12
|
-
|
|
13
11
|
export type {PlatformInfo} from './lib/shader-assembly/platform-info';
|
|
14
12
|
|
|
13
|
+
// ShaderModules
|
|
14
|
+
|
|
15
15
|
export type {ShaderModule} from './lib/shader-module/shader-module';
|
|
16
16
|
export type {ShaderPass} from './lib/shader-module/shader-pass';
|
|
17
|
-
|
|
18
|
-
export
|
|
19
|
-
export {
|
|
17
|
+
|
|
18
|
+
export {initializeShaderModule, initializeShaderModules} from './lib/shader-module/shader-module';
|
|
19
|
+
export {getShaderModuleUniforms} from './lib/shader-module/shader-module';
|
|
20
|
+
export {getShaderModuleDependencies} from './lib/shader-module/shader-module-dependencies';
|
|
21
|
+
export {checkShaderModuleDeprecations} from './lib/shader-module/shader-module';
|
|
22
|
+
|
|
23
|
+
export {getShaderModuleSource} from './lib/shader-assembly/assemble-shaders';
|
|
24
|
+
|
|
25
|
+
export {resolveModules as _resolveModules} from './lib/shader-module/shader-module-dependencies';
|
|
26
|
+
export {getDependencyGraph as _getDependencyGraph} from './lib/shader-module/shader-module-dependencies';
|
|
20
27
|
|
|
21
28
|
// ShaderAssembler
|
|
22
29
|
export {ShaderAssembler} from './lib/shader-assembler';
|
|
23
|
-
|
|
24
|
-
export {
|
|
30
|
+
export type {ShaderHook} from './lib/shader-assembly/shader-hooks';
|
|
31
|
+
export type {ShaderInjection} from './lib/shader-assembly/shader-injections';
|
|
25
32
|
|
|
26
33
|
// SHADER HELPERS
|
|
27
34
|
|
|
@@ -43,10 +50,7 @@ export {capitalize} from './lib/shader-generator/utils/capitalize';
|
|
|
43
50
|
// TEST EXPORTS - Do not use in production applications
|
|
44
51
|
export {preprocess} from './lib/preprocessor/preprocessor';
|
|
45
52
|
export {assembleGLSLShaderPair} from './lib/shader-assembly/assemble-shaders';
|
|
46
|
-
export {ShaderModuleInstance as _ShaderModuleInstance} from './lib/shader-module/shader-module-instance';
|
|
47
53
|
export {combineInjects} from './lib/shader-assembly/shader-injections';
|
|
48
|
-
export {resolveModules as _resolveModules} from './lib/shader-assembly/resolve-modules';
|
|
49
|
-
export {getDependencyGraph as _getDependencyGraph} from './lib/shader-assembly/resolve-modules';
|
|
50
54
|
|
|
51
55
|
// EXPERIMENTAL WGSL
|
|
52
56
|
export {getShaderLayoutFromWGSL} from './lib/wgsl/get-shader-layout-wgsl';
|
|
@@ -66,11 +70,11 @@ export {fp32} from './modules/math/fp32/fp32';
|
|
|
66
70
|
// // projection
|
|
67
71
|
// export type {ProjectionUniforms} from './modules/engine/project/project';
|
|
68
72
|
// export {projection} from './modules/engine/project/project';
|
|
69
|
-
export type {PickingProps} from './modules/engine/picking/picking';
|
|
73
|
+
export type {PickingProps, PickingUniforms} from './modules/engine/picking/picking';
|
|
70
74
|
export {picking} from './modules/engine/picking/picking';
|
|
71
75
|
|
|
72
76
|
// // lighting
|
|
73
|
-
export type {LightingProps} from './modules/lighting/lights/lighting';
|
|
77
|
+
export type {LightingProps, LightingUniforms} from './modules/lighting/lights/lighting';
|
|
74
78
|
export {lighting} from './modules/lighting/lights/lighting';
|
|
75
79
|
export {dirlight} from './modules/lighting/no-material/dirlight';
|
|
76
80
|
export type {PhongMaterialUniforms as GouraudMaterialUniforms} from './modules/lighting/phong-material/phong-material';
|
|
@@ -83,55 +87,97 @@ export {pbrMaterial} from './modules/lighting/pbr-material/pbr-material';
|
|
|
83
87
|
// POST PROCESSING / SHADER PASS MODULES
|
|
84
88
|
|
|
85
89
|
// glfx image adjustment shader modules
|
|
86
|
-
export type {
|
|
90
|
+
export type {
|
|
91
|
+
BrightnessContrastProps,
|
|
92
|
+
BrightnessContrastUniforms
|
|
93
|
+
} from './modules/postprocessing/image-adjust-filters/brightnesscontrast';
|
|
87
94
|
export {brightnessContrast} from './modules/postprocessing/image-adjust-filters/brightnesscontrast';
|
|
88
|
-
export type {
|
|
95
|
+
export type {
|
|
96
|
+
DenoiseProps,
|
|
97
|
+
DenoiseUniforms
|
|
98
|
+
} from './modules/postprocessing/image-adjust-filters/denoise';
|
|
89
99
|
export {denoise} from './modules/postprocessing/image-adjust-filters/denoise';
|
|
90
|
-
export type {
|
|
100
|
+
export type {
|
|
101
|
+
HueSaturationProps,
|
|
102
|
+
HueSaturationUniforms
|
|
103
|
+
} from './modules/postprocessing/image-adjust-filters/huesaturation';
|
|
91
104
|
export {hueSaturation} from './modules/postprocessing/image-adjust-filters/huesaturation';
|
|
92
|
-
export type {NoiseProps} from './modules/postprocessing/image-adjust-filters/noise';
|
|
105
|
+
export type {NoiseProps, NoiseUniforms} from './modules/postprocessing/image-adjust-filters/noise';
|
|
93
106
|
export {noise} from './modules/postprocessing/image-adjust-filters/noise';
|
|
94
|
-
export type {SepiaProps} from './modules/postprocessing/image-adjust-filters/sepia';
|
|
107
|
+
export type {SepiaProps, SepiaUniforms} from './modules/postprocessing/image-adjust-filters/sepia';
|
|
95
108
|
export {sepia} from './modules/postprocessing/image-adjust-filters/sepia';
|
|
96
|
-
export type {
|
|
109
|
+
export type {
|
|
110
|
+
VibranceProps,
|
|
111
|
+
VibranceUniforms
|
|
112
|
+
} from './modules/postprocessing/image-adjust-filters/vibrance';
|
|
97
113
|
export {vibrance} from './modules/postprocessing/image-adjust-filters/vibrance';
|
|
98
|
-
export type {
|
|
114
|
+
export type {
|
|
115
|
+
VignetteProps,
|
|
116
|
+
VignetteUniforms
|
|
117
|
+
} from './modules/postprocessing/image-adjust-filters/vignette';
|
|
99
118
|
export {vignette} from './modules/postprocessing/image-adjust-filters/vignette';
|
|
100
119
|
|
|
101
120
|
// glfx BLUR shader modules
|
|
102
|
-
export type {
|
|
121
|
+
export type {
|
|
122
|
+
TiltShiftProps,
|
|
123
|
+
TiltShiftUniforms
|
|
124
|
+
} from './modules/postprocessing/image-blur-filters/tiltshift';
|
|
103
125
|
export {tiltShift} from './modules/postprocessing/image-blur-filters/tiltshift';
|
|
104
|
-
export type {
|
|
126
|
+
export type {
|
|
127
|
+
TriangleBlurProps,
|
|
128
|
+
TriangleBlurUniforms
|
|
129
|
+
} from './modules/postprocessing/image-blur-filters/triangleblur';
|
|
105
130
|
export {triangleBlur} from './modules/postprocessing/image-blur-filters/triangleblur';
|
|
106
|
-
export type {
|
|
131
|
+
export type {
|
|
132
|
+
ZoomBlurProps,
|
|
133
|
+
ZoomBlurUniforms
|
|
134
|
+
} from './modules/postprocessing/image-blur-filters/zoomblur';
|
|
107
135
|
export {zoomBlur} from './modules/postprocessing/image-blur-filters/zoomblur';
|
|
108
136
|
|
|
109
137
|
// glfx FUN shader modules
|
|
110
|
-
export type {
|
|
138
|
+
export type {
|
|
139
|
+
ColorHalftoneProps,
|
|
140
|
+
ColorHalftoneUniforms
|
|
141
|
+
} from './modules/postprocessing/image-fun-filters/colorhalftone';
|
|
111
142
|
export {colorHalftone} from './modules/postprocessing/image-fun-filters/colorhalftone';
|
|
112
|
-
export type {
|
|
143
|
+
export type {
|
|
144
|
+
DotScreenProps,
|
|
145
|
+
DotScreenUniforms
|
|
146
|
+
} from './modules/postprocessing/image-fun-filters/dotscreen';
|
|
113
147
|
export {dotScreen} from './modules/postprocessing/image-fun-filters/dotscreen';
|
|
114
|
-
export type {
|
|
148
|
+
export type {
|
|
149
|
+
EdgeWorkProps,
|
|
150
|
+
EdgeWorkUniforms
|
|
151
|
+
} from './modules/postprocessing/image-fun-filters/edgework';
|
|
115
152
|
export {edgeWork} from './modules/postprocessing/image-fun-filters/edgework';
|
|
116
|
-
export type {
|
|
153
|
+
export type {
|
|
154
|
+
HexagonalPixelateProps,
|
|
155
|
+
HexagonalPixelateUniforms
|
|
156
|
+
} from './modules/postprocessing/image-fun-filters/hexagonalpixelate';
|
|
117
157
|
export {hexagonalPixelate} from './modules/postprocessing/image-fun-filters/hexagonalpixelate';
|
|
118
|
-
export type {InkProps} from './modules/postprocessing/image-fun-filters/ink';
|
|
158
|
+
export type {InkProps, InkUniforms} from './modules/postprocessing/image-fun-filters/ink';
|
|
119
159
|
export {ink} from './modules/postprocessing/image-fun-filters/ink';
|
|
120
|
-
export type {
|
|
160
|
+
export type {
|
|
161
|
+
MagnifyProps,
|
|
162
|
+
MagnifyUniforms
|
|
163
|
+
} from './modules/postprocessing/image-fun-filters/magnify';
|
|
121
164
|
export {magnify} from './modules/postprocessing/image-fun-filters/magnify';
|
|
122
165
|
|
|
123
166
|
// glfx WARP shader modules
|
|
124
|
-
export type {
|
|
167
|
+
export type {
|
|
168
|
+
BulgePinchProps,
|
|
169
|
+
BulgePinchUniforms
|
|
170
|
+
} from './modules/postprocessing/image-warp-filters/bulgepinch';
|
|
125
171
|
export {bulgePinch} from './modules/postprocessing/image-warp-filters/bulgepinch';
|
|
126
|
-
export type {SwirlProps} from './modules/postprocessing/image-warp-filters/swirl';
|
|
172
|
+
export type {SwirlProps, SwirlUniforms} from './modules/postprocessing/image-warp-filters/swirl';
|
|
127
173
|
export {swirl} from './modules/postprocessing/image-warp-filters/swirl';
|
|
128
174
|
|
|
129
175
|
// Postprocessing modules
|
|
130
|
-
// export type {FXAAProps} from './modules/postprocessing/fxaa/fxaa';
|
|
176
|
+
// export type {FXAAProps, FXAAUniforms} from './modules/postprocessing/fxaa/fxaa';
|
|
131
177
|
export {fxaa} from './modules/postprocessing/fxaa/fxaa';
|
|
132
178
|
|
|
133
179
|
// experimental modules
|
|
134
|
-
export type {WarpProps} from './modules/postprocessing/image-warp-filters/warp';
|
|
180
|
+
export type {WarpProps, WarpUniforms} from './modules/postprocessing/image-warp-filters/warp';
|
|
135
181
|
export {warp as _warp} from './modules/postprocessing/image-warp-filters/warp';
|
|
136
182
|
|
|
137
183
|
// DEPRECATED - v8 legacy shader modules (non-uniform buffer)
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import type {ShaderModule} from './shader-module/shader-module';
|
|
6
|
-
import {
|
|
6
|
+
import {initializeShaderModules} from './shader-module/shader-module';
|
|
7
7
|
import {
|
|
8
8
|
AssembleShaderProps,
|
|
9
9
|
GetUniformsFunc,
|
|
@@ -76,7 +76,7 @@ export class ShaderAssembler {
|
|
|
76
76
|
assembleWGSLShader(props: AssembleShaderProps): {
|
|
77
77
|
source: string;
|
|
78
78
|
getUniforms: GetUniformsFunc;
|
|
79
|
-
modules:
|
|
79
|
+
modules: ShaderModule[];
|
|
80
80
|
} {
|
|
81
81
|
const modules = this._getModuleList(props.modules); // Combine with default modules
|
|
82
82
|
const hookFunctions = this._hookFunctions; // TODO - combine with default hook functions
|
|
@@ -103,7 +103,7 @@ export class ShaderAssembler {
|
|
|
103
103
|
vs: string;
|
|
104
104
|
fs: string;
|
|
105
105
|
getUniforms: GetUniformsFunc;
|
|
106
|
-
modules:
|
|
106
|
+
modules: ShaderModule[];
|
|
107
107
|
} {
|
|
108
108
|
const modules = this._getModuleList(props.modules); // Combine with default modules
|
|
109
109
|
const hookFunctions = this._hookFunctions; // TODO - combine with default hook functions
|
|
@@ -123,10 +123,8 @@ export class ShaderAssembler {
|
|
|
123
123
|
/**
|
|
124
124
|
* Dedupe and combine with default modules
|
|
125
125
|
*/
|
|
126
|
-
_getModuleList(appModules:
|
|
127
|
-
const modules = new Array<ShaderModule
|
|
128
|
-
this._defaultModules.length + appModules.length
|
|
129
|
-
);
|
|
126
|
+
_getModuleList(appModules: ShaderModule[] = []): ShaderModule[] {
|
|
127
|
+
const modules = new Array<ShaderModule>(this._defaultModules.length + appModules.length);
|
|
130
128
|
const seen: Record<string, boolean> = {};
|
|
131
129
|
let count = 0;
|
|
132
130
|
|
|
@@ -148,6 +146,7 @@ export class ShaderAssembler {
|
|
|
148
146
|
|
|
149
147
|
modules.length = count;
|
|
150
148
|
|
|
151
|
-
|
|
149
|
+
initializeShaderModules(modules);
|
|
150
|
+
return modules;
|
|
152
151
|
}
|
|
153
152
|
}
|
|
@@ -2,13 +2,12 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {resolveModules} from './resolve-modules';
|
|
5
|
+
import {getShaderModuleDependencies} from '../shader-module/shader-module-dependencies';
|
|
7
6
|
import {PlatformInfo} from './platform-info';
|
|
8
7
|
import {getPlatformShaderDefines} from './platform-defines';
|
|
9
8
|
import {injectShader, DECLARATION_INJECT_MARKER} from './shader-injections';
|
|
10
9
|
import {transpileGLSLShader} from '../shader-transpiler/transpile-glsl-shader';
|
|
11
|
-
import {
|
|
10
|
+
import {checkShaderModuleDeprecations} from '../shader-module/shader-module';
|
|
12
11
|
import type {ShaderInjection} from './shader-injections';
|
|
13
12
|
import type {ShaderModule} from '../shader-module/shader-module';
|
|
14
13
|
import {ShaderHook, normalizeShaderHooks, getShaderHooks} from './shader-hooks';
|
|
@@ -24,7 +23,7 @@ const INJECT_SHADER_DECLARATIONS = `\n\n${DECLARATION_INJECT_MARKER}\n`;
|
|
|
24
23
|
* Precision prologue to inject before functions are injected in shader
|
|
25
24
|
* TODO - extract any existing prologue in the fragment source and move it up...
|
|
26
25
|
*/
|
|
27
|
-
const FRAGMENT_SHADER_PROLOGUE = glsl`\
|
|
26
|
+
const FRAGMENT_SHADER_PROLOGUE = /* glsl */ `\
|
|
28
27
|
precision highp float;
|
|
29
28
|
`;
|
|
30
29
|
|
|
@@ -47,7 +46,7 @@ export type AssembleShaderOptions = {
|
|
|
47
46
|
/** Inject shader id #defines */
|
|
48
47
|
id?: string;
|
|
49
48
|
/** Modules to be injected */
|
|
50
|
-
modules?:
|
|
49
|
+
modules?: ShaderModule[];
|
|
51
50
|
/** Defines to be injected */
|
|
52
51
|
defines?: Record<string, ShaderDefine>;
|
|
53
52
|
/** Hook functions */
|
|
@@ -99,7 +98,8 @@ export function assembleWGSLShader(
|
|
|
99
98
|
source: string;
|
|
100
99
|
getUniforms: GetUniformsFunc;
|
|
101
100
|
} {
|
|
102
|
-
const modules =
|
|
101
|
+
const modules = getShaderModuleDependencies(options.modules || []);
|
|
102
|
+
|
|
103
103
|
return {
|
|
104
104
|
source: assembleShaderWGSL(options.platformInfo, {
|
|
105
105
|
...options,
|
|
@@ -127,7 +127,7 @@ export function assembleGLSLShaderPair(
|
|
|
127
127
|
getUniforms: GetUniformsFunc;
|
|
128
128
|
} {
|
|
129
129
|
const {vs, fs} = options;
|
|
130
|
-
const modules =
|
|
130
|
+
const modules = getShaderModuleDependencies(options.modules || []);
|
|
131
131
|
|
|
132
132
|
return {
|
|
133
133
|
vs: assembleShaderGLSL(options.platformInfo, {
|
|
@@ -228,9 +228,9 @@ export function assembleShaderWGSL(platformInfo: PlatformInfo, options: Assemble
|
|
|
228
228
|
|
|
229
229
|
for (const module of modulesToInject) {
|
|
230
230
|
if (log) {
|
|
231
|
-
module
|
|
231
|
+
checkShaderModuleDeprecations(module, coreSource, log);
|
|
232
232
|
}
|
|
233
|
-
const moduleSource = module
|
|
233
|
+
const moduleSource = getShaderModuleSource(module, stage);
|
|
234
234
|
// Add the module source, and a #define that declares it presence
|
|
235
235
|
assembledSource += moduleSource;
|
|
236
236
|
|
|
@@ -279,7 +279,7 @@ function assembleShaderGLSL(
|
|
|
279
279
|
source: string;
|
|
280
280
|
language?: 'glsl' | 'wgsl';
|
|
281
281
|
stage: 'vertex' | 'fragment';
|
|
282
|
-
modules:
|
|
282
|
+
modules: ShaderModule[];
|
|
283
283
|
defines?: Record<string, ShaderDefine>;
|
|
284
284
|
hookFunctions?: any[];
|
|
285
285
|
inject?: Record<string, string | ShaderInjection>;
|
|
@@ -314,7 +314,7 @@ function assembleShaderGLSL(
|
|
|
314
314
|
// Combine Module and Application Defines
|
|
315
315
|
const allDefines = {};
|
|
316
316
|
modules.forEach(module => {
|
|
317
|
-
Object.assign(allDefines, module.
|
|
317
|
+
Object.assign(allDefines, module.defines);
|
|
318
318
|
});
|
|
319
319
|
Object.assign(allDefines, defines);
|
|
320
320
|
|
|
@@ -333,6 +333,7 @@ ${sourceVersionDirective}
|
|
|
333
333
|
// ----- PROLOGUE -------------------------
|
|
334
334
|
${getShaderNameDefine({id, source, stage})}
|
|
335
335
|
${`#define SHADER_TYPE_${stage.toUpperCase()}`}
|
|
336
|
+
|
|
336
337
|
${getPlatformShaderDefines(platformInfo)}
|
|
337
338
|
${stage === 'fragment' ? FRAGMENT_SHADER_PROLOGUE : ''}
|
|
338
339
|
|
|
@@ -354,7 +355,6 @@ ${getApplicationDefines(allDefines)}
|
|
|
354
355
|
const mainInjections: Record<string, ShaderInjection[]> = {};
|
|
355
356
|
|
|
356
357
|
for (const key in inject) {
|
|
357
|
-
// @ts-expect-error
|
|
358
358
|
const injection: ShaderInjection =
|
|
359
359
|
typeof inject[key] === 'string' ? {injection: inject[key], order: 0} : inject[key];
|
|
360
360
|
const match = /^(v|f)s:(#)?([\w-]+)$/.exec(key);
|
|
@@ -378,13 +378,13 @@ ${getApplicationDefines(allDefines)}
|
|
|
378
378
|
|
|
379
379
|
for (const module of modules) {
|
|
380
380
|
if (log) {
|
|
381
|
-
module
|
|
381
|
+
checkShaderModuleDeprecations(module, coreSource, log);
|
|
382
382
|
}
|
|
383
|
-
const moduleSource = module
|
|
383
|
+
const moduleSource = getShaderModuleSource(module, stage);
|
|
384
384
|
// Add the module source, and a #define that declares it presence
|
|
385
385
|
assembledSource += moduleSource;
|
|
386
386
|
|
|
387
|
-
const injections = module.
|
|
387
|
+
const injections = module.instance?.normalizedInjections[stage] || {};
|
|
388
388
|
for (const key in injections) {
|
|
389
389
|
const match = /^(v|f)s:#([\w-]+)$/.exec(key);
|
|
390
390
|
if (match) {
|
|
@@ -429,13 +429,13 @@ ${getApplicationDefines(allDefines)}
|
|
|
429
429
|
* @param modules
|
|
430
430
|
* @returns
|
|
431
431
|
*/
|
|
432
|
-
export function assembleGetUniforms(modules:
|
|
432
|
+
export function assembleGetUniforms(modules: ShaderModule[]) {
|
|
433
433
|
return function getUniforms(opts: Record<string, any>): Record<string, any> {
|
|
434
434
|
const uniforms = {};
|
|
435
435
|
for (const module of modules) {
|
|
436
436
|
// `modules` is already sorted by dependency level. This guarantees that
|
|
437
437
|
// modules have access to the uniforms that are generated by their dependencies.
|
|
438
|
-
const moduleUniforms = module.getUniforms(opts, uniforms);
|
|
438
|
+
const moduleUniforms = module.getUniforms?.(opts, uniforms);
|
|
439
439
|
Object.assign(uniforms, moduleUniforms);
|
|
440
440
|
}
|
|
441
441
|
return uniforms;
|
|
@@ -456,9 +456,7 @@ function getShaderNameDefine(options: {
|
|
|
456
456
|
const injectShaderName = id && source.indexOf('SHADER_NAME') === -1;
|
|
457
457
|
return injectShaderName
|
|
458
458
|
? `
|
|
459
|
-
#define SHADER_NAME ${id}_${stage}
|
|
460
|
-
|
|
461
|
-
`
|
|
459
|
+
#define SHADER_NAME ${id}_${stage}`
|
|
462
460
|
: '';
|
|
463
461
|
}
|
|
464
462
|
|
|
@@ -474,6 +472,40 @@ function getApplicationDefines(defines: Record<string, ShaderDefine> = {}): stri
|
|
|
474
472
|
return sourceText;
|
|
475
473
|
}
|
|
476
474
|
|
|
475
|
+
/** Extracts the source code chunk for the specified shader type from the named shader module */
|
|
476
|
+
export function getShaderModuleSource(
|
|
477
|
+
module: ShaderModule,
|
|
478
|
+
stage: 'vertex' | 'fragment' | 'wgsl'
|
|
479
|
+
): string {
|
|
480
|
+
let moduleSource;
|
|
481
|
+
switch (stage) {
|
|
482
|
+
case 'vertex':
|
|
483
|
+
moduleSource = module.vs || '';
|
|
484
|
+
break;
|
|
485
|
+
case 'fragment':
|
|
486
|
+
moduleSource = module.fs || '';
|
|
487
|
+
break;
|
|
488
|
+
case 'wgsl':
|
|
489
|
+
moduleSource = module.source || '';
|
|
490
|
+
break;
|
|
491
|
+
default:
|
|
492
|
+
assert(false);
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
if (!module.name) {
|
|
496
|
+
throw new Error('Shader module must have a name');
|
|
497
|
+
}
|
|
498
|
+
const moduleName = module.name.toUpperCase().replace(/[^0-9a-z]/gi, '_');
|
|
499
|
+
return `\
|
|
500
|
+
// ----- MODULE ${module.name} ---------------
|
|
501
|
+
|
|
502
|
+
#define MODULE_${moduleName}
|
|
503
|
+
${moduleSource}\
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
`;
|
|
507
|
+
}
|
|
508
|
+
|
|
477
509
|
/*
|
|
478
510
|
function getHookFunctions(
|
|
479
511
|
hookFunctions: Record<string, HookFunction>,
|
|
@@ -2,14 +2,13 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import {glsl} from '../glsl-utils/highlight';
|
|
6
5
|
import {PlatformInfo} from './platform-info';
|
|
7
6
|
|
|
8
7
|
/** Adds defines to help identify GPU architecture / platform */
|
|
9
8
|
export function getPlatformShaderDefines(platformInfo: PlatformInfo): string {
|
|
10
9
|
switch (platformInfo?.gpu.toLowerCase()) {
|
|
11
10
|
case 'apple':
|
|
12
|
-
return glsl`\
|
|
11
|
+
return /* glsl */ `\
|
|
13
12
|
#define APPLE_GPU
|
|
14
13
|
// Apple optimizes away the calculation necessary for emulated fp64
|
|
15
14
|
#define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1
|
|
@@ -19,14 +18,14 @@ export function getPlatformShaderDefines(platformInfo: PlatformInfo): string {
|
|
|
19
18
|
`;
|
|
20
19
|
|
|
21
20
|
case 'nvidia':
|
|
22
|
-
return glsl`\
|
|
21
|
+
return /* glsl */ `\
|
|
23
22
|
#define NVIDIA_GPU
|
|
24
23
|
// Nvidia optimizes away the calculation necessary for emulated fp64
|
|
25
24
|
#define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1
|
|
26
25
|
`;
|
|
27
26
|
|
|
28
27
|
case 'intel':
|
|
29
|
-
return glsl`\
|
|
28
|
+
return /* glsl */ `\
|
|
30
29
|
#define INTEL_GPU
|
|
31
30
|
// Intel optimizes away the calculation necessary for emulated fp64
|
|
32
31
|
#define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1
|
|
@@ -38,7 +37,7 @@ export function getPlatformShaderDefines(platformInfo: PlatformInfo): string {
|
|
|
38
37
|
|
|
39
38
|
case 'amd':
|
|
40
39
|
// AMD Does not eliminate fp64 code
|
|
41
|
-
return glsl`\
|
|
40
|
+
return /* glsl */ `\
|
|
42
41
|
#define AMD_GPU
|
|
43
42
|
`;
|
|
44
43
|
|
|
@@ -46,7 +45,7 @@ export function getPlatformShaderDefines(platformInfo: PlatformInfo): string {
|
|
|
46
45
|
// We don't know what GPU it is, could be that the GPU driver or
|
|
47
46
|
// browser is not implementing UNMASKED_RENDERER constant and not
|
|
48
47
|
// reporting a correct name
|
|
49
|
-
return glsl`\
|
|
48
|
+
return /* glsl */ `\
|
|
50
49
|
#define DEFAULT_GPU
|
|
51
50
|
// Prevent driver from optimizing away the calculation necessary for emulated fp64
|
|
52
51
|
#define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {ShaderModule} from './shader-module';
|
|
6
|
+
import {initializeShaderModules} from '../shader-module/shader-module';
|
|
7
|
+
|
|
8
|
+
// import type {ShaderModule} from '../shader-module/shader-module';
|
|
9
|
+
|
|
10
|
+
type AbstractModule = {
|
|
11
|
+
name: string;
|
|
12
|
+
dependencies?: AbstractModule[];
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Takes a list of shader module names and returns a new list of
|
|
17
|
+
* shader module names that includes all dependencies, sorted so
|
|
18
|
+
* that modules that are dependencies of other modules come first.
|
|
19
|
+
*
|
|
20
|
+
* If the shader glsl code from the returned modules is concatenated
|
|
21
|
+
* in the reverse order, it is guaranteed that all functions be resolved and
|
|
22
|
+
* that all function and variable definitions come before use.
|
|
23
|
+
*
|
|
24
|
+
* @param modules - Array of modules (inline modules or module names)
|
|
25
|
+
* @return - Array of modules
|
|
26
|
+
*/
|
|
27
|
+
export function getShaderModuleDependencies<T extends AbstractModule>(modules: T[]): T[] {
|
|
28
|
+
initializeShaderModules(modules);
|
|
29
|
+
const moduleMap: Record<string, T> = {};
|
|
30
|
+
const moduleDepth: Record<string, number> = {};
|
|
31
|
+
getDependencyGraph({modules, level: 0, moduleMap, moduleDepth});
|
|
32
|
+
|
|
33
|
+
// Return a reverse sort so that dependencies come before the modules that use them
|
|
34
|
+
const dependencies = Object.keys(moduleDepth)
|
|
35
|
+
.sort((a, b) => moduleDepth[b] - moduleDepth[a])
|
|
36
|
+
.map(name => moduleMap[name]);
|
|
37
|
+
initializeShaderModules(dependencies);
|
|
38
|
+
return dependencies;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Recursively checks module dependencies to calculate dependency level of each module.
|
|
43
|
+
*
|
|
44
|
+
* @param options.modules - Array of modules
|
|
45
|
+
* @param options.level - Current level
|
|
46
|
+
* @param options.moduleMap -
|
|
47
|
+
* @param options.moduleDepth - Current level
|
|
48
|
+
* @return - Map of module name to its level
|
|
49
|
+
*/
|
|
50
|
+
// Adds another level of dependencies to the result map
|
|
51
|
+
export function getDependencyGraph<T extends AbstractModule>(options: {
|
|
52
|
+
modules: T[];
|
|
53
|
+
level: number;
|
|
54
|
+
moduleMap: Record<string, T>;
|
|
55
|
+
moduleDepth: Record<string, number>;
|
|
56
|
+
}) {
|
|
57
|
+
const {modules, level, moduleMap, moduleDepth} = options;
|
|
58
|
+
if (level >= 5) {
|
|
59
|
+
throw new Error('Possible loop in shader dependency graph');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Update level on all current modules
|
|
63
|
+
for (const module of modules) {
|
|
64
|
+
moduleMap[module.name] = module;
|
|
65
|
+
if (moduleDepth[module.name] === undefined || moduleDepth[module.name] < level) {
|
|
66
|
+
moduleDepth[module.name] = level;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Recurse
|
|
71
|
+
for (const module of modules) {
|
|
72
|
+
if (module.dependencies) {
|
|
73
|
+
getDependencyGraph({modules: module.dependencies, level: level + 1, moduleMap, moduleDepth});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Takes a list of shader module names and returns a new list of
|
|
80
|
+
* shader module names that includes all dependencies, sorted so
|
|
81
|
+
* that modules that are dependencies of other modules come first.
|
|
82
|
+
*
|
|
83
|
+
* If the shader glsl code from the returned modules is concatenated
|
|
84
|
+
* in the reverse order, it is guaranteed that all functions be resolved and
|
|
85
|
+
* that all function and variable definitions come before use.
|
|
86
|
+
*
|
|
87
|
+
* @param modules - Array of modules (inline modules or module names)
|
|
88
|
+
* @return - Array of modules
|
|
89
|
+
*/
|
|
90
|
+
export function getShaderDependencies(modules: ShaderModule[]): ShaderModule[] {
|
|
91
|
+
initializeShaderModules(modules);
|
|
92
|
+
const moduleMap: Record<string, ShaderModule> = {};
|
|
93
|
+
const moduleDepth: Record<string, number> = {};
|
|
94
|
+
getDependencyGraph({modules, level: 0, moduleMap, moduleDepth});
|
|
95
|
+
|
|
96
|
+
// Return a reverse sort so that dependencies come before the modules that use them
|
|
97
|
+
modules = Object.keys(moduleDepth)
|
|
98
|
+
.sort((a, b) => moduleDepth[b] - moduleDepth[a])
|
|
99
|
+
.map(name => moduleMap[name]);
|
|
100
|
+
initializeShaderModules(modules);
|
|
101
|
+
return modules;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// DEPRECATED
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Instantiate shader modules and resolve any dependencies
|
|
108
|
+
* @deprecated Use getShaderDpendencies
|
|
109
|
+
*/
|
|
110
|
+
export function resolveModules(modules: ShaderModule[]): ShaderModule[] {
|
|
111
|
+
return getShaderDependencies(modules);
|
|
112
|
+
}
|