@luma.gl/shadertools 9.0.15 → 9.0.17
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 +787 -195
- package/dist/dist.min.js +79 -79
- package/dist/index.cjs +18 -2854
- package/dist/index.cjs.map +4 -4
- package/dist/lib/shader-module/shader-module.d.ts +22 -13
- package/dist/lib/shader-module/shader-module.d.ts.map +1 -1
- package/dist/lib/shader-module/shader-pass.d.ts +4 -2
- package/dist/lib/shader-module/shader-pass.d.ts.map +1 -1
- package/dist/lib/utils/uniform-types.d.ts +49 -0
- package/dist/lib/utils/uniform-types.d.ts.map +1 -0
- package/dist/lib/utils/uniform-types.js +1 -0
- package/dist/lib/wgsl/get-shader-layout-wgsl.js +5 -5
- package/dist/modules/engine/picking/picking.d.ts +5 -5
- package/dist/modules/engine/picking/picking.d.ts.map +1 -1
- package/dist/modules/engine/picking/picking.js +2 -2
- package/dist/modules/engine/project/project.d.ts +9 -8
- package/dist/modules/engine/project/project.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting-uniforms.d.ts +13 -13
- package/dist/modules/lighting/lights/lighting-uniforms.d.ts.map +1 -1
- package/dist/modules/lighting/no-material/dirlight.d.ts +2 -2
- package/dist/modules/lighting/no-material/dirlight.d.ts.map +1 -1
- package/dist/modules/lighting/no-material/dirlight.js +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts +14 -13
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material.js +0 -11
- package/dist/modules/postprocessing/image-blur-filters/tiltshift.d.ts +2 -2
- package/dist/modules/postprocessing/image-blur-filters/tiltshift.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-blur-filters/triangleblur.d.ts +1 -1
- package/dist/modules/postprocessing/image-blur-filters/triangleblur.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-blur-filters/zoomblur.d.ts +1 -1
- package/dist/modules/postprocessing/image-blur-filters/zoomblur.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-fun-filters/colorhalftone.d.ts +1 -1
- package/dist/modules/postprocessing/image-fun-filters/colorhalftone.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-fun-filters/dotscreen.d.ts +1 -1
- package/dist/modules/postprocessing/image-fun-filters/dotscreen.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-fun-filters/hexagonalpixelate.d.ts +1 -1
- package/dist/modules/postprocessing/image-fun-filters/hexagonalpixelate.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-fun-filters/magnify.d.ts +2 -2
- package/dist/modules/postprocessing/image-fun-filters/magnify.d.ts.map +1 -1
- package/dist/modules/postprocessing/image-warp-filters/bulgepinch.d.ts +1 -1
- package/dist/modules/postprocessing/image-warp-filters/bulgepinch.d.ts.map +1 -1
- package/dist/modules-webgl1/project/project.d.ts +6 -4
- package/dist/modules-webgl1/project/project.d.ts.map +1 -1
- package/package.json +4 -3
- package/src/lib/shader-module/shader-module.ts +24 -12
- package/src/lib/shader-module/shader-pass.ts +7 -4
- package/src/lib/utils/uniform-types.ts +91 -0
- package/src/lib/wgsl/get-shader-layout-wgsl.ts +5 -5
- package/src/modules/engine/picking/picking.ts +9 -9
- package/src/modules/engine/project/project.ts +10 -9
- package/src/modules/lighting/lights/lighting-uniforms.ts +16 -16
- package/src/modules/lighting/no-material/dirlight.ts +3 -3
- package/src/modules/lighting/pbr-material/pbr-material.ts +14 -24
- package/src/modules/postprocessing/image-blur-filters/tiltshift.ts +2 -2
- package/src/modules/postprocessing/image-blur-filters/triangleblur.ts +1 -1
- package/src/modules/postprocessing/image-blur-filters/zoomblur.ts +1 -1
- package/src/modules/postprocessing/image-fun-filters/colorhalftone.ts +1 -1
- package/src/modules/postprocessing/image-fun-filters/dotscreen.ts +1 -1
- package/src/modules/postprocessing/image-fun-filters/hexagonalpixelate.ts +1 -1
- package/src/modules/postprocessing/image-fun-filters/magnify.ts +2 -2
- package/src/modules/postprocessing/image-warp-filters/bulgepinch.ts +1 -1
- package/src/modules-webgl1/project/project.ts +8 -7
- package/dist/libs/wgsl-reflect/wgsl_reflect.module.d.ts +0 -1112
- package/dist/libs/wgsl-reflect/wgsl_reflect.module.d.ts.map +0 -1
- package/dist/libs/wgsl-reflect/wgsl_reflect.module.js +0 -3389
- package/src/libs/wgsl-reflect/wgsl_reflect.module.js +0 -3394
- package/src/libs/wgsl-reflect/wgsl_reflect.module.js.map +0 -1
|
@@ -2,7 +2,7 @@ import { ShaderPass } from "../../../lib/shader-module/shader-pass.js";
|
|
|
2
2
|
/** Bulges or pinches the image in a circle. */
|
|
3
3
|
export type BulgePinchProps = {
|
|
4
4
|
/** The [x, y] coordinates of the center of the circle of effect. */
|
|
5
|
-
center?: number
|
|
5
|
+
center?: [number, number];
|
|
6
6
|
/** The radius of the circle of effect. */
|
|
7
7
|
radius?: number;
|
|
8
8
|
/** strength -1 to 1 (-1 is strong pinch, 0 is no effect, 1 is strong bulge) */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bulgepinch.d.ts","sourceRoot":"","sources":["../../../../src/modules/postprocessing/image-warp-filters/bulgepinch.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,UAAU,EAAC,kDAA+C;AAkClE,+CAA+C;AAC/C,MAAM,MAAM,eAAe,GAAG;IAC5B,oEAAoE;IACpE,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"bulgepinch.d.ts","sourceRoot":"","sources":["../../../../src/modules/postprocessing/image-warp-filters/bulgepinch.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,UAAU,EAAC,kDAA+C;AAkClE,+CAA+C;AAC/C,MAAM,MAAM,eAAe,GAAG;IAC5B,oEAAoE;IACpE,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC1B,0CAA0C;IAC1C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,UAAU,EAAE,UAAU,CAAC,eAAe,EAAE,eAAe,CAenE,CAAC"}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { Vector3, Matrix4 } from '@math.gl/core';
|
|
1
2
|
import { ShaderModule } from "../../lib/shader-module/shader-module.js";
|
|
3
|
+
import type { NumberArray3, NumberArray16 } from "../../lib/utils/uniform-types.js";
|
|
2
4
|
type ProjectionProps = {
|
|
3
|
-
modelMatrix?:
|
|
4
|
-
viewMatrix?:
|
|
5
|
-
projectionMatrix?:
|
|
6
|
-
cameraPositionWorld?:
|
|
5
|
+
modelMatrix?: Readonly<Matrix4 | NumberArray16>;
|
|
6
|
+
viewMatrix?: Readonly<Matrix4 | NumberArray16>;
|
|
7
|
+
projectionMatrix?: Readonly<Matrix4 | NumberArray16>;
|
|
8
|
+
cameraPositionWorld?: Readonly<Vector3 | NumberArray3>;
|
|
7
9
|
};
|
|
8
10
|
/**
|
|
9
11
|
* Projects coordinates
|
|
@@ -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":"AAIA,OAAO,EAAC,OAAO,EAAE,OAAO,EAAC,MAAM,eAAe,CAAC;AAE/C,OAAO,EAAC,YAAY,EAAC,iDAA8C;AACnE,OAAO,KAAK,EAAC,YAAY,EAAE,aAAa,EAAC,yCAAsC;AAE/E,KAAK,eAAe,GAAG;IACrB,WAAW,CAAC,EAAE,QAAQ,CAAC,OAAO,GAAG,aAAa,CAAC,CAAC;IAChD,UAAU,CAAC,EAAE,QAAQ,CAAC,OAAO,GAAG,aAAa,CAAC,CAAC;IAC/C,gBAAgB,CAAC,EAAE,QAAQ,CAAC,OAAO,GAAG,aAAa,CAAC,CAAC;IACrD,mBAAmB,CAAC,EAAE,QAAQ,CAAC,OAAO,GAAG,YAAY,CAAC,CAAC;CACxD,CAAC;AAiHF;;GAEG;AACH,eAAO,MAAM,OAAO,EAAE,YAAY,CAAC,eAAe,EAAE,eAAe,CAKlE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luma.gl/shadertools",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.17",
|
|
4
4
|
"description": "Shader module system for luma.gl",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -50,7 +50,8 @@
|
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@math.gl/core": "^4.0.0",
|
|
53
|
-
"@math.gl/types": "^4.0.0"
|
|
53
|
+
"@math.gl/types": "^4.0.0",
|
|
54
|
+
"wgsl_reflect": "^1.0.1"
|
|
54
55
|
},
|
|
55
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "f348f3221ab2842ffa877b6c99e0e9e4df82426e"
|
|
56
57
|
}
|
|
@@ -2,47 +2,59 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import {NumberArray} from '@math.gl/types';
|
|
6
5
|
import {UniformFormat} from '../../types';
|
|
7
6
|
import {PropType} from '../filters/prop-types';
|
|
8
|
-
import {
|
|
7
|
+
import type {UniformTypes, UniformValue} from '../utils/uniform-types';
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
// To avoid dependency on core module, do not import `Binding` type.
|
|
10
|
+
// The ShaderModule is not concerned with the type of `Binding`,
|
|
11
|
+
// it is the repsonsibility of `splitUniformsAndBindings` in
|
|
12
|
+
// ShaderInputs to type the result of `getUniforms()`
|
|
13
|
+
type Binding = unknown; // import type {Binding} from '@luma.gl/core';
|
|
11
14
|
|
|
12
15
|
export type UniformInfo = {
|
|
13
16
|
format?: UniformFormat;
|
|
14
17
|
} & PropType;
|
|
15
18
|
|
|
19
|
+
// Helper types
|
|
20
|
+
type BindingKeys<T> = {[K in keyof T]: T[K] extends UniformValue ? never : K}[keyof T];
|
|
21
|
+
type UniformKeys<T> = {[K in keyof T]: T[K] extends UniformValue ? K : never}[keyof T];
|
|
22
|
+
export type PickBindings<T> = {[K in BindingKeys<Required<T>>]: T[K]};
|
|
23
|
+
export type PickUniforms<T> = {[K in UniformKeys<Required<T>>]: T[K]};
|
|
24
|
+
|
|
16
25
|
/**
|
|
17
26
|
* A shader module definition object
|
|
18
|
-
* @note
|
|
27
|
+
* @note `UniformsT` & `BindingsT` are deduced from `PropsT` by default. If
|
|
28
|
+
* a custom type for `UniformsT` is used, `BindingsT` should be also be provided.
|
|
19
29
|
*/
|
|
20
30
|
export type ShaderModule<
|
|
21
|
-
PropsT extends Record<string,
|
|
22
|
-
UniformsT extends Record<string, UniformValue> =
|
|
23
|
-
BindingsT extends Record<string,
|
|
31
|
+
PropsT extends Record<string, any> = Record<string, any>,
|
|
32
|
+
UniformsT extends Record<string, UniformValue> = PickUniforms<PropsT>,
|
|
33
|
+
BindingsT extends Record<string, Binding> = PickBindings<PropsT>
|
|
24
34
|
> = {
|
|
25
35
|
/** Used for type inference not for values */
|
|
26
36
|
props?: Required<PropsT>;
|
|
27
37
|
/** Used for type inference, not currently used for values */
|
|
28
38
|
uniforms?: UniformsT;
|
|
39
|
+
/** Used for type inference, not currently used for values */
|
|
40
|
+
bindings?: BindingsT;
|
|
29
41
|
|
|
30
42
|
name: string;
|
|
31
43
|
fs?: string;
|
|
32
44
|
vs?: string;
|
|
33
45
|
|
|
34
46
|
/** Uniform shader types @note: Both order and types MUST match uniform block declarations in shader */
|
|
35
|
-
uniformTypes?: Record<keyof UniformsT, UniformFormat>;
|
|
47
|
+
uniformTypes?: Required<UniformTypes<UniformsT>>; // Record<keyof UniformsT, UniformFormat>;
|
|
36
48
|
/** Uniform JS prop types */
|
|
37
49
|
uniformPropTypes?: Record<keyof UniformsT, UniformInfo>;
|
|
38
50
|
/** Default uniform values */
|
|
39
51
|
defaultUniforms?: Required<UniformsT>; // Record<keyof UniformsT, UniformValue>;
|
|
40
52
|
|
|
41
53
|
/** Function that maps props to uniforms & bindings */
|
|
42
|
-
getUniforms?: (
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
54
|
+
getUniforms?: (
|
|
55
|
+
props?: Partial<PropsT>,
|
|
56
|
+
prevUniforms?: UniformsT
|
|
57
|
+
) => Partial<UniformsT & BindingsT>;
|
|
46
58
|
|
|
47
59
|
defines?: Record<string, string | number>;
|
|
48
60
|
/** Injections */
|
|
@@ -2,16 +2,19 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import type {
|
|
5
|
+
import type {Binding} from '@luma.gl/core';
|
|
6
|
+
import type {PickBindings, PickUniforms, ShaderModule} from './shader-module';
|
|
7
|
+
import type {UniformValue} from '../utils/uniform-types';
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* A shaderpass is a shader module with additional information
|
|
9
11
|
* on how to run
|
|
10
12
|
*/
|
|
11
13
|
export type ShaderPass<
|
|
12
|
-
PropsT extends Record<string,
|
|
13
|
-
UniformsT extends Record<string, UniformValue> =
|
|
14
|
-
|
|
14
|
+
PropsT extends Record<string, any> = Record<string, any>,
|
|
15
|
+
UniformsT extends Record<string, UniformValue> = PickUniforms<PropsT>,
|
|
16
|
+
BindingsT extends Record<string, Binding> = PickBindings<PropsT>
|
|
17
|
+
> = ShaderModule<PropsT, UniformsT, BindingsT> & {
|
|
15
18
|
passes: ShaderPassData[];
|
|
16
19
|
};
|
|
17
20
|
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type {Matrix3, Matrix4, Vector2, Vector3, Vector4} from '@math.gl/core';
|
|
2
|
+
|
|
3
|
+
export type NumberArray2 = [number, number];
|
|
4
|
+
export type NumberArray3 = [number, number, number];
|
|
5
|
+
export type NumberArray4 = [number, number, number, number];
|
|
6
|
+
export type NumberArray6 = [number, number, number, number, number, number];
|
|
7
|
+
export type NumberArray8 = [number, number, number, number, number, number, number, number];
|
|
8
|
+
export type NumberArray9 = [number, number, number, number, number, number, number, number, number];
|
|
9
|
+
export type NumberArray12 = [
|
|
10
|
+
number,
|
|
11
|
+
number,
|
|
12
|
+
number,
|
|
13
|
+
number,
|
|
14
|
+
number,
|
|
15
|
+
number,
|
|
16
|
+
number,
|
|
17
|
+
number,
|
|
18
|
+
number,
|
|
19
|
+
number,
|
|
20
|
+
number,
|
|
21
|
+
number
|
|
22
|
+
];
|
|
23
|
+
export type NumberArray16 = [
|
|
24
|
+
number,
|
|
25
|
+
number,
|
|
26
|
+
number,
|
|
27
|
+
number,
|
|
28
|
+
number,
|
|
29
|
+
number,
|
|
30
|
+
number,
|
|
31
|
+
number,
|
|
32
|
+
number,
|
|
33
|
+
number,
|
|
34
|
+
number,
|
|
35
|
+
number,
|
|
36
|
+
number,
|
|
37
|
+
number,
|
|
38
|
+
number,
|
|
39
|
+
number
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
/*
|
|
43
|
+
* Allowed types to be used for uniform values
|
|
44
|
+
*
|
|
45
|
+
* Only allow types whose length we can type-check (not `TypedArray`)
|
|
46
|
+
*/
|
|
47
|
+
export type UniformValue = Readonly<
|
|
48
|
+
| number
|
|
49
|
+
| boolean
|
|
50
|
+
| NumberArray2
|
|
51
|
+
| NumberArray3
|
|
52
|
+
| NumberArray4
|
|
53
|
+
| NumberArray6
|
|
54
|
+
| NumberArray8
|
|
55
|
+
| NumberArray9
|
|
56
|
+
| NumberArray12
|
|
57
|
+
| NumberArray16
|
|
58
|
+
| Vector2
|
|
59
|
+
| Vector3
|
|
60
|
+
| Vector4
|
|
61
|
+
| Matrix3
|
|
62
|
+
| Matrix4
|
|
63
|
+
>;
|
|
64
|
+
|
|
65
|
+
type UniformType<ValueT extends UniformValue> = ValueT extends number | boolean
|
|
66
|
+
? 'f32' | 'i32' | 'u32'
|
|
67
|
+
: ValueT extends Readonly<NumberArray2 | Vector2>
|
|
68
|
+
? 'vec2<f32>' | 'vec2<i32>' | 'vec2<u32>'
|
|
69
|
+
: ValueT extends Readonly<NumberArray3 | Vector3>
|
|
70
|
+
? 'vec3<f32>' | 'vec3<i32>' | 'vec3<u32>'
|
|
71
|
+
: ValueT extends Readonly<NumberArray4 | Vector4>
|
|
72
|
+
? 'vec4<f32>' | 'vec4<i32>' | 'vec4<u32>' | 'mat2x2<f32>'
|
|
73
|
+
: ValueT extends Readonly<NumberArray6>
|
|
74
|
+
? 'mat2x3<f32>' | 'mat3x2<f32>'
|
|
75
|
+
: ValueT extends Readonly<NumberArray8>
|
|
76
|
+
? 'mat2x4<f32>' | 'mat4x2<f32>'
|
|
77
|
+
: ValueT extends Readonly<NumberArray9 | Matrix3>
|
|
78
|
+
? 'mat3x3<f32>'
|
|
79
|
+
: ValueT extends Readonly<NumberArray12>
|
|
80
|
+
? 'mat3x4<f32>' | 'mat4x3<f32>'
|
|
81
|
+
: ValueT extends Readonly<NumberArray16 | Matrix4>
|
|
82
|
+
? 'mat4x4<f32>'
|
|
83
|
+
: never;
|
|
84
|
+
|
|
85
|
+
type UniformProps = {
|
|
86
|
+
[name: string]: UniformValue;
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export type UniformTypes<PropsT extends UniformProps> = {
|
|
90
|
+
[name in keyof PropsT]: UniformType<PropsT[name]>;
|
|
91
|
+
};
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import {ShaderAttributeType, ShaderLayout, log} from '@luma.gl/core';
|
|
6
|
-
import {WgslReflect} from '
|
|
6
|
+
import {WgslReflect} from 'wgsl_reflect';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Parse a ShaderLayout from WGSL shader source code.
|
|
@@ -23,10 +23,10 @@ export function getShaderLayoutFromWGSL(source: string): ShaderLayout {
|
|
|
23
23
|
|
|
24
24
|
for (const uniform of parsedWGSL.uniforms) {
|
|
25
25
|
const members = [];
|
|
26
|
-
for (const
|
|
26
|
+
for (const attribute of (uniform.type as any)?.members || []) {
|
|
27
27
|
members.push({
|
|
28
|
-
name:
|
|
29
|
-
type: getType(
|
|
28
|
+
name: attribute.name,
|
|
29
|
+
type: getType(attribute.type)
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -53,7 +53,7 @@ export function getShaderLayoutFromWGSL(source: string): ShaderLayout {
|
|
|
53
53
|
|
|
54
54
|
shaderLayout.attributes.push({
|
|
55
55
|
name: wgslAttribute.name,
|
|
56
|
-
location: wgslAttribute.location,
|
|
56
|
+
location: Number(wgslAttribute.location),
|
|
57
57
|
type
|
|
58
58
|
});
|
|
59
59
|
}
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import {NumberArray} from '../../../types';
|
|
6
5
|
import {glsl} from '../../../lib/glsl-utils/highlight';
|
|
7
6
|
import {ShaderModule} from '../../../lib/shader-module/shader-module';
|
|
7
|
+
import type {NumberArray3, NumberArray4} from '../../../lib/utils/uniform-types';
|
|
8
8
|
|
|
9
9
|
// cyan color
|
|
10
|
-
const DEFAULT_HIGHLIGHT_COLOR =
|
|
10
|
+
const DEFAULT_HIGHLIGHT_COLOR: NumberArray4 = [0, 1, 1, 1];
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Props for the picking module, which depending on mode renders picking colors or highlighted item.
|
|
@@ -20,9 +20,9 @@ export type PickingProps = {
|
|
|
20
20
|
/** Set to true when picking an attribute value instead of object index */
|
|
21
21
|
isAttribute?: boolean;
|
|
22
22
|
/** Set to a picking color to visually highlight that item, or `null` to explicitly clear **/
|
|
23
|
-
highlightedObjectColor?:
|
|
23
|
+
highlightedObjectColor?: NumberArray3 | null;
|
|
24
24
|
/** Color of visual highlight of "selected" item */
|
|
25
|
-
highlightColor?:
|
|
25
|
+
highlightColor?: NumberArray3 | NumberArray4;
|
|
26
26
|
/** Color range 0-1 or 0-255 */
|
|
27
27
|
useFloatColors?: boolean;
|
|
28
28
|
};
|
|
@@ -45,9 +45,9 @@ export type PickingUniforms = {
|
|
|
45
45
|
/** Do we have a highlighted item? */
|
|
46
46
|
isHighlightActive?: boolean;
|
|
47
47
|
/** Set to a picking color to visually highlight that item */
|
|
48
|
-
highlightedObjectColor?:
|
|
48
|
+
highlightedObjectColor?: NumberArray3;
|
|
49
49
|
/** Color of visual highlight of "selected" item */
|
|
50
|
-
highlightColor?:
|
|
50
|
+
highlightColor?: NumberArray4;
|
|
51
51
|
};
|
|
52
52
|
|
|
53
53
|
const vs = glsl`\
|
|
@@ -207,7 +207,7 @@ export const picking: ShaderModule<PickingProps, PickingUniforms> = {
|
|
|
207
207
|
isAttribute: false,
|
|
208
208
|
isHighlightActive: false,
|
|
209
209
|
useFloatColors: true,
|
|
210
|
-
highlightedObjectColor:
|
|
210
|
+
highlightedObjectColor: [0, 0, 0],
|
|
211
211
|
highlightColor: DEFAULT_HIGHLIGHT_COLOR
|
|
212
212
|
},
|
|
213
213
|
getUniforms
|
|
@@ -222,7 +222,7 @@ function getUniforms(opts: PickingProps = {}, prevUniforms?: PickingUniforms): P
|
|
|
222
222
|
uniforms.isHighlightActive = false;
|
|
223
223
|
} else {
|
|
224
224
|
uniforms.isHighlightActive = true;
|
|
225
|
-
const highlightedObjectColor = opts.highlightedObjectColor.slice(0, 3);
|
|
225
|
+
const highlightedObjectColor = opts.highlightedObjectColor.slice(0, 3) as NumberArray3;
|
|
226
226
|
uniforms.highlightedObjectColor = highlightedObjectColor;
|
|
227
227
|
}
|
|
228
228
|
|
|
@@ -231,7 +231,7 @@ function getUniforms(opts: PickingProps = {}, prevUniforms?: PickingUniforms): P
|
|
|
231
231
|
if (!Number.isFinite(color[3])) {
|
|
232
232
|
color[3] = 1;
|
|
233
233
|
}
|
|
234
|
-
uniforms.highlightColor = color;
|
|
234
|
+
uniforms.highlightColor = color as NumberArray4;
|
|
235
235
|
}
|
|
236
236
|
|
|
237
237
|
if (opts.isActive !== undefined) {
|
|
@@ -2,20 +2,21 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import {Matrix4, Vector3} from '@math.gl/core';
|
|
6
6
|
import {ShaderModule} from '../../../lib/shader-module/shader-module';
|
|
7
7
|
import {glsl} from '../../../lib/glsl-utils/highlight';
|
|
8
|
+
import type {NumberArray3, NumberArray16} from '../../../lib/utils/uniform-types';
|
|
8
9
|
|
|
9
|
-
const IDENTITY_MATRIX: Readonly<
|
|
10
|
+
const IDENTITY_MATRIX: Readonly<NumberArray16> = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* @note Projection uniforms are normally constant across draw calls,
|
|
13
14
|
* at least for each view.
|
|
14
15
|
*/
|
|
15
16
|
export type ProjectionProps = {
|
|
16
|
-
viewMatrix?: Readonly<Matrix4 |
|
|
17
|
-
projectionMatrix?: Readonly<Matrix4 |
|
|
18
|
-
cameraPositionWorld?: Readonly<Vector3 |
|
|
17
|
+
viewMatrix?: Readonly<Matrix4 | NumberArray16>;
|
|
18
|
+
projectionMatrix?: Readonly<Matrix4 | NumberArray16>;
|
|
19
|
+
cameraPositionWorld?: Readonly<Vector3 | NumberArray3>;
|
|
19
20
|
};
|
|
20
21
|
|
|
21
22
|
/**
|
|
@@ -23,10 +24,10 @@ export type ProjectionProps = {
|
|
|
23
24
|
* at least for each view.
|
|
24
25
|
*/
|
|
25
26
|
export type ProjectionUniforms = {
|
|
26
|
-
viewMatrix?: Readonly<Matrix4 |
|
|
27
|
-
projectionMatrix?: Readonly<Matrix4 |
|
|
28
|
-
viewProjectionMatrix?: Readonly<Matrix4 |
|
|
29
|
-
cameraPositionWorld?: Readonly<Vector3 |
|
|
27
|
+
viewMatrix?: Readonly<Matrix4 | NumberArray16>;
|
|
28
|
+
projectionMatrix?: Readonly<Matrix4 | NumberArray16>;
|
|
29
|
+
viewProjectionMatrix?: Readonly<Matrix4 | NumberArray16>;
|
|
30
|
+
cameraPositionWorld?: Readonly<Vector3 | NumberArray3>;
|
|
30
31
|
};
|
|
31
32
|
|
|
32
33
|
const DEFAULT_MODULE_OPTIONS: Required<ProjectionUniforms> = {
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import type {NumberArray} from '@math.gl/types';
|
|
6
5
|
import {ShaderModule} from '../../../lib/shader-module/shader-module';
|
|
7
6
|
import {lightingUniforms} from './lighting-uniforms-glsl';
|
|
7
|
+
import type {NumberArray3} from '../../../lib/utils/uniform-types';
|
|
8
8
|
|
|
9
9
|
/** Max number of supported lights (in addition to ambient light */
|
|
10
10
|
const MAX_LIGHTS = 5;
|
|
@@ -24,23 +24,23 @@ export type Light = AmbientLight | PointLight | DirectionalLight;
|
|
|
24
24
|
|
|
25
25
|
export type AmbientLight = {
|
|
26
26
|
type: 'ambient';
|
|
27
|
-
color?: Readonly<
|
|
27
|
+
color?: Readonly<NumberArray3>;
|
|
28
28
|
intensity?: number;
|
|
29
29
|
};
|
|
30
30
|
|
|
31
31
|
export type PointLight = {
|
|
32
32
|
type: 'point';
|
|
33
|
-
position: Readonly<
|
|
34
|
-
color?: Readonly<
|
|
33
|
+
position: Readonly<NumberArray3>;
|
|
34
|
+
color?: Readonly<NumberArray3>;
|
|
35
35
|
intensity?: number;
|
|
36
36
|
attenuation?: number;
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
export type DirectionalLight = {
|
|
40
40
|
type: 'directional';
|
|
41
|
-
position: Readonly<
|
|
42
|
-
direction: Readonly<
|
|
43
|
-
color?: Readonly<
|
|
41
|
+
position: Readonly<NumberArray3>;
|
|
42
|
+
direction: Readonly<NumberArray3>;
|
|
43
|
+
color?: Readonly<NumberArray3>;
|
|
44
44
|
intensity?: number;
|
|
45
45
|
};
|
|
46
46
|
|
|
@@ -57,17 +57,17 @@ export type LightingProps = {
|
|
|
57
57
|
|
|
58
58
|
export type LightingUniforms = {
|
|
59
59
|
enabled: number;
|
|
60
|
-
ambientLightColor: Readonly<
|
|
60
|
+
ambientLightColor: Readonly<NumberArray3>;
|
|
61
61
|
numberOfLights: number;
|
|
62
62
|
lightType: number; // [];
|
|
63
|
-
lightColor: Readonly<
|
|
64
|
-
lightPosition: Readonly<
|
|
65
|
-
lightDirection: Readonly<
|
|
66
|
-
lightAttenuation: Readonly<
|
|
63
|
+
lightColor: Readonly<NumberArray3>; // [];
|
|
64
|
+
lightPosition: Readonly<NumberArray3>; // [];
|
|
65
|
+
lightDirection: Readonly<NumberArray3>; // [];
|
|
66
|
+
lightAttenuation: Readonly<NumberArray3>; // [];
|
|
67
67
|
};
|
|
68
68
|
|
|
69
69
|
/** UBO ready lighting module */
|
|
70
|
-
export const lighting: ShaderModule<LightingProps, LightingUniforms> = {
|
|
70
|
+
export const lighting: ShaderModule<LightingProps, LightingUniforms, {}> = {
|
|
71
71
|
name: 'lighting',
|
|
72
72
|
vs: lightingUniforms,
|
|
73
73
|
fs: lightingUniforms,
|
|
@@ -217,8 +217,8 @@ function extractLightTypes(lights: Light[]): LightingProps {
|
|
|
217
217
|
|
|
218
218
|
/** Take color 0-255 and intensity as input and output 0.0-1.0 range */
|
|
219
219
|
function convertColor(
|
|
220
|
-
colorDef: {color?: Readonly<
|
|
221
|
-
):
|
|
220
|
+
colorDef: {color?: Readonly<NumberArray3>; intensity?: number} = {}
|
|
221
|
+
): NumberArray3 {
|
|
222
222
|
const {color = [0, 0, 0], intensity = 1.0} = colorDef;
|
|
223
|
-
return color.map(component => (component * intensity) / COLOR_FACTOR);
|
|
223
|
+
return color.map(component => (component * intensity) / COLOR_FACTOR) as NumberArray3;
|
|
224
224
|
}
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import type {
|
|
5
|
+
import type {Vector3} from '@math.gl/core';
|
|
6
6
|
import {glsl} from '../../../lib/glsl-utils/highlight';
|
|
7
7
|
import {ShaderModule} from '../../../lib/shader-module/shader-module';
|
|
8
8
|
|
|
9
9
|
export type DirlightProps = {
|
|
10
|
-
lightDirection?:
|
|
10
|
+
lightDirection?: Vector3 | [number, number, number];
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
export type DirlightUniforms = DirlightProps;
|
|
@@ -72,7 +72,7 @@ export const dirlight: ShaderModule<DirlightProps, DirlightUniforms> = {
|
|
|
72
72
|
lightDirection: 'vec3<f32>'
|
|
73
73
|
},
|
|
74
74
|
defaultUniforms: {
|
|
75
|
-
lightDirection:
|
|
75
|
+
lightDirection: [1, 1, 2]
|
|
76
76
|
},
|
|
77
77
|
getUniforms
|
|
78
78
|
};
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
/* eslint-disable camelcase */
|
|
6
6
|
|
|
7
|
-
import type {
|
|
7
|
+
import type {Texture} from '@luma.gl/core';
|
|
8
8
|
import type {Vector2, Vector3, Vector4} from '@math.gl/core';
|
|
9
|
+
import type {NumberArray2, NumberArray3, NumberArray4} from '../../../lib/utils/uniform-types';
|
|
9
10
|
|
|
10
11
|
import {ShaderModule} from '../../../lib/shader-module/shader-module';
|
|
11
12
|
import {lighting} from '../lights/lighting-uniforms';
|
|
@@ -18,15 +19,15 @@ export type PBRMaterialProps = PBRMaterialBindings & {
|
|
|
18
19
|
|
|
19
20
|
// Base color map
|
|
20
21
|
baseColorMapEnabled: boolean;
|
|
21
|
-
baseColorFactor: Readonly<Vector4 |
|
|
22
|
+
baseColorFactor: Readonly<Vector4 | NumberArray4>;
|
|
22
23
|
|
|
23
24
|
normalMapEnabled: boolean;
|
|
24
25
|
normalScale: number; // #ifdef HAS_NORMALMAP
|
|
25
26
|
|
|
26
27
|
emissiveMapEnabled: boolean;
|
|
27
|
-
emissiveFactor: Readonly<Vector3 |
|
|
28
|
+
emissiveFactor: Readonly<Vector3 | NumberArray3>; // #ifdef HAS_EMISSIVEMAP
|
|
28
29
|
|
|
29
|
-
metallicRoughnessValues: Readonly<Vector2 |
|
|
30
|
+
metallicRoughnessValues: Readonly<Vector2 | NumberArray2>;
|
|
30
31
|
metallicRoughnessMapEnabled: boolean;
|
|
31
32
|
|
|
32
33
|
occlusionMapEnabled: boolean;
|
|
@@ -37,12 +38,12 @@ export type PBRMaterialProps = PBRMaterialBindings & {
|
|
|
37
38
|
|
|
38
39
|
// IBL
|
|
39
40
|
IBLenabled: boolean;
|
|
40
|
-
scaleIBLAmbient: Readonly<Vector2 |
|
|
41
|
+
scaleIBLAmbient: Readonly<Vector2 | NumberArray2>; // #ifdef USE_IBL
|
|
41
42
|
|
|
42
43
|
// debugging flags used for shader output of intermediate PBR variables
|
|
43
44
|
// #ifdef PBR_DEBUG
|
|
44
|
-
scaleDiffBaseMR: Readonly<Vector4 |
|
|
45
|
-
scaleFGDSpec: Readonly<Vector4 |
|
|
45
|
+
scaleDiffBaseMR: Readonly<Vector4 | NumberArray4>;
|
|
46
|
+
scaleFGDSpec: Readonly<Vector4 | NumberArray4>;
|
|
46
47
|
};
|
|
47
48
|
|
|
48
49
|
/** Non-uniform block bindings for pbr module */
|
|
@@ -65,15 +66,15 @@ export type PBRMaterialUniforms = {
|
|
|
65
66
|
|
|
66
67
|
// Base color map
|
|
67
68
|
baseColorMapEnabled: boolean;
|
|
68
|
-
baseColorFactor: Readonly<Vector4 |
|
|
69
|
+
baseColorFactor: Readonly<Vector4 | NumberArray4>;
|
|
69
70
|
|
|
70
71
|
normalMapEnabled: boolean;
|
|
71
72
|
normalScale: number; // #ifdef HAS_NORMALMAP
|
|
72
73
|
|
|
73
74
|
emissiveMapEnabled: boolean;
|
|
74
|
-
emissiveFactor: Readonly<Vector3 |
|
|
75
|
+
emissiveFactor: Readonly<Vector3 | NumberArray3>; // #ifdef HAS_EMISSIVEMAP
|
|
75
76
|
|
|
76
|
-
metallicRoughnessValues: Readonly<Vector2 |
|
|
77
|
+
metallicRoughnessValues: Readonly<Vector2 | NumberArray2>;
|
|
77
78
|
metallicRoughnessMapEnabled: boolean;
|
|
78
79
|
|
|
79
80
|
occlusionMapEnabled: boolean;
|
|
@@ -84,12 +85,12 @@ export type PBRMaterialUniforms = {
|
|
|
84
85
|
|
|
85
86
|
// IBL
|
|
86
87
|
IBLenabled: boolean;
|
|
87
|
-
scaleIBLAmbient: Readonly<Vector2 |
|
|
88
|
+
scaleIBLAmbient: Readonly<Vector2 | NumberArray2>; // #ifdef USE_IBL
|
|
88
89
|
|
|
89
90
|
// debugging flags used for shader output of intermediate PBR variables
|
|
90
91
|
// #ifdef PBR_DEBUG
|
|
91
|
-
scaleDiffBaseMR: Readonly<Vector4 |
|
|
92
|
-
scaleFGDSpec: Readonly<Vector4 |
|
|
92
|
+
scaleDiffBaseMR: Readonly<Vector4 | NumberArray4>;
|
|
93
|
+
scaleFGDSpec: Readonly<Vector4 | NumberArray4>;
|
|
93
94
|
};
|
|
94
95
|
|
|
95
96
|
/**
|
|
@@ -143,16 +144,5 @@ export const pbrMaterial: ShaderModule<PBRMaterialProps, PBRMaterialUniforms> =
|
|
|
143
144
|
scaleDiffBaseMR: 'vec4<f32>',
|
|
144
145
|
scaleFGDSpec: 'vec4<f32>'
|
|
145
146
|
},
|
|
146
|
-
bindings: {
|
|
147
|
-
baseColorSampler: {type: 'texture', location: 8}, // #ifdef HAS_BASECOLORMAP
|
|
148
|
-
normalSampler: {type: 'texture', location: 9}, // #ifdef HAS_NORMALMAP
|
|
149
|
-
emissiveSampler: {type: 'texture', location: 10}, // #ifdef HAS_EMISSIVEMAP
|
|
150
|
-
metallicRoughnessSampler: {type: 'texture', location: 11}, // #ifdef HAS_METALROUGHNESSMAP
|
|
151
|
-
occlusionSampler: {type: 'texture', location: 12}, // #ifdef HAS_OCCLUSIONMAP
|
|
152
|
-
// IBL Samplers
|
|
153
|
-
diffuseEnvSampler: {type: 'texture', location: 13}, // #ifdef USE_IBL (samplerCube)
|
|
154
|
-
specularEnvSampler: {type: 'texture', location: 14}, // #ifdef USE_IBL (samplerCube)
|
|
155
|
-
brdfLUT: {type: 'texture', location: 15} // #ifdef USE_IBL
|
|
156
|
-
},
|
|
157
147
|
dependencies: [lighting]
|
|
158
148
|
};
|
|
@@ -58,9 +58,9 @@ vec4 tiltShift_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
|
|
|
58
58
|
*/
|
|
59
59
|
export type TiltShiftProps = {
|
|
60
60
|
/** The x,y coordinate of the start of the line segment. */
|
|
61
|
-
start?: number
|
|
61
|
+
start?: [number, number];
|
|
62
62
|
/** The xm y coordinate of the end of the line segment. */
|
|
63
|
-
end?: number
|
|
63
|
+
end?: [number, number];
|
|
64
64
|
/** The maximum radius of the pyramid blur. */
|
|
65
65
|
blurRadius?: number;
|
|
66
66
|
/** The distance from the line at which the maximum blur radius is reached. */
|
|
@@ -45,7 +45,7 @@ vec4 zoomBlur_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) {
|
|
|
45
45
|
*/
|
|
46
46
|
export type ZoomBlurProps = {
|
|
47
47
|
/** - The x, y coordinate of the blur origin. */
|
|
48
|
-
center?: number
|
|
48
|
+
center?: [number, number];
|
|
49
49
|
/** - The strength of the blur. Values in the range 0 to 1 are usually sufficient, where 0 doesn't change the image and 1 creates a highly blurred image. */
|
|
50
50
|
strength?: number;
|
|
51
51
|
};
|
|
@@ -51,7 +51,7 @@ vec4 colorHalftone_filterColor(vec4 color, vec2 texSize, vec2 texCoord) {
|
|
|
51
51
|
*/
|
|
52
52
|
export type ColorHalftoneProps = {
|
|
53
53
|
/** The x,y coordinate of the pattern origin. */
|
|
54
|
-
center?: number
|
|
54
|
+
center?: [number, number];
|
|
55
55
|
/** The rotation of the pattern in radians. */
|
|
56
56
|
angle?: number;
|
|
57
57
|
/** The diameter of a dot in pixels. */
|
|
@@ -37,7 +37,7 @@ vec4 dotScreen_filterColor(vec4 color, vec2 texSize, vec2 texCoord) {
|
|
|
37
37
|
*/
|
|
38
38
|
export type DotScreenProps = {
|
|
39
39
|
/** The x, y coordinate of the pattern origin. */
|
|
40
|
-
center?: number
|
|
40
|
+
center?: [number, number];
|
|
41
41
|
/** The rotation of the pattern in radians. */
|
|
42
42
|
angle?: number;
|
|
43
43
|
/** The diameter of a dot in pixels. */
|
|
@@ -57,7 +57,7 @@ vec4 hexagonalPixelate_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord
|
|
|
57
57
|
*/
|
|
58
58
|
export type HexagonalPixelateProps = {
|
|
59
59
|
/** The [x, y] coordinates of the pattern center. */
|
|
60
|
-
center?: number
|
|
60
|
+
center?: [number, number];
|
|
61
61
|
/** The width of an individual tile, in pixels. */
|
|
62
62
|
scale?: number;
|
|
63
63
|
};
|