@luma.gl/shadertools 9.1.0-alpha.16 → 9.1.0-alpha.18
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 +277 -344
- package/dist/dist.min.js +215 -314
- package/dist/index.cjs +276 -346
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/lib/shader-module/shader-module.d.ts +24 -14
- package/dist/lib/shader-module/shader-module.d.ts.map +1 -1
- package/dist/lib/shader-module/shader-module.js +11 -15
- 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 +11 -0
- package/dist/lib/utils/uniform-types.d.ts.map +1 -0
- package/dist/lib/utils/uniform-types.js +1 -0
- package/dist/modules/engine/picking/picking.d.ts +7 -7
- 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/gouraud-material/gouraud-material.d.ts +3 -57
- package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts.map +1 -1
- package/dist/modules/lighting/gouraud-material/gouraud-material.js +9 -6
- 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 +35 -12
- package/dist/modules/lighting/lights/lighting.d.ts +55 -29
- package/dist/modules/lighting/lights/lighting.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting.js +46 -35
- package/dist/modules/lighting/no-material/dirlight.d.ts +3 -3
- 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-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 +56 -60
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts +56 -98
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material.js +14 -22
- package/dist/modules/lighting/pbr-material/pbr-projection.d.ts +10 -0
- package/dist/modules/lighting/pbr-material/pbr-projection.d.ts.map +1 -0
- package/dist/modules/lighting/pbr-material/pbr-projection.js +24 -0
- 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 +8 -16
- package/dist/modules/lighting/phong-material/phong-material.d.ts +5 -59
- package/dist/modules/lighting/phong-material/phong-material.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-material.js +6 -4
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts +1 -40
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.js +8 -87
- package/dist/modules-webgl1/project/project.d.ts +6 -4
- package/dist/modules-webgl1/project/project.d.ts.map +1 -1
- package/dist/passes/postprocessing/fxaa/fxaa.d.ts +1 -1
- package/dist/passes/postprocessing/fxaa/fxaa.d.ts.map +1 -1
- package/dist/passes/postprocessing/fxaa/fxaa.js +1 -1
- package/dist/passes/postprocessing/image-adjust-filters/brightnesscontrast.d.ts +0 -1
- package/dist/passes/postprocessing/image-adjust-filters/brightnesscontrast.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-adjust-filters/brightnesscontrast.js +0 -1
- package/dist/passes/postprocessing/image-adjust-filters/huesaturation.d.ts +0 -1
- package/dist/passes/postprocessing/image-adjust-filters/huesaturation.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-adjust-filters/huesaturation.js +0 -1
- package/dist/passes/postprocessing/image-adjust-filters/vibrance.d.ts +3 -0
- package/dist/passes/postprocessing/image-adjust-filters/vibrance.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-adjust-filters/vibrance.js +3 -0
- package/dist/passes/postprocessing/image-blur-filters/tiltshift.d.ts +2 -2
- package/dist/passes/postprocessing/image-blur-filters/tiltshift.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-blur-filters/triangleblur.d.ts +1 -1
- package/dist/passes/postprocessing/image-blur-filters/triangleblur.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-blur-filters/zoomblur.d.ts +1 -1
- package/dist/passes/postprocessing/image-blur-filters/zoomblur.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-fun-filters/colorhalftone.d.ts +1 -1
- package/dist/passes/postprocessing/image-fun-filters/colorhalftone.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-fun-filters/dotscreen.d.ts +1 -1
- package/dist/passes/postprocessing/image-fun-filters/dotscreen.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-fun-filters/edgework.d.ts +15 -11
- package/dist/passes/postprocessing/image-fun-filters/edgework.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-fun-filters/edgework.js +24 -12
- package/dist/passes/postprocessing/image-fun-filters/hexagonalpixelate.d.ts +1 -1
- package/dist/passes/postprocessing/image-fun-filters/hexagonalpixelate.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-fun-filters/magnify.d.ts +2 -2
- package/dist/passes/postprocessing/image-fun-filters/magnify.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-warp-filters/bulgepinch.d.ts +1 -1
- package/dist/passes/postprocessing/image-warp-filters/bulgepinch.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +9 -3
- package/src/lib/shader-module/shader-module.ts +31 -20
- package/src/lib/shader-module/shader-pass.ts +7 -4
- package/src/lib/utils/uniform-types.ts +66 -0
- package/src/modules/engine/picking/picking.ts +9 -9
- package/src/modules/engine/project/project.ts +10 -9
- package/src/modules/lighting/gouraud-material/gouraud-material.ts +14 -12
- package/src/modules/lighting/lights/lighting-uniforms-glsl.ts +35 -12
- package/src/modules/lighting/lights/lighting.ts +83 -54
- package/src/modules/lighting/no-material/dirlight.ts +3 -3
- package/src/modules/lighting/pbr-material/pbr-fragment-glsl.ts +56 -60
- package/src/modules/lighting/pbr-material/pbr-material.ts +40 -74
- package/src/modules/lighting/pbr-material/pbr-projection.ts +39 -0
- package/src/modules/lighting/pbr-material/pbr-vertex-glsl.ts +8 -16
- package/src/modules/lighting/phong-material/phong-material.ts +12 -12
- package/src/modules/lighting/phong-material/phong-shaders-glsl.ts +8 -88
- package/src/modules-webgl1/project/project.ts +8 -7
- package/src/passes/postprocessing/fxaa/fxaa.ts +2 -2
- package/src/passes/postprocessing/image-adjust-filters/brightnesscontrast.ts +0 -1
- package/src/passes/postprocessing/image-adjust-filters/huesaturation.ts +0 -1
- package/src/passes/postprocessing/image-adjust-filters/vibrance.ts +3 -0
- package/src/passes/postprocessing/image-blur-filters/tiltshift.ts +2 -2
- package/src/passes/postprocessing/image-blur-filters/triangleblur.ts +1 -1
- package/src/passes/postprocessing/image-blur-filters/zoomblur.ts +1 -1
- package/src/passes/postprocessing/image-fun-filters/colorhalftone.ts +1 -1
- package/src/passes/postprocessing/image-fun-filters/dotscreen.ts +1 -1
- package/src/passes/postprocessing/image-fun-filters/edgework.ts +26 -15
- package/src/passes/postprocessing/image-fun-filters/hexagonalpixelate.ts +1 -1
- package/src/passes/postprocessing/image-fun-filters/magnify.ts +2 -2
- package/src/passes/postprocessing/image-warp-filters/bulgepinch.ts +1 -1
- package/dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.d.ts +0 -42
- package/dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.d.ts.map +0 -1
- package/dist/modules/lighting/gouraud-material/gouraud-shaders-glsl.js +0 -134
- package/src/modules/lighting/gouraud-material/gouraud-shaders-glsl.ts +0 -137
package/src/index.ts
CHANGED
|
@@ -77,11 +77,17 @@ export {picking} from './modules/engine/picking/picking';
|
|
|
77
77
|
export type {LightingProps, LightingUniforms} from './modules/lighting/lights/lighting';
|
|
78
78
|
export {lighting} from './modules/lighting/lights/lighting';
|
|
79
79
|
export {dirlight} from './modules/lighting/no-material/dirlight';
|
|
80
|
-
export type {
|
|
80
|
+
export type {GouraudMaterialProps} from './modules/lighting/gouraud-material/gouraud-material';
|
|
81
81
|
export {gouraudMaterial} from './modules/lighting/gouraud-material/gouraud-material';
|
|
82
|
-
export type {
|
|
82
|
+
export type {PhongMaterialProps} from './modules/lighting/phong-material/phong-material';
|
|
83
83
|
export {phongMaterial} from './modules/lighting/phong-material/phong-material';
|
|
84
|
-
|
|
84
|
+
export type {
|
|
85
|
+
PBRMaterialBindings,
|
|
86
|
+
PBRMaterialProps,
|
|
87
|
+
PBRMaterialUniforms
|
|
88
|
+
} from './modules/lighting/pbr-material/pbr-material';
|
|
89
|
+
export type {PBRProjectionProps} from './modules/lighting/pbr-material/pbr-projection';
|
|
90
|
+
|
|
85
91
|
export {pbrMaterial} from './modules/lighting/pbr-material/pbr-material';
|
|
86
92
|
|
|
87
93
|
// POST PROCESSING / SHADER PASS MODULES
|
|
@@ -2,39 +2,50 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import
|
|
6
|
-
import {Sampler, Texture} from '@luma.gl/core';
|
|
7
|
-
import type {UniformFormat} from '../../types';
|
|
5
|
+
import {UniformFormat} from '../../types';
|
|
8
6
|
import {
|
|
9
7
|
PropType,
|
|
10
8
|
PropValidator,
|
|
11
9
|
makePropValidators,
|
|
12
10
|
getValidatedProperties
|
|
13
11
|
} from '../filters/prop-types';
|
|
12
|
+
import type {UniformTypes, UniformValue} from '../utils/uniform-types';
|
|
14
13
|
import {ShaderInjection, normalizeInjections} from '../shader-assembly/shader-injections';
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
//
|
|
15
|
+
// To avoid dependency on core module, do not import `Binding` type.
|
|
16
|
+
// The ShaderModule is not concerned with the type of `Binding`,
|
|
17
|
+
// it is the repsonsibility of `splitUniformsAndBindings` in
|
|
18
|
+
// ShaderInputs to type the result of `getUniforms()`
|
|
19
|
+
type Binding = unknown; // import type {Binding} from '@luma.gl/core';
|
|
19
20
|
|
|
20
21
|
export type UniformInfo = {
|
|
21
22
|
format?: UniformFormat;
|
|
22
23
|
} & PropType;
|
|
23
24
|
|
|
25
|
+
// Helper types
|
|
26
|
+
type BindingKeys<T> = {[K in keyof T]: T[K] extends UniformValue ? never : K}[keyof T];
|
|
27
|
+
type UniformKeys<T> = {[K in keyof T]: T[K] extends UniformValue ? K : never}[keyof T];
|
|
28
|
+
export type PickBindings<T> = {[K in BindingKeys<Required<T>>]: T[K]};
|
|
29
|
+
export type PickUniforms<T> = {[K in UniformKeys<Required<T>>]: T[K]};
|
|
30
|
+
|
|
24
31
|
/**
|
|
25
32
|
* A shader module definition object
|
|
26
33
|
*
|
|
27
34
|
* @note Needs to be initialized with `initializeShaderModules`
|
|
35
|
+
* @note `UniformsT` & `BindingsT` are deduced from `PropsT` by default. If
|
|
36
|
+
* a custom type for `UniformsT` is used, `BindingsT` should be also be provided.
|
|
28
37
|
*/
|
|
29
38
|
export type ShaderModule<
|
|
30
|
-
PropsT extends Record<string,
|
|
31
|
-
UniformsT extends Record<string, UniformValue> =
|
|
32
|
-
BindingsT extends Record<string,
|
|
39
|
+
PropsT extends Record<string, any> = Record<string, any>,
|
|
40
|
+
UniformsT extends Record<string, UniformValue> = PickUniforms<PropsT>,
|
|
41
|
+
BindingsT extends Record<string, Binding> = PickBindings<PropsT>
|
|
33
42
|
> = {
|
|
34
43
|
/** Used for type inference not for values */
|
|
35
44
|
props?: PropsT;
|
|
36
45
|
/** Used for type inference, not currently used for values */
|
|
37
46
|
uniforms?: UniformsT;
|
|
47
|
+
/** Used for type inference, not currently used for values */
|
|
48
|
+
bindings?: BindingsT;
|
|
38
49
|
|
|
39
50
|
name: string;
|
|
40
51
|
|
|
@@ -46,17 +57,17 @@ export type ShaderModule<
|
|
|
46
57
|
vs?: string;
|
|
47
58
|
|
|
48
59
|
/** Uniform shader types @note: Both order and types MUST match uniform block declarations in shader */
|
|
49
|
-
uniformTypes?: Record<keyof UniformsT, UniformFormat>;
|
|
60
|
+
uniformTypes?: Required<UniformTypes<UniformsT>>; // Record<keyof UniformsT, UniformFormat>;
|
|
50
61
|
/** Uniform JS prop types */
|
|
51
62
|
propTypes?: Record<keyof UniformsT, UniformInfo>;
|
|
52
63
|
/** Default uniform values */
|
|
53
64
|
defaultUniforms?: Required<UniformsT>; // Record<keyof UniformsT, UniformValue>;
|
|
54
65
|
|
|
55
66
|
/** Function that maps props to uniforms & bindings */
|
|
56
|
-
getUniforms?: (
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
67
|
+
getUniforms?: (
|
|
68
|
+
props: Partial<PropsT>,
|
|
69
|
+
prevUniforms?: UniformsT
|
|
70
|
+
) => Partial<UniformsT & BindingsT>;
|
|
60
71
|
|
|
61
72
|
defines?: Record<string, string | number>;
|
|
62
73
|
/** Injections */
|
|
@@ -117,9 +128,10 @@ export function initializeShaderModule(module: ShaderModule): void {
|
|
|
117
128
|
|
|
118
129
|
module.instance = instance;
|
|
119
130
|
|
|
120
|
-
|
|
131
|
+
// TODO(ib) - we need to apply the original prop types to the default uniforms
|
|
132
|
+
let defaultProps: ShaderModule['props'] = {};
|
|
121
133
|
if (propTypes) {
|
|
122
|
-
|
|
134
|
+
defaultProps = Object.entries(propTypes).reduce(
|
|
123
135
|
(obj: ShaderModule['props'], [key, propType]) => {
|
|
124
136
|
// @ts-expect-error
|
|
125
137
|
const value = propType?.value;
|
|
@@ -131,10 +143,9 @@ export function initializeShaderModule(module: ShaderModule): void {
|
|
|
131
143
|
},
|
|
132
144
|
{} as ShaderModule['props']
|
|
133
145
|
);
|
|
134
|
-
const defaultUniforms = getShaderModuleUniforms(module, defaultProps);
|
|
135
|
-
module.defaultUniforms = {...module.defaultUniforms, ...defaultUniforms} as any;
|
|
136
146
|
}
|
|
137
|
-
|
|
147
|
+
|
|
148
|
+
module.defaultUniforms = {...module.defaultUniforms, ...defaultProps} as any;
|
|
138
149
|
}
|
|
139
150
|
|
|
140
151
|
/** Convert module props to uniforms */
|
|
@@ -144,7 +155,7 @@ export function getShaderModuleUniforms<
|
|
|
144
155
|
module: ShaderModuleT,
|
|
145
156
|
props?: ShaderModuleT['props'],
|
|
146
157
|
oldUniforms?: ShaderModuleT['uniforms']
|
|
147
|
-
): Record<string,
|
|
158
|
+
): Record<string, Binding | UniformValue> {
|
|
148
159
|
initializeShaderModule(module);
|
|
149
160
|
|
|
150
161
|
const uniforms = oldUniforms || {...module.defaultUniforms};
|
|
@@ -2,7 +2,9 @@
|
|
|
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 ShaderModule that can be run "standalone" (e.g. post processing effects)
|
|
@@ -10,9 +12,10 @@ import type {ShaderModule, UniformValue} from './shader-module';
|
|
|
10
12
|
* A ShaderPass can require one or more sub passes.
|
|
11
13
|
*/
|
|
12
14
|
export type ShaderPass<
|
|
13
|
-
PropsT extends Record<string,
|
|
14
|
-
UniformsT extends Record<string, UniformValue> =
|
|
15
|
-
|
|
15
|
+
PropsT extends Record<string, any> = Record<string, any>,
|
|
16
|
+
UniformsT extends Record<string, UniformValue> = PickUniforms<PropsT>,
|
|
17
|
+
BindingsT extends Record<string, Binding> = PickBindings<PropsT>
|
|
18
|
+
> = ShaderModule<PropsT, UniformsT, BindingsT> & {
|
|
16
19
|
/** A shader pass can run multiple sub passes */
|
|
17
20
|
passes?: ShaderSubPass<UniformsT>[];
|
|
18
21
|
// TODO better name
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Matrix3,
|
|
3
|
+
Matrix4,
|
|
4
|
+
Vector2,
|
|
5
|
+
Vector3,
|
|
6
|
+
Vector4,
|
|
7
|
+
NumberArray2,
|
|
8
|
+
NumberArray3,
|
|
9
|
+
NumberArray4,
|
|
10
|
+
NumberArray6,
|
|
11
|
+
NumberArray8,
|
|
12
|
+
NumberArray9,
|
|
13
|
+
NumberArray12,
|
|
14
|
+
NumberArray16
|
|
15
|
+
} from '@math.gl/core';
|
|
16
|
+
|
|
17
|
+
/*
|
|
18
|
+
* Allowed types to be used for uniform values
|
|
19
|
+
*
|
|
20
|
+
* Only allow types whose length we can type-check (not `TypedArray`)
|
|
21
|
+
*/
|
|
22
|
+
export type UniformValue = Readonly<
|
|
23
|
+
| number
|
|
24
|
+
| boolean
|
|
25
|
+
| NumberArray2
|
|
26
|
+
| NumberArray3
|
|
27
|
+
| NumberArray4
|
|
28
|
+
| NumberArray6
|
|
29
|
+
| NumberArray8
|
|
30
|
+
| NumberArray9
|
|
31
|
+
| NumberArray12
|
|
32
|
+
| NumberArray16
|
|
33
|
+
| Vector2
|
|
34
|
+
| Vector3
|
|
35
|
+
| Vector4
|
|
36
|
+
| Matrix3
|
|
37
|
+
| Matrix4
|
|
38
|
+
>;
|
|
39
|
+
|
|
40
|
+
type UniformType<ValueT extends UniformValue> = ValueT extends number | boolean
|
|
41
|
+
? 'f32' | 'i32' | 'u32'
|
|
42
|
+
: ValueT extends Readonly<NumberArray2 | Vector2>
|
|
43
|
+
? 'vec2<f32>' | 'vec2<i32>' | 'vec2<u32>'
|
|
44
|
+
: ValueT extends Readonly<NumberArray3 | Vector3>
|
|
45
|
+
? 'vec3<f32>' | 'vec3<i32>' | 'vec3<u32>'
|
|
46
|
+
: ValueT extends Readonly<NumberArray4 | Vector4>
|
|
47
|
+
? 'vec4<f32>' | 'vec4<i32>' | 'vec4<u32>' | 'mat2x2<f32>'
|
|
48
|
+
: ValueT extends Readonly<NumberArray6>
|
|
49
|
+
? 'mat2x3<f32>' | 'mat3x2<f32>'
|
|
50
|
+
: ValueT extends Readonly<NumberArray8>
|
|
51
|
+
? 'mat2x4<f32>' | 'mat4x2<f32>'
|
|
52
|
+
: ValueT extends Readonly<NumberArray9 | Matrix3>
|
|
53
|
+
? 'mat3x3<f32>'
|
|
54
|
+
: ValueT extends Readonly<NumberArray12>
|
|
55
|
+
? 'mat3x4<f32>' | 'mat4x3<f32>'
|
|
56
|
+
: ValueT extends Readonly<NumberArray16 | Matrix4>
|
|
57
|
+
? 'mat4x4<f32>'
|
|
58
|
+
: never;
|
|
59
|
+
|
|
60
|
+
type UniformProps = {
|
|
61
|
+
[name: string]: UniformValue;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export type UniformTypes<PropsT extends UniformProps> = {
|
|
65
|
+
[name in keyof PropsT]: UniformType<PropsT[name]>;
|
|
66
|
+
};
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import {NumericArray} from '../../../types';
|
|
6
5
|
import {ShaderModule} from '../../../lib/shader-module/shader-module';
|
|
6
|
+
import type {NumberArray3, NumberArray4} from '@math.gl/core';
|
|
7
7
|
|
|
8
8
|
// cyan color
|
|
9
|
-
const DEFAULT_HIGHLIGHT_COLOR =
|
|
9
|
+
const DEFAULT_HIGHLIGHT_COLOR: NumberArray4 = [0, 1, 1, 1];
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Props for the picking module, which depending on mode renders picking colors or highlighted item.
|
|
@@ -19,9 +19,9 @@ export type PickingProps = {
|
|
|
19
19
|
/** Set to true when picking an attribute value instead of object index */
|
|
20
20
|
isAttribute?: boolean;
|
|
21
21
|
/** Set to a picking color to visually highlight that item, or `null` to explicitly clear **/
|
|
22
|
-
highlightedObjectColor?:
|
|
22
|
+
highlightedObjectColor?: NumberArray3 | null;
|
|
23
23
|
/** Color of visual highlight of "selected" item */
|
|
24
|
-
highlightColor?:
|
|
24
|
+
highlightColor?: NumberArray3 | NumberArray4;
|
|
25
25
|
/** Color range 0-1 or 0-255 */
|
|
26
26
|
useFloatColors?: boolean;
|
|
27
27
|
};
|
|
@@ -44,9 +44,9 @@ export type PickingUniforms = {
|
|
|
44
44
|
/** Do we have a highlighted item? */
|
|
45
45
|
isHighlightActive?: boolean;
|
|
46
46
|
/** Set to a picking color to visually highlight that item */
|
|
47
|
-
highlightedObjectColor?:
|
|
47
|
+
highlightedObjectColor?: NumberArray3;
|
|
48
48
|
/** Color of visual highlight of "selected" item */
|
|
49
|
-
highlightColor?:
|
|
49
|
+
highlightColor?: NumberArray4;
|
|
50
50
|
};
|
|
51
51
|
|
|
52
52
|
const vs = /* glsl */ `\
|
|
@@ -208,7 +208,7 @@ export const picking = {
|
|
|
208
208
|
isAttribute: false,
|
|
209
209
|
isHighlightActive: false,
|
|
210
210
|
useFloatColors: true,
|
|
211
|
-
highlightedObjectColor:
|
|
211
|
+
highlightedObjectColor: [0, 0, 0],
|
|
212
212
|
highlightColor: DEFAULT_HIGHLIGHT_COLOR
|
|
213
213
|
},
|
|
214
214
|
|
|
@@ -226,7 +226,7 @@ function getUniforms(opts: PickingProps = {}, prevUniforms?: PickingUniforms): P
|
|
|
226
226
|
uniforms.isHighlightActive = false;
|
|
227
227
|
} else {
|
|
228
228
|
uniforms.isHighlightActive = true;
|
|
229
|
-
const highlightedObjectColor = opts.highlightedObjectColor.slice(0, 3);
|
|
229
|
+
const highlightedObjectColor = opts.highlightedObjectColor.slice(0, 3) as NumberArray3;
|
|
230
230
|
uniforms.highlightedObjectColor = highlightedObjectColor;
|
|
231
231
|
}
|
|
232
232
|
|
|
@@ -235,7 +235,7 @@ function getUniforms(opts: PickingProps = {}, prevUniforms?: PickingUniforms): P
|
|
|
235
235
|
if (!Number.isFinite(color[3])) {
|
|
236
236
|
color[3] = 1;
|
|
237
237
|
}
|
|
238
|
-
uniforms.highlightColor = color;
|
|
238
|
+
uniforms.highlightColor = color as NumberArray4;
|
|
239
239
|
}
|
|
240
240
|
|
|
241
241
|
if (opts.isActive !== undefined) {
|
|
@@ -2,19 +2,20 @@
|
|
|
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
|
+
import type {NumberArray3, NumberArray16} from '@math.gl/core';
|
|
7
8
|
|
|
8
|
-
const IDENTITY_MATRIX: Readonly<
|
|
9
|
+
const IDENTITY_MATRIX: Readonly<NumberArray16> = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* @note Projection uniforms are normally constant across draw calls,
|
|
12
13
|
* at least for each view.
|
|
13
14
|
*/
|
|
14
15
|
export type ProjectionProps = {
|
|
15
|
-
viewMatrix?: Readonly<Matrix4 |
|
|
16
|
-
projectionMatrix?: Readonly<Matrix4 |
|
|
17
|
-
cameraPositionWorld?: Readonly<Vector3 |
|
|
16
|
+
viewMatrix?: Readonly<Matrix4 | NumberArray16>;
|
|
17
|
+
projectionMatrix?: Readonly<Matrix4 | NumberArray16>;
|
|
18
|
+
cameraPositionWorld?: Readonly<Vector3 | NumberArray3>;
|
|
18
19
|
};
|
|
19
20
|
|
|
20
21
|
/**
|
|
@@ -22,10 +23,10 @@ export type ProjectionProps = {
|
|
|
22
23
|
* at least for each view.
|
|
23
24
|
*/
|
|
24
25
|
export type ProjectionUniforms = {
|
|
25
|
-
viewMatrix?: Readonly<Matrix4 |
|
|
26
|
-
projectionMatrix?: Readonly<Matrix4 |
|
|
27
|
-
viewProjectionMatrix?: Readonly<Matrix4 |
|
|
28
|
-
cameraPositionWorld?: Readonly<Vector3 |
|
|
26
|
+
viewMatrix?: Readonly<Matrix4 | NumberArray16>;
|
|
27
|
+
projectionMatrix?: Readonly<Matrix4 | NumberArray16>;
|
|
28
|
+
viewProjectionMatrix?: Readonly<Matrix4 | NumberArray16>;
|
|
29
|
+
cameraPositionWorld?: Readonly<Vector3 | NumberArray3>;
|
|
29
30
|
};
|
|
30
31
|
|
|
31
32
|
const DEFAULT_MODULE_OPTIONS: Required<ProjectionUniforms> = {
|
|
@@ -2,13 +2,12 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
+
import {NumberArray3} from '@math.gl/types';
|
|
5
6
|
import {ShaderModule} from '../../../lib/shader-module/shader-module';
|
|
6
7
|
import {lighting} from '../lights/lighting';
|
|
7
|
-
import {
|
|
8
|
+
import {PHONG_VS, PHONG_FS} from '../phong-material/phong-shaders-glsl';
|
|
8
9
|
|
|
9
|
-
export type GouraudMaterialProps =
|
|
10
|
-
|
|
11
|
-
export type GouraudMaterialUniforms = {
|
|
10
|
+
export type GouraudMaterialProps = {
|
|
12
11
|
ambient?: number;
|
|
13
12
|
diffuse?: number;
|
|
14
13
|
/** Specularity exponent */
|
|
@@ -17,14 +16,13 @@ export type GouraudMaterialUniforms = {
|
|
|
17
16
|
};
|
|
18
17
|
|
|
19
18
|
/** In Gouraud shading, color is calculated for each triangle vertex normal, and then color is interpolated colors across the triangle */
|
|
20
|
-
export const gouraudMaterial = {
|
|
19
|
+
export const gouraudMaterial: ShaderModule<GouraudMaterialProps> = {
|
|
21
20
|
props: {} as GouraudMaterialProps,
|
|
22
|
-
uniforms: {} as GouraudMaterialUniforms,
|
|
23
21
|
|
|
24
|
-
name: '
|
|
22
|
+
name: 'gouraudMaterial',
|
|
25
23
|
// Note these are switched between phong and gouraud
|
|
26
|
-
vs:
|
|
27
|
-
fs:
|
|
24
|
+
vs: PHONG_FS.replace('phongMaterial', 'gouraudMaterial'),
|
|
25
|
+
fs: PHONG_VS.replace('phongMaterial', 'gouraudMaterial'),
|
|
28
26
|
defines: {
|
|
29
27
|
LIGHTING_VERTEX: 1
|
|
30
28
|
},
|
|
@@ -42,7 +40,11 @@ export const gouraudMaterial = {
|
|
|
42
40
|
specularColor: [0.15, 0.15, 0.15]
|
|
43
41
|
},
|
|
44
42
|
|
|
45
|
-
getUniforms(props: GouraudMaterialProps)
|
|
46
|
-
|
|
43
|
+
getUniforms(props: GouraudMaterialProps) {
|
|
44
|
+
const uniforms = {...props};
|
|
45
|
+
if (uniforms.specularColor) {
|
|
46
|
+
uniforms.specularColor = uniforms.specularColor.map(x => x / 255) as NumberArray3;
|
|
47
|
+
}
|
|
48
|
+
return {...gouraudMaterial.defaultUniforms, ...uniforms};
|
|
47
49
|
}
|
|
48
|
-
}
|
|
50
|
+
};
|
|
@@ -23,28 +23,51 @@ struct DirectionalLight {
|
|
|
23
23
|
|
|
24
24
|
uniform lightingUniforms {
|
|
25
25
|
int enabled;
|
|
26
|
-
int
|
|
26
|
+
int lightType;
|
|
27
|
+
|
|
27
28
|
int directionalLightCount;
|
|
29
|
+
int pointLightCount;
|
|
28
30
|
|
|
29
31
|
vec3 ambientColor;
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
vec3
|
|
33
|
-
vec3
|
|
34
|
-
vec3
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
33
|
+
vec3 lightColor0;
|
|
34
|
+
vec3 lightPosition0;
|
|
35
|
+
vec3 lightDirection0;
|
|
36
|
+
vec3 lightAttenuation0;
|
|
37
|
+
|
|
38
|
+
vec3 lightColor1;
|
|
39
|
+
vec3 lightPosition1;
|
|
40
|
+
vec3 lightDirection1;
|
|
41
|
+
vec3 lightAttenuation1;
|
|
42
|
+
|
|
43
|
+
vec3 lightColor2;
|
|
44
|
+
vec3 lightPosition2;
|
|
45
|
+
vec3 lightDirection2;
|
|
46
|
+
vec3 lightAttenuation2;
|
|
40
47
|
} lighting;
|
|
41
48
|
|
|
42
49
|
PointLight lighting_getPointLight(int index) {
|
|
43
|
-
|
|
50
|
+
switch (index) {
|
|
51
|
+
case 0:
|
|
52
|
+
return PointLight(lighting.lightColor0, lighting.lightPosition0, lighting.lightAttenuation0);
|
|
53
|
+
case 1:
|
|
54
|
+
return PointLight(lighting.lightColor1, lighting.lightPosition1, lighting.lightAttenuation1);
|
|
55
|
+
case 2:
|
|
56
|
+
default:
|
|
57
|
+
return PointLight(lighting.lightColor2, lighting.lightPosition2, lighting.lightAttenuation2);
|
|
58
|
+
}
|
|
44
59
|
}
|
|
45
60
|
|
|
46
61
|
DirectionalLight lighting_getDirectionalLight(int index) {
|
|
47
|
-
|
|
62
|
+
switch (index) {
|
|
63
|
+
case 0:
|
|
64
|
+
return DirectionalLight(lighting.lightColor0, lighting.lightDirection0);
|
|
65
|
+
case 1:
|
|
66
|
+
return DirectionalLight(lighting.lightColor1, lighting.lightDirection1);
|
|
67
|
+
case 2:
|
|
68
|
+
default:
|
|
69
|
+
return DirectionalLight(lighting.lightColor2, lighting.lightDirection2);
|
|
70
|
+
}
|
|
48
71
|
}
|
|
49
72
|
|
|
50
73
|
float getPointLightAttenuation(PointLight pointLight, float distance) {
|