@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
package/dist/lib/{shader-assembly/resolve-modules.js → shader-module/shader-module-dependencies.js}
RENAMED
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
// luma.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
|
-
import {
|
|
5
|
-
/**
|
|
6
|
-
* Instantiate shader modules and esolve any dependencies
|
|
7
|
-
*/
|
|
8
|
-
export function resolveModules(modules) {
|
|
9
|
-
const instances = ShaderModuleInstance.instantiateModules(modules);
|
|
10
|
-
return getShaderDependencies(instances);
|
|
11
|
-
}
|
|
4
|
+
import { initializeShaderModules } from "../shader-module/shader-module.js";
|
|
12
5
|
/**
|
|
13
6
|
* Takes a list of shader module names and returns a new list of
|
|
14
7
|
* shader module names that includes all dependencies, sorted so
|
|
@@ -21,14 +14,17 @@ export function resolveModules(modules) {
|
|
|
21
14
|
* @param modules - Array of modules (inline modules or module names)
|
|
22
15
|
* @return - Array of modules
|
|
23
16
|
*/
|
|
24
|
-
function
|
|
17
|
+
export function getShaderModuleDependencies(modules) {
|
|
18
|
+
initializeShaderModules(modules);
|
|
25
19
|
const moduleMap = {};
|
|
26
20
|
const moduleDepth = {};
|
|
27
21
|
getDependencyGraph({ modules, level: 0, moduleMap, moduleDepth });
|
|
28
22
|
// Return a reverse sort so that dependencies come before the modules that use them
|
|
29
|
-
|
|
23
|
+
const dependencies = Object.keys(moduleDepth)
|
|
30
24
|
.sort((a, b) => moduleDepth[b] - moduleDepth[a])
|
|
31
25
|
.map(name => moduleMap[name]);
|
|
26
|
+
initializeShaderModules(dependencies);
|
|
27
|
+
return dependencies;
|
|
32
28
|
}
|
|
33
29
|
/**
|
|
34
30
|
* Recursively checks module dependencies to calculate dependency level of each module.
|
|
@@ -59,7 +55,35 @@ export function getDependencyGraph(options) {
|
|
|
59
55
|
}
|
|
60
56
|
}
|
|
61
57
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
58
|
+
/**
|
|
59
|
+
* Takes a list of shader module names and returns a new list of
|
|
60
|
+
* shader module names that includes all dependencies, sorted so
|
|
61
|
+
* that modules that are dependencies of other modules come first.
|
|
62
|
+
*
|
|
63
|
+
* If the shader glsl code from the returned modules is concatenated
|
|
64
|
+
* in the reverse order, it is guaranteed that all functions be resolved and
|
|
65
|
+
* that all function and variable definitions come before use.
|
|
66
|
+
*
|
|
67
|
+
* @param modules - Array of modules (inline modules or module names)
|
|
68
|
+
* @return - Array of modules
|
|
69
|
+
*/
|
|
70
|
+
export function getShaderDependencies(modules) {
|
|
71
|
+
initializeShaderModules(modules);
|
|
72
|
+
const moduleMap = {};
|
|
73
|
+
const moduleDepth = {};
|
|
74
|
+
getDependencyGraph({ modules, level: 0, moduleMap, moduleDepth });
|
|
75
|
+
// Return a reverse sort so that dependencies come before the modules that use them
|
|
76
|
+
modules = Object.keys(moduleDepth)
|
|
77
|
+
.sort((a, b) => moduleDepth[b] - moduleDepth[a])
|
|
78
|
+
.map(name => moduleMap[name]);
|
|
79
|
+
initializeShaderModules(modules);
|
|
80
|
+
return modules;
|
|
81
|
+
}
|
|
82
|
+
// DEPRECATED
|
|
83
|
+
/**
|
|
84
|
+
* Instantiate shader modules and resolve any dependencies
|
|
85
|
+
* @deprecated Use getShaderDpendencies
|
|
86
|
+
*/
|
|
87
|
+
export function resolveModules(modules) {
|
|
88
|
+
return getShaderDependencies(modules);
|
|
89
|
+
}
|
|
@@ -1,21 +1,29 @@
|
|
|
1
|
-
import { NumberArray } from '@math.gl/types';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import type { NumberArray } from '@math.gl/types';
|
|
2
|
+
import { Sampler, Texture } from '@luma.gl/core';
|
|
3
|
+
import type { UniformFormat } from "../../types.js";
|
|
4
|
+
import { PropType, PropValidator } from "../filters/prop-types.js";
|
|
5
|
+
import { ShaderInjection } from "../shader-assembly/shader-injections.js";
|
|
6
|
+
export type BindingValue = Buffer | Texture | Sampler;
|
|
4
7
|
export type UniformValue = number | boolean | Readonly<NumberArray>;
|
|
5
8
|
export type UniformInfo = {
|
|
6
9
|
format?: UniformFormat;
|
|
7
10
|
} & PropType;
|
|
8
11
|
/**
|
|
9
12
|
* A shader module definition object
|
|
10
|
-
*
|
|
13
|
+
*
|
|
14
|
+
* @note Needs to be initialized with `initializeShaderModules`
|
|
11
15
|
*/
|
|
12
|
-
export type ShaderModule<PropsT extends Record<string, unknown> = Record<string, unknown>, UniformsT extends Record<string, UniformValue> = Record<string, UniformValue>, BindingsT extends Record<string,
|
|
16
|
+
export type ShaderModule<PropsT extends Record<string, unknown> = Record<string, unknown>, UniformsT extends Record<string, UniformValue> = Record<string, UniformValue>, BindingsT extends Record<string, BindingValue> = Record<string, BindingValue>> = {
|
|
13
17
|
/** Used for type inference not for values */
|
|
14
|
-
props?:
|
|
18
|
+
props?: PropsT;
|
|
15
19
|
/** Used for type inference, not currently used for values */
|
|
16
20
|
uniforms?: UniformsT;
|
|
17
21
|
name: string;
|
|
22
|
+
/** WGSL code */
|
|
23
|
+
source?: string;
|
|
24
|
+
/** GLSL fragment shader code */
|
|
18
25
|
fs?: string;
|
|
26
|
+
/** GLSL vertex shader code */
|
|
19
27
|
vs?: string;
|
|
20
28
|
/** Uniform shader types @note: Both order and types MUST match uniform block declarations in shader */
|
|
21
29
|
uniformTypes?: Record<keyof UniformsT, UniformFormat>;
|
|
@@ -23,8 +31,8 @@ export type ShaderModule<PropsT extends Record<string, unknown> = Record<string,
|
|
|
23
31
|
uniformPropTypes?: Record<keyof UniformsT, UniformInfo>;
|
|
24
32
|
/** Default uniform values */
|
|
25
33
|
defaultUniforms?: Required<UniformsT>;
|
|
26
|
-
/** Function that maps
|
|
27
|
-
getUniforms?: (
|
|
34
|
+
/** Function that maps props to uniforms & bindings */
|
|
35
|
+
getUniforms?: (props?: any, oldProps?: any) => Record<string, BindingValue | UniformValue>;
|
|
28
36
|
/** uniform buffers, textures, samplers, storage, ... */
|
|
29
37
|
bindings?: Record<keyof BindingsT, {
|
|
30
38
|
location: number;
|
|
@@ -39,8 +47,15 @@ export type ShaderModule<PropsT extends Record<string, unknown> = Record<string,
|
|
|
39
47
|
dependencies?: ShaderModule<any, any>[];
|
|
40
48
|
/** Information on deprecated properties */
|
|
41
49
|
deprecations?: ShaderModuleDeprecation[];
|
|
42
|
-
/**
|
|
43
|
-
|
|
50
|
+
/** The instance field contains information that is generated at run-time */
|
|
51
|
+
instance?: {
|
|
52
|
+
propValidators?: Record<string, PropValidator>;
|
|
53
|
+
parsedDeprecations: ShaderModuleDeprecation[];
|
|
54
|
+
normalizedInjections: {
|
|
55
|
+
vertex: Record<string, ShaderInjection>;
|
|
56
|
+
fragment: Record<string, ShaderInjection>;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
44
59
|
};
|
|
45
60
|
/** Use to generate deprecations when shader module is used */
|
|
46
61
|
export type ShaderModuleDeprecation = {
|
|
@@ -50,6 +65,9 @@ export type ShaderModuleDeprecation = {
|
|
|
50
65
|
old: string;
|
|
51
66
|
deprecated?: boolean;
|
|
52
67
|
};
|
|
68
|
+
export declare function initializeShaderModules(modules: ShaderModule[]): void;
|
|
69
|
+
export declare function initializeShaderModule(module: ShaderModule): void;
|
|
53
70
|
/** Convert module props to uniforms */
|
|
54
|
-
export declare function getShaderModuleUniforms<ShaderModuleT extends ShaderModule<Record<string, unknown>, Record<string, UniformValue>>>(module: ShaderModuleT, props: ShaderModuleT['props']
|
|
71
|
+
export declare function getShaderModuleUniforms<ShaderModuleT extends ShaderModule<Record<string, unknown>, Record<string, UniformValue>>>(module: ShaderModuleT, props: ShaderModuleT['props'], oldUniforms?: ShaderModuleT['uniforms']): Record<string, BindingValue | UniformValue>;
|
|
72
|
+
export declare function checkShaderModuleDeprecations(shaderModule: ShaderModule, shaderSource: string, log: any): void;
|
|
55
73
|
//# sourceMappingURL=shader-module.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shader-module.d.ts","sourceRoot":"","sources":["../../../src/lib/shader-module/shader-module.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,WAAW,EAAC,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"shader-module.d.ts","sourceRoot":"","sources":["../../../src/lib/shader-module/shader-module.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,WAAW,EAAC,MAAM,g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AAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAIF,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,IAAI,CAErE;AAED,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI,CAwBjE;AAED,uCAAuC;AACvC,wBAAgB,uBAAuB,CACrC,aAAa,SAAS,YAAY,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,EAEzF,MAAM,EAAE,aAAa,EACrB,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,EAC7B,WAAW,CAAC,EAAE,aAAa,CAAC,UAAU,CAAC,GACtC,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,YAAY,CAAC,CAY7C;AAwBD,wBAAgB,6BAA6B,CAC3C,YAAY,EAAE,YAAY,EAC1B,YAAY,EAAE,MAAM,EACpB,GAAG,EAAE,GAAG,GACP,IAAI,CAUN"}
|
|
@@ -1,15 +1,85 @@
|
|
|
1
1
|
// luma.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
|
+
import { makePropValidators, getValidatedProperties } from "../filters/prop-types.js";
|
|
5
|
+
import { normalizeInjections } from "../shader-assembly/shader-injections.js";
|
|
6
|
+
// SHNDER MODULE API
|
|
7
|
+
export function initializeShaderModules(modules) {
|
|
8
|
+
modules.map((module) => initializeShaderModule(module));
|
|
9
|
+
}
|
|
10
|
+
export function initializeShaderModule(module) {
|
|
11
|
+
if (module.instance) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
initializeShaderModules(module.dependencies || []);
|
|
15
|
+
const { uniformPropTypes = {}, deprecations = [],
|
|
16
|
+
// defines = {},
|
|
17
|
+
inject = {} } = module;
|
|
18
|
+
const instance = {
|
|
19
|
+
normalizedInjections: normalizeInjections(inject),
|
|
20
|
+
parsedDeprecations: parseDeprecationDefinitions(deprecations)
|
|
21
|
+
};
|
|
22
|
+
if (uniformPropTypes) {
|
|
23
|
+
instance.propValidators = makePropValidators(uniformPropTypes);
|
|
24
|
+
}
|
|
25
|
+
module.instance = instance;
|
|
26
|
+
}
|
|
4
27
|
/** Convert module props to uniforms */
|
|
5
|
-
export function getShaderModuleUniforms(module, props) {
|
|
6
|
-
|
|
28
|
+
export function getShaderModuleUniforms(module, props, oldUniforms) {
|
|
29
|
+
initializeShaderModule(module);
|
|
30
|
+
const uniforms = oldUniforms || { ...module.defaultUniforms };
|
|
31
|
+
// If module has a getUniforms function, use it
|
|
7
32
|
if (module.getUniforms) {
|
|
8
|
-
|
|
9
|
-
Object.assign(props, module.getUniforms(props));
|
|
33
|
+
return module.getUniforms(props, uniforms);
|
|
10
34
|
}
|
|
11
|
-
|
|
12
|
-
|
|
35
|
+
// Build uniforms from the uniforms array
|
|
36
|
+
// @ts-expect-error
|
|
37
|
+
return getValidatedProperties(props, module.instance?.propValidators, module.name);
|
|
38
|
+
}
|
|
39
|
+
/* TODO this looks like it was unused code
|
|
40
|
+
_defaultGetUniforms(opts: Record<string, any> = {}): Record<string, any> {
|
|
41
|
+
const uniforms: Record<string, any> = {};
|
|
42
|
+
const propTypes = this.uniforms;
|
|
43
|
+
|
|
44
|
+
for (const key in propTypes) {
|
|
45
|
+
const propDef = propTypes[key];
|
|
46
|
+
if (key in opts && !propDef.private) {
|
|
47
|
+
if (propDef.validate) {
|
|
48
|
+
assert(propDef.validate(opts[key], propDef), `${this.name}: invalid ${key}`);
|
|
49
|
+
}
|
|
50
|
+
uniforms[key] = opts[key];
|
|
51
|
+
} else {
|
|
52
|
+
uniforms[key] = propDef.value;
|
|
53
|
+
}
|
|
13
54
|
}
|
|
55
|
+
|
|
14
56
|
return uniforms;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
*/
|
|
60
|
+
// Warn about deprecated uniforms or functions
|
|
61
|
+
export function checkShaderModuleDeprecations(shaderModule, shaderSource, log) {
|
|
62
|
+
shaderModule.deprecations?.forEach(def => {
|
|
63
|
+
if (def.regex?.test(shaderSource)) {
|
|
64
|
+
if (def.deprecated) {
|
|
65
|
+
log.deprecated(def.old, def.new)();
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
log.removed(def.old, def.new)();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
// HELPERS
|
|
74
|
+
function parseDeprecationDefinitions(deprecations) {
|
|
75
|
+
deprecations.forEach(def => {
|
|
76
|
+
switch (def.type) {
|
|
77
|
+
case 'function':
|
|
78
|
+
def.regex = new RegExp(`\\b${def.old}\\(`);
|
|
79
|
+
break;
|
|
80
|
+
default:
|
|
81
|
+
def.regex = new RegExp(`${def.type} ${def.old};`);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
return deprecations;
|
|
15
85
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { ShaderModule, UniformValue } from "./shader-module.js";
|
|
2
2
|
/**
|
|
3
|
-
* A
|
|
4
|
-
* on how to run
|
|
3
|
+
* A ShaderPass is a ShaderModule that can be run "standalone" (e.g. post processing effects)
|
|
4
|
+
* It adds additional information on how to run the module in one or more passes.
|
|
5
5
|
*/
|
|
6
6
|
export type ShaderPass<PropsT extends Record<string, unknown> = Record<string, unknown>, UniformsT extends Record<string, UniformValue> = Record<string, UniformValue>> = ShaderModule<PropsT, UniformsT> & {
|
|
7
7
|
passes: ShaderPassData[];
|
|
8
8
|
};
|
|
9
|
+
/** Information on how to run a specific pass */
|
|
9
10
|
type ShaderPassData = {
|
|
10
11
|
sampler?: boolean;
|
|
11
12
|
filter?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shader-pass.d.ts","sourceRoot":"","sources":["../../../src/lib/shader-module/shader-pass.ts"],"names":[],"mappings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AAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const MODULE_INJECTORS_VS
|
|
2
|
-
export declare const MODULE_INJECTORS_FS
|
|
1
|
+
export declare const MODULE_INJECTORS_VS = "#ifdef MODULE_LOGDEPTH\n logdepth_adjustPosition(gl_Position);\n#endif\n";
|
|
2
|
+
export declare const MODULE_INJECTORS_FS = "#ifdef MODULE_MATERIAL\n gl_FragColor = material_filterColor(gl_FragColor);\n#endif\n\n#ifdef MODULE_LIGHTING\n gl_FragColor = lighting_filterColor(gl_FragColor);\n#endif\n\n#ifdef MODULE_FOG\n gl_FragColor = fog_filterColor(gl_FragColor);\n#endif\n\n#ifdef MODULE_PICKING\n gl_FragColor = picking_filterHighlightColor(gl_FragColor);\n gl_FragColor = picking_filterPickingColor(gl_FragColor);\n#endif\n\n#ifdef MODULE_LOGDEPTH\n logdepth_setFragDepth();\n#endif\n";
|
|
3
3
|
//# sourceMappingURL=module-injectors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module-injectors.d.ts","sourceRoot":"","sources":["../src/module-injectors.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"module-injectors.d.ts","sourceRoot":"","sources":["../src/module-injectors.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,mBAAmB,8EAI/B,CAAC;AAEF,eAAO,MAAM,mBAAmB,0dAqB/B,CAAC"}
|
package/dist/module-injectors.js
CHANGED
|
@@ -1,27 +1,30 @@
|
|
|
1
1
|
// luma.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
|
-
|
|
5
|
-
export const MODULE_INJECTORS_VS = `\
|
|
4
|
+
export const MODULE_INJECTORS_VS = /* glsl */ `\
|
|
6
5
|
#ifdef MODULE_LOGDEPTH
|
|
7
|
-
logdepth_adjustPosition(gl_Position);
|
|
6
|
+
logdepth_adjustPosition(gl_Position);
|
|
8
7
|
#endif
|
|
9
8
|
`;
|
|
10
|
-
export const MODULE_INJECTORS_FS = `\
|
|
9
|
+
export const MODULE_INJECTORS_FS = /* glsl */ `\
|
|
11
10
|
#ifdef MODULE_MATERIAL
|
|
12
|
-
gl_FragColor = material_filterColor(gl_FragColor);
|
|
11
|
+
gl_FragColor = material_filterColor(gl_FragColor);
|
|
13
12
|
#endif
|
|
13
|
+
|
|
14
14
|
#ifdef MODULE_LIGHTING
|
|
15
|
-
gl_FragColor = lighting_filterColor(gl_FragColor);
|
|
15
|
+
gl_FragColor = lighting_filterColor(gl_FragColor);
|
|
16
16
|
#endif
|
|
17
|
+
|
|
17
18
|
#ifdef MODULE_FOG
|
|
18
|
-
gl_FragColor = fog_filterColor(gl_FragColor);
|
|
19
|
+
gl_FragColor = fog_filterColor(gl_FragColor);
|
|
19
20
|
#endif
|
|
21
|
+
|
|
20
22
|
#ifdef MODULE_PICKING
|
|
21
|
-
gl_FragColor = picking_filterHighlightColor(gl_FragColor);
|
|
22
|
-
gl_FragColor = picking_filterPickingColor(gl_FragColor);
|
|
23
|
+
gl_FragColor = picking_filterHighlightColor(gl_FragColor);
|
|
24
|
+
gl_FragColor = picking_filterPickingColor(gl_FragColor);
|
|
23
25
|
#endif
|
|
26
|
+
|
|
24
27
|
#ifdef MODULE_LOGDEPTH
|
|
25
|
-
logdepth_setFragDepth();
|
|
28
|
+
logdepth_setFragDepth();
|
|
26
29
|
#endif
|
|
27
30
|
`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geometry.d.ts","sourceRoot":"","sources":["../../../../src/modules/engine/geometry/geometry.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"geometry.d.ts","sourceRoot":"","sources":["../../../../src/modules/engine/geometry/geometry.ts"],"names":[],"mappings":"AAqCA;;GAEG;AACH,eAAO,MAAM,QAAQ;;;;CAIpB,CAAC"}
|
|
@@ -2,29 +2,33 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
// import {ShaderModule} from '../../types';
|
|
5
|
-
import { glsl } from "../../../lib/glsl-utils/highlight.js";
|
|
6
5
|
// TODO - reuse normal from geometry module
|
|
7
|
-
const vs = `\
|
|
6
|
+
const vs = /* glsl */ `\
|
|
8
7
|
varying vec4 geometry_vPosition;
|
|
9
8
|
varying vec3 geometry_vNormal;
|
|
9
|
+
|
|
10
10
|
void geometry_setNormal(vec3 normal) {
|
|
11
|
-
geometry_vNormal = normal;
|
|
11
|
+
geometry_vNormal = normal;
|
|
12
12
|
}
|
|
13
|
+
|
|
13
14
|
void geometry_setPosition(vec4 position) {
|
|
14
|
-
geometry_vPosition = position;
|
|
15
|
+
geometry_vPosition = position;
|
|
15
16
|
}
|
|
17
|
+
|
|
16
18
|
void geometry_setPosition(vec3 position) {
|
|
17
|
-
geometry_vPosition = vec4(position, 1.);
|
|
19
|
+
geometry_vPosition = vec4(position, 1.);
|
|
18
20
|
}
|
|
19
21
|
`;
|
|
20
|
-
const fs = `\
|
|
22
|
+
const fs = /* glsl */ `\
|
|
21
23
|
varying vec4 geometry_vPosition;
|
|
22
24
|
varying vec3 geometry_vNormal;
|
|
25
|
+
|
|
23
26
|
vec4 geometry_getPosition() {
|
|
24
|
-
return geometry_vPosition;
|
|
27
|
+
return geometry_vPosition;
|
|
25
28
|
}
|
|
29
|
+
|
|
26
30
|
vec3 geometry_getNormal() {
|
|
27
|
-
return geometry_vNormal;
|
|
31
|
+
return geometry_vNormal;
|
|
28
32
|
}
|
|
29
33
|
`;
|
|
30
34
|
/**
|
|
@@ -46,6 +46,8 @@ export type PickingUniforms = {
|
|
|
46
46
|
* primitives with the same picking color in non-instanced draw-calls
|
|
47
47
|
*/
|
|
48
48
|
export declare const picking: {
|
|
49
|
+
readonly props: PickingProps;
|
|
50
|
+
readonly uniforms: PickingUniforms;
|
|
49
51
|
readonly name: "picking";
|
|
50
52
|
readonly uniformTypes: {
|
|
51
53
|
readonly isActive: "f32";
|
|
@@ -63,10 +65,8 @@ export declare const picking: {
|
|
|
63
65
|
readonly highlightedObjectColor: Float32Array;
|
|
64
66
|
readonly highlightColor: Float32Array;
|
|
65
67
|
};
|
|
66
|
-
readonly vs:
|
|
67
|
-
readonly fs:
|
|
68
|
-
readonly props: Required<PickingProps>;
|
|
69
|
-
readonly uniforms: PickingUniforms;
|
|
68
|
+
readonly vs: "uniform pickingUniforms {\n float isActive;\n float isAttribute;\n float isHighlightActive;\n float useFloatColors;\n vec3 highlightedObjectColor;\n vec4 highlightColor;\n} picking;\n\nout vec4 picking_vRGBcolor_Avalid;\n\n// Normalize unsigned byte color to 0-1 range\nvec3 picking_normalizeColor(vec3 color) {\n return picking.useFloatColors > 0.5 ? color : color / 255.0;\n}\n\n// Normalize unsigned byte color to 0-1 range\nvec4 picking_normalizeColor(vec4 color) {\n return picking.useFloatColors > 0.5 ? color : color / 255.0;\n}\n\nbool picking_isColorZero(vec3 color) {\n return dot(color, vec3(1.0)) < 0.00001;\n}\n\nbool picking_isColorValid(vec3 color) {\n return dot(color, vec3(1.0)) > 0.00001;\n}\n\n// Check if this vertex is highlighted \nbool isVertexHighlighted(vec3 vertexColor) {\n vec3 highlightedObjectColor = picking_normalizeColor(picking.highlightedObjectColor);\n return\n bool(picking.isHighlightActive) && picking_isColorZero(abs(vertexColor - highlightedObjectColor));\n}\n\n// Set the current picking color\nvoid picking_setPickingColor(vec3 pickingColor) {\n pickingColor = picking_normalizeColor(pickingColor);\n\n if (bool(picking.isActive)) {\n // Use alpha as the validity flag. If pickingColor is [0, 0, 0] fragment is non-pickable\n picking_vRGBcolor_Avalid.a = float(picking_isColorValid(pickingColor));\n\n if (!bool(picking.isAttribute)) {\n // Stores the picking color so that the fragment shader can render it during picking\n picking_vRGBcolor_Avalid.rgb = pickingColor;\n }\n } else {\n // Do the comparison with selected item color in vertex shader as it should mean fewer compares\n picking_vRGBcolor_Avalid.a = float(isVertexHighlighted(pickingColor));\n }\n}\n\nvoid picking_setPickingAttribute(float value) {\n if (bool(picking.isAttribute)) {\n picking_vRGBcolor_Avalid.r = value;\n }\n}\n\nvoid picking_setPickingAttribute(vec2 value) {\n if (bool(picking.isAttribute)) {\n picking_vRGBcolor_Avalid.rg = value;\n }\n}\n\nvoid picking_setPickingAttribute(vec3 value) {\n if (bool(picking.isAttribute)) {\n picking_vRGBcolor_Avalid.rgb = value;\n }\n}\n";
|
|
69
|
+
readonly fs: "uniform pickingUniforms {\n float isActive;\n float isAttribute;\n float isHighlightActive;\n float useFloatColors;\n vec3 highlightedObjectColor;\n vec4 highlightColor;\n} picking;\n\nin vec4 picking_vRGBcolor_Avalid;\n\n/*\n * Returns highlight color if this item is selected.\n */\nvec4 picking_filterHighlightColor(vec4 color) {\n // If we are still picking, we don't highlight\n if (picking.isActive > 0.5) {\n return color;\n }\n\n bool selected = bool(picking_vRGBcolor_Avalid.a);\n\n if (selected) {\n // Blend in highlight color based on its alpha value\n float highLightAlpha = picking.highlightColor.a;\n float blendedAlpha = highLightAlpha + color.a * (1.0 - highLightAlpha);\n float highLightRatio = highLightAlpha / blendedAlpha;\n\n vec3 blendedRGB = mix(color.rgb, picking.highlightColor.rgb, highLightRatio);\n return vec4(blendedRGB, blendedAlpha);\n } else {\n return color;\n }\n}\n\n/*\n * Returns picking color if picking enabled else unmodified argument.\n */\nvec4 picking_filterPickingColor(vec4 color) {\n if (bool(picking.isActive)) {\n if (picking_vRGBcolor_Avalid.a == 0.0) {\n discard;\n }\n return picking_vRGBcolor_Avalid;\n }\n return color;\n}\n\n/*\n * Returns picking color if picking is enabled if not\n * highlight color if this item is selected, otherwise unmodified argument.\n */\nvec4 picking_filterColor(vec4 color) {\n vec4 highlightColor = picking_filterHighlightColor(color);\n return picking_filterPickingColor(highlightColor);\n}\n";
|
|
70
70
|
readonly getUniforms: typeof getUniforms;
|
|
71
71
|
};
|
|
72
72
|
declare function getUniforms(opts?: PickingProps, prevUniforms?: PickingUniforms): PickingUniforms;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"picking.d.ts","sourceRoot":"","sources":["../../../../src/modules/engine/picking/picking.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,WAAW,EAAC,0BAAuB;
|
|
1
|
+
{"version":3,"file":"picking.d.ts","sourceRoot":"","sources":["../../../../src/modules/engine/picking/picking.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,WAAW,EAAC,0BAAuB;AAM3C;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,qDAAqD;IACrD,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,0EAA0E;IAC1E,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,6FAA6F;IAC7F,sBAAsB,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;IAC5C,mDAAmD;IACnD,cAAc,CAAC,EAAE,WAAW,CAAC;IAC7B,+BAA+B;IAC/B,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,0EAA0E;IAC1E,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,+BAA+B;IAC/B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,qCAAqC;IACrC,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,6DAA6D;IAC7D,sBAAsB,CAAC,EAAE,WAAW,CAAC;IACrC,mDAAmD;IACnD,cAAc,CAAC,EAAE,WAAW,CAAC;CAC9B,CAAC;AAuIF;;;;;;GAMG;AACH,eAAO,MAAM,OAAO;oBACL,YAAY;uBACT,eAAe;;;;;;;;;;;;;;;;;;;;;CAwB+B,CAAC;AAEjE,iBAAS,WAAW,CAAC,IAAI,GAAE,YAAiB,EAAE,YAAY,CAAC,EAAE,eAAe,GAAG,eAAe,CA+B7F"}
|
|
@@ -1,100 +1,137 @@
|
|
|
1
1
|
// luma.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
|
-
import { glsl } from "../../../lib/glsl-utils/highlight.js";
|
|
5
4
|
// cyan color
|
|
6
5
|
const DEFAULT_HIGHLIGHT_COLOR = new Float32Array([0, 1, 1, 1]);
|
|
7
|
-
const vs = `\
|
|
6
|
+
const vs = /* glsl */ `\
|
|
8
7
|
uniform pickingUniforms {
|
|
9
|
-
float isActive;
|
|
10
|
-
float isAttribute;
|
|
11
|
-
float isHighlightActive;
|
|
12
|
-
float useFloatColors;
|
|
13
|
-
vec3 highlightedObjectColor;
|
|
14
|
-
vec4 highlightColor;
|
|
8
|
+
float isActive;
|
|
9
|
+
float isAttribute;
|
|
10
|
+
float isHighlightActive;
|
|
11
|
+
float useFloatColors;
|
|
12
|
+
vec3 highlightedObjectColor;
|
|
13
|
+
vec4 highlightColor;
|
|
15
14
|
} picking;
|
|
15
|
+
|
|
16
16
|
out vec4 picking_vRGBcolor_Avalid;
|
|
17
|
+
|
|
18
|
+
// Normalize unsigned byte color to 0-1 range
|
|
17
19
|
vec3 picking_normalizeColor(vec3 color) {
|
|
18
|
-
return picking.useFloatColors > 0.5 ? color : color / 255.0;
|
|
20
|
+
return picking.useFloatColors > 0.5 ? color : color / 255.0;
|
|
19
21
|
}
|
|
22
|
+
|
|
23
|
+
// Normalize unsigned byte color to 0-1 range
|
|
20
24
|
vec4 picking_normalizeColor(vec4 color) {
|
|
21
|
-
return picking.useFloatColors > 0.5 ? color : color / 255.0;
|
|
25
|
+
return picking.useFloatColors > 0.5 ? color : color / 255.0;
|
|
22
26
|
}
|
|
27
|
+
|
|
23
28
|
bool picking_isColorZero(vec3 color) {
|
|
24
|
-
return dot(color, vec3(1.0)) < 0.00001;
|
|
29
|
+
return dot(color, vec3(1.0)) < 0.00001;
|
|
25
30
|
}
|
|
31
|
+
|
|
26
32
|
bool picking_isColorValid(vec3 color) {
|
|
27
|
-
return dot(color, vec3(1.0)) > 0.00001;
|
|
33
|
+
return dot(color, vec3(1.0)) > 0.00001;
|
|
28
34
|
}
|
|
35
|
+
|
|
36
|
+
// Check if this vertex is highlighted
|
|
29
37
|
bool isVertexHighlighted(vec3 vertexColor) {
|
|
30
|
-
vec3 highlightedObjectColor = picking_normalizeColor(picking.highlightedObjectColor);
|
|
31
|
-
return
|
|
32
|
-
bool(picking.isHighlightActive) && picking_isColorZero(abs(vertexColor - highlightedObjectColor));
|
|
38
|
+
vec3 highlightedObjectColor = picking_normalizeColor(picking.highlightedObjectColor);
|
|
39
|
+
return
|
|
40
|
+
bool(picking.isHighlightActive) && picking_isColorZero(abs(vertexColor - highlightedObjectColor));
|
|
33
41
|
}
|
|
42
|
+
|
|
43
|
+
// Set the current picking color
|
|
34
44
|
void picking_setPickingColor(vec3 pickingColor) {
|
|
35
|
-
pickingColor = picking_normalizeColor(pickingColor);
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
picking_vRGBcolor_Avalid.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
45
|
+
pickingColor = picking_normalizeColor(pickingColor);
|
|
46
|
+
|
|
47
|
+
if (bool(picking.isActive)) {
|
|
48
|
+
// Use alpha as the validity flag. If pickingColor is [0, 0, 0] fragment is non-pickable
|
|
49
|
+
picking_vRGBcolor_Avalid.a = float(picking_isColorValid(pickingColor));
|
|
50
|
+
|
|
51
|
+
if (!bool(picking.isAttribute)) {
|
|
52
|
+
// Stores the picking color so that the fragment shader can render it during picking
|
|
53
|
+
picking_vRGBcolor_Avalid.rgb = pickingColor;
|
|
54
|
+
}
|
|
55
|
+
} else {
|
|
56
|
+
// Do the comparison with selected item color in vertex shader as it should mean fewer compares
|
|
57
|
+
picking_vRGBcolor_Avalid.a = float(isVertexHighlighted(pickingColor));
|
|
58
|
+
}
|
|
44
59
|
}
|
|
60
|
+
|
|
45
61
|
void picking_setPickingAttribute(float value) {
|
|
46
|
-
if (bool(picking.isAttribute)) {
|
|
47
|
-
picking_vRGBcolor_Avalid.r = value;
|
|
48
|
-
}
|
|
62
|
+
if (bool(picking.isAttribute)) {
|
|
63
|
+
picking_vRGBcolor_Avalid.r = value;
|
|
64
|
+
}
|
|
49
65
|
}
|
|
66
|
+
|
|
50
67
|
void picking_setPickingAttribute(vec2 value) {
|
|
51
|
-
if (bool(picking.isAttribute)) {
|
|
52
|
-
picking_vRGBcolor_Avalid.rg = value;
|
|
53
|
-
}
|
|
68
|
+
if (bool(picking.isAttribute)) {
|
|
69
|
+
picking_vRGBcolor_Avalid.rg = value;
|
|
70
|
+
}
|
|
54
71
|
}
|
|
72
|
+
|
|
55
73
|
void picking_setPickingAttribute(vec3 value) {
|
|
56
|
-
if (bool(picking.isAttribute)) {
|
|
57
|
-
picking_vRGBcolor_Avalid.rgb = value;
|
|
58
|
-
}
|
|
74
|
+
if (bool(picking.isAttribute)) {
|
|
75
|
+
picking_vRGBcolor_Avalid.rgb = value;
|
|
76
|
+
}
|
|
59
77
|
}
|
|
60
78
|
`;
|
|
61
|
-
const fs = `\
|
|
79
|
+
const fs = /* glsl */ `\
|
|
62
80
|
uniform pickingUniforms {
|
|
63
|
-
float isActive;
|
|
64
|
-
float isAttribute;
|
|
65
|
-
float isHighlightActive;
|
|
66
|
-
float useFloatColors;
|
|
67
|
-
vec3 highlightedObjectColor;
|
|
68
|
-
vec4 highlightColor;
|
|
81
|
+
float isActive;
|
|
82
|
+
float isAttribute;
|
|
83
|
+
float isHighlightActive;
|
|
84
|
+
float useFloatColors;
|
|
85
|
+
vec3 highlightedObjectColor;
|
|
86
|
+
vec4 highlightColor;
|
|
69
87
|
} picking;
|
|
88
|
+
|
|
70
89
|
in vec4 picking_vRGBcolor_Avalid;
|
|
90
|
+
|
|
91
|
+
/*
|
|
92
|
+
* Returns highlight color if this item is selected.
|
|
93
|
+
*/
|
|
71
94
|
vec4 picking_filterHighlightColor(vec4 color) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
95
|
+
// If we are still picking, we don't highlight
|
|
96
|
+
if (picking.isActive > 0.5) {
|
|
97
|
+
return color;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
bool selected = bool(picking_vRGBcolor_Avalid.a);
|
|
101
|
+
|
|
102
|
+
if (selected) {
|
|
103
|
+
// Blend in highlight color based on its alpha value
|
|
104
|
+
float highLightAlpha = picking.highlightColor.a;
|
|
105
|
+
float blendedAlpha = highLightAlpha + color.a * (1.0 - highLightAlpha);
|
|
106
|
+
float highLightRatio = highLightAlpha / blendedAlpha;
|
|
107
|
+
|
|
108
|
+
vec3 blendedRGB = mix(color.rgb, picking.highlightColor.rgb, highLightRatio);
|
|
109
|
+
return vec4(blendedRGB, blendedAlpha);
|
|
110
|
+
} else {
|
|
111
|
+
return color;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/*
|
|
116
|
+
* Returns picking color if picking enabled else unmodified argument.
|
|
117
|
+
*/
|
|
86
118
|
vec4 picking_filterPickingColor(vec4 color) {
|
|
87
|
-
if (bool(picking.isActive)) {
|
|
88
|
-
if (picking_vRGBcolor_Avalid.a == 0.0) {
|
|
89
|
-
discard;
|
|
90
|
-
}
|
|
91
|
-
return picking_vRGBcolor_Avalid;
|
|
92
|
-
}
|
|
93
|
-
return color;
|
|
94
|
-
}
|
|
119
|
+
if (bool(picking.isActive)) {
|
|
120
|
+
if (picking_vRGBcolor_Avalid.a == 0.0) {
|
|
121
|
+
discard;
|
|
122
|
+
}
|
|
123
|
+
return picking_vRGBcolor_Avalid;
|
|
124
|
+
}
|
|
125
|
+
return color;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/*
|
|
129
|
+
* Returns picking color if picking is enabled if not
|
|
130
|
+
* highlight color if this item is selected, otherwise unmodified argument.
|
|
131
|
+
*/
|
|
95
132
|
vec4 picking_filterColor(vec4 color) {
|
|
96
|
-
vec4 highlightColor = picking_filterHighlightColor(color);
|
|
97
|
-
return picking_filterPickingColor(highlightColor);
|
|
133
|
+
vec4 highlightColor = picking_filterHighlightColor(color);
|
|
134
|
+
return picking_filterPickingColor(highlightColor);
|
|
98
135
|
}
|
|
99
136
|
`;
|
|
100
137
|
/**
|
|
@@ -105,6 +142,8 @@ return picking_filterPickingColor(highlightColor);
|
|
|
105
142
|
* primitives with the same picking color in non-instanced draw-calls
|
|
106
143
|
*/
|
|
107
144
|
export const picking = {
|
|
145
|
+
props: {},
|
|
146
|
+
uniforms: {},
|
|
108
147
|
name: 'picking',
|
|
109
148
|
uniformTypes: {
|
|
110
149
|
isActive: 'f32',
|
|
@@ -124,8 +163,6 @@ export const picking = {
|
|
|
124
163
|
},
|
|
125
164
|
vs,
|
|
126
165
|
fs,
|
|
127
|
-
props: {},
|
|
128
|
-
uniforms: {},
|
|
129
166
|
getUniforms
|
|
130
167
|
};
|
|
131
168
|
function getUniforms(opts = {}, prevUniforms) {
|
|
@@ -31,8 +31,8 @@ export declare const projection: {
|
|
|
31
31
|
readonly cameraPositionWorld: "vec3<f32>";
|
|
32
32
|
};
|
|
33
33
|
readonly getUniforms: typeof getUniforms;
|
|
34
|
-
readonly vs:
|
|
35
|
-
readonly fs:
|
|
34
|
+
readonly vs: "varying vec4 project_vPositionWorld;\nvarying vec3 project_vNormalWorld;\n\n// Project uniform block\nuniform Project {\n mat4 viewMatrix;\n mat4 projectionMatrix;\n mat4 viewProjectionMatrix;\n vec3 cameraPositionWorld;\n} project;\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, mat4 modelMatrix) {\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 project.viewProjectionMatrix * position;\n}\n\nvec4 project_model_to_clipspace_Model(vec3 position, mat4 modelMatrix) {\n return project.viewProjectionMatrix * modelMatrix * vec4(position, 1.);\n}\n\nvec4 project_world_to_clipspace(vec3 position) {\n return project.viewProjectionMatrix * vec4(position, 1.);\n}\n\nvec4 project_view_to_clipspace(vec3 position) {\n return project.projectionMatrix * vec4(position, 1.);\n}\n\nvec4 project_to_clipspace(vec3 position) {\n return project.viewProjectionMatrix * vec4(position, 1.);\n}\n";
|
|
35
|
+
readonly fs: "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";
|
|
36
36
|
};
|
|
37
37
|
export {};
|
|
38
38
|
//# sourceMappingURL=project.d.ts.map
|