@luma.gl/shadertools 9.2.6 → 9.3.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.dev.js +5388 -6438
- package/dist/dist.min.js +2264 -322
- package/dist/index.cjs +3601 -566
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +12 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/glsl-utils/shader-utils.js +4 -4
- package/dist/lib/glsl-utils/shader-utils.js.map +1 -1
- package/dist/lib/preprocessor/preprocessor.d.ts.map +1 -1
- package/dist/lib/preprocessor/preprocessor.js +35 -8
- package/dist/lib/preprocessor/preprocessor.js.map +1 -1
- package/dist/lib/shader-assembler.d.ts +10 -0
- package/dist/lib/shader-assembler.d.ts.map +1 -1
- package/dist/lib/shader-assembler.js +20 -3
- package/dist/lib/shader-assembler.js.map +1 -1
- package/dist/lib/shader-assembly/assemble-shaders.d.ts +23 -2
- package/dist/lib/shader-assembly/assemble-shaders.d.ts.map +1 -1
- package/dist/lib/shader-assembly/assemble-shaders.js +265 -12
- package/dist/lib/shader-assembly/assemble-shaders.js.map +1 -1
- package/dist/lib/shader-assembly/wgsl-binding-debug.d.ts +37 -0
- package/dist/lib/shader-assembly/wgsl-binding-debug.d.ts.map +1 -0
- package/dist/lib/shader-assembly/wgsl-binding-debug.js +144 -0
- package/dist/lib/shader-assembly/wgsl-binding-debug.js.map +1 -0
- package/dist/lib/shader-assembly/wgsl-binding-scan.d.ts +19 -0
- package/dist/lib/shader-assembly/wgsl-binding-scan.d.ts.map +1 -0
- package/dist/lib/shader-assembly/wgsl-binding-scan.js +151 -0
- package/dist/lib/shader-assembly/wgsl-binding-scan.js.map +1 -0
- package/dist/lib/shader-generator/glsl/generate-glsl.js +7 -4
- package/dist/lib/shader-generator/glsl/generate-glsl.js.map +1 -1
- package/dist/lib/shader-generator/wgsl/generate-wgsl.d.ts.map +1 -1
- package/dist/lib/shader-generator/wgsl/generate-wgsl.js +3 -0
- package/dist/lib/shader-generator/wgsl/generate-wgsl.js.map +1 -1
- package/dist/lib/shader-module/shader-module-uniform-layout.d.ts +91 -0
- package/dist/lib/shader-module/shader-module-uniform-layout.d.ts.map +1 -0
- package/dist/lib/shader-module/shader-module-uniform-layout.js +253 -0
- package/dist/lib/shader-module/shader-module-uniform-layout.js.map +1 -0
- package/dist/lib/shader-module/shader-module.d.ts +12 -6
- package/dist/lib/shader-module/shader-module.d.ts.map +1 -1
- package/dist/lib/shader-module/shader-module.js.map +1 -1
- package/dist/lib/utils/assert.d.ts.map +1 -1
- package/dist/lib/utils/assert.js +3 -1
- package/dist/lib/utils/assert.js.map +1 -1
- package/dist/lib/utils/uniform-types.d.ts +11 -7
- package/dist/lib/utils/uniform-types.d.ts.map +1 -1
- package/dist/modules/engine/picking/picking.d.ts +5 -2
- package/dist/modules/engine/picking/picking.d.ts.map +1 -1
- package/dist/modules/engine/picking/picking.js +5 -2
- package/dist/modules/engine/picking/picking.js.map +1 -1
- package/dist/modules/engine/project/project.d.ts +1 -1
- package/dist/modules/engine/project/project.js +1 -1
- package/dist/modules/engine/skin/skin.d.ts +30 -0
- package/dist/modules/engine/skin/skin.d.ts.map +1 -0
- package/dist/modules/engine/skin/skin.js +86 -0
- package/dist/modules/engine/skin/skin.js.map +1 -0
- package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts +1 -0
- package/dist/modules/lighting/gouraud-material/gouraud-material.d.ts.map +1 -1
- package/dist/modules/lighting/gouraud-material/gouraud-material.js +3 -0
- package/dist/modules/lighting/gouraud-material/gouraud-material.js.map +1 -1
- package/dist/modules/lighting/ibl/ibl.d.ts +26 -0
- package/dist/modules/lighting/ibl/ibl.d.ts.map +1 -0
- package/dist/modules/lighting/ibl/ibl.js +33 -0
- package/dist/modules/lighting/ibl/ibl.js.map +1 -0
- package/dist/modules/lighting/lambert-material/lambert-material.d.ts +10 -0
- package/dist/modules/lighting/lambert-material/lambert-material.d.ts.map +1 -0
- package/dist/modules/lighting/lambert-material/lambert-material.js +33 -0
- package/dist/modules/lighting/lambert-material/lambert-material.js.map +1 -0
- package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.d.ts +3 -0
- package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.d.ts.map +1 -0
- package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.js +60 -0
- package/dist/modules/lighting/lambert-material/lambert-shaders-glsl.js.map +1 -0
- package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.d.ts +2 -0
- package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.d.ts.map +1 -0
- package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.js +73 -0
- package/dist/modules/lighting/lambert-material/lambert-shaders-wgsl.js.map +1 -0
- package/dist/modules/lighting/lights/lighting-glsl.d.ts +1 -1
- package/dist/modules/lighting/lights/lighting-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting-glsl.js +44 -38
- package/dist/modules/lighting/lights/lighting-glsl.js.map +1 -1
- package/dist/modules/lighting/lights/lighting-wgsl.d.ts +1 -1
- package/dist/modules/lighting/lights/lighting-wgsl.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting-wgsl.js +46 -18
- package/dist/modules/lighting/lights/lighting-wgsl.js.map +1 -1
- package/dist/modules/lighting/lights/lighting.d.ts +104 -62
- package/dist/modules/lighting/lights/lighting.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting.js +107 -68
- package/dist/modules/lighting/lights/lighting.js.map +1 -1
- package/dist/modules/lighting/no-material/dirlight.d.ts +8 -3
- package/dist/modules/lighting/no-material/dirlight.d.ts.map +1 -1
- package/dist/modules/lighting/no-material/dirlight.js +5 -3
- package/dist/modules/lighting/no-material/dirlight.js.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material-glsl.d.ts +2 -2
- package/dist/modules/lighting/pbr-material/pbr-material-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material-glsl.js +694 -38
- package/dist/modules/lighting/pbr-material/pbr-material-glsl.js.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material-wgsl.d.ts +2 -2
- package/dist/modules/lighting/pbr-material/pbr-material-wgsl.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js +956 -109
- package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts +242 -43
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material.js +178 -2
- package/dist/modules/lighting/pbr-material/pbr-material.js.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-projection.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-projection.js +14 -2
- package/dist/modules/lighting/pbr-material/pbr-projection.js.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-scene.d.ts +40 -0
- package/dist/modules/lighting/pbr-material/pbr-scene.d.ts.map +1 -0
- package/dist/modules/lighting/pbr-material/pbr-scene.js +67 -0
- package/dist/modules/lighting/pbr-material/pbr-scene.js.map +1 -0
- package/dist/modules/lighting/phong-material/phong-material.d.ts +1 -0
- package/dist/modules/lighting/phong-material/phong-material.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-material.js +4 -0
- package/dist/modules/lighting/phong-material/phong-material.js.map +1 -1
- 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 +17 -6
- package/dist/modules/lighting/phong-material/phong-shaders-glsl.js.map +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-wgsl.d.ts +1 -40
- package/dist/modules/lighting/phong-material/phong-shaders-wgsl.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-wgsl.js +71 -76
- package/dist/modules/lighting/phong-material/phong-shaders-wgsl.js.map +1 -1
- package/dist/modules/math/fp64/fp64-arithmetic-glsl.d.ts +1 -1
- package/dist/modules/math/fp64/fp64-arithmetic-glsl.d.ts.map +1 -1
- package/dist/modules/math/fp64/fp64-arithmetic-glsl.js +42 -11
- package/dist/modules/math/fp64/fp64-arithmetic-glsl.js.map +1 -1
- package/dist/modules/math/fp64/fp64-arithmetic-wgsl.d.ts +2 -0
- package/dist/modules/math/fp64/fp64-arithmetic-wgsl.d.ts.map +1 -0
- package/dist/modules/math/fp64/fp64-arithmetic-wgsl.js +212 -0
- package/dist/modules/math/fp64/fp64-arithmetic-wgsl.js.map +1 -0
- package/dist/modules/math/fp64/fp64.d.ts +1 -0
- package/dist/modules/math/fp64/fp64.d.ts.map +1 -1
- package/dist/modules/math/fp64/fp64.js +8 -2
- package/dist/modules/math/fp64/fp64.js.map +1 -1
- 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 +2 -3
- package/dist/modules/math/random/random.js.map +1 -1
- package/package.json +4 -5
- package/src/index.ts +37 -6
- package/src/lib/glsl-utils/shader-utils.ts +4 -4
- package/src/lib/preprocessor/preprocessor.ts +44 -8
- package/src/lib/shader-assembler.ts +25 -3
- package/src/lib/shader-assembly/assemble-shaders.ts +506 -13
- package/src/lib/shader-assembly/wgsl-binding-debug.ts +227 -0
- package/src/lib/shader-assembly/wgsl-binding-scan.ts +228 -0
- package/src/lib/shader-generator/glsl/generate-glsl.ts +11 -5
- package/src/lib/shader-generator/wgsl/generate-wgsl.ts +6 -0
- package/src/lib/shader-module/shader-module-uniform-layout.ts +420 -0
- package/src/lib/shader-module/shader-module.ts +17 -7
- package/src/lib/utils/assert.ts +3 -1
- package/src/lib/utils/uniform-types.ts +24 -9
- package/src/modules/engine/picking/picking.ts +5 -2
- package/src/modules/engine/project/project.ts +1 -1
- package/src/modules/engine/skin/skin.ts +114 -0
- package/src/modules/lighting/gouraud-material/gouraud-material.ts +4 -0
- package/src/modules/lighting/ibl/ibl.ts +44 -0
- package/src/modules/lighting/lambert-material/lambert-material.ts +42 -0
- package/src/modules/lighting/lambert-material/lambert-shaders-glsl.ts +61 -0
- package/src/modules/lighting/lambert-material/lambert-shaders-wgsl.ts +73 -0
- package/src/modules/lighting/lights/lighting-glsl.ts +44 -38
- package/src/modules/lighting/lights/lighting-wgsl.ts +46 -18
- package/src/modules/lighting/lights/lighting.ts +198 -99
- package/src/modules/lighting/no-material/dirlight.ts +5 -3
- package/src/modules/lighting/pbr-material/pbr-material-glsl.ts +694 -38
- package/src/modules/lighting/pbr-material/pbr-material-wgsl.ts +956 -109
- package/src/modules/lighting/pbr-material/pbr-material.ts +294 -7
- package/src/modules/lighting/pbr-material/pbr-projection.ts +15 -2
- package/src/modules/lighting/pbr-material/pbr-scene.ts +91 -0
- package/src/modules/lighting/phong-material/phong-material.ts +5 -0
- package/src/modules/lighting/phong-material/phong-shaders-glsl.ts +17 -6
- package/src/modules/lighting/phong-material/phong-shaders-wgsl.ts +71 -77
- package/src/modules/math/fp64/fp64-arithmetic-glsl.ts +42 -11
- package/src/modules/math/fp64/fp64-arithmetic-wgsl.ts +212 -0
- package/src/modules/math/fp64/fp64.ts +9 -3
- package/src/modules/math/random/random.ts +2 -3
- package/dist/lib/wgsl/get-shader-layout-wgsl.d.ts +0 -8
- package/dist/lib/wgsl/get-shader-layout-wgsl.d.ts.map +0 -1
- package/dist/lib/wgsl/get-shader-layout-wgsl.js +0 -95
- package/dist/lib/wgsl/get-shader-layout-wgsl.js.map +0 -1
- package/src/lib/wgsl/get-shader-layout-wgsl.ts +0 -105
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {Matrix4} from '@math.gl/core';
|
|
6
|
+
|
|
7
|
+
import {ShaderModule} from '../../../lib/shader-module/shader-module';
|
|
8
|
+
|
|
9
|
+
const SKIN_MAX_JOINTS = 20;
|
|
10
|
+
|
|
11
|
+
export const source = /* wgsl */ `
|
|
12
|
+
struct skinUniforms {
|
|
13
|
+
jointMatrix: array<mat4x4<f32>, ${SKIN_MAX_JOINTS}>,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
@group(0) @binding(auto) var<uniform> skin: skinUniforms;
|
|
17
|
+
|
|
18
|
+
fn getSkinMatrix(weights: vec4f, joints: vec4u) -> mat4x4<f32> {
|
|
19
|
+
return (weights.x * skin.jointMatrix[joints.x])
|
|
20
|
+
+ (weights.y * skin.jointMatrix[joints.y])
|
|
21
|
+
+ (weights.z * skin.jointMatrix[joints.z])
|
|
22
|
+
+ (weights.w * skin.jointMatrix[joints.w]);
|
|
23
|
+
}
|
|
24
|
+
`;
|
|
25
|
+
|
|
26
|
+
export const vs = /* glsl */ `\
|
|
27
|
+
|
|
28
|
+
layout(std140) uniform skinUniforms {
|
|
29
|
+
mat4 jointMatrix[SKIN_MAX_JOINTS];
|
|
30
|
+
} skin;
|
|
31
|
+
|
|
32
|
+
mat4 getSkinMatrix(vec4 weights, uvec4 joints) {
|
|
33
|
+
return (weights.x * skin.jointMatrix[joints.x])
|
|
34
|
+
+ (weights.y * skin.jointMatrix[joints.y])
|
|
35
|
+
+ (weights.z * skin.jointMatrix[joints.z])
|
|
36
|
+
+ (weights.w * skin.jointMatrix[joints.w]);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
`;
|
|
40
|
+
|
|
41
|
+
export const fs = /* glsl */ `\
|
|
42
|
+
`;
|
|
43
|
+
|
|
44
|
+
export type SkinProps = {
|
|
45
|
+
scenegraphsFromGLTF?: any;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export type SkinUniforms = {
|
|
49
|
+
jointMatrix?: any;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const skin = {
|
|
53
|
+
props: {} as SkinProps,
|
|
54
|
+
uniforms: {} as SkinUniforms,
|
|
55
|
+
|
|
56
|
+
name: 'skin',
|
|
57
|
+
bindingLayout: [{name: 'skin', group: 0}],
|
|
58
|
+
dependencies: [],
|
|
59
|
+
source,
|
|
60
|
+
vs,
|
|
61
|
+
fs,
|
|
62
|
+
|
|
63
|
+
defines: {
|
|
64
|
+
SKIN_MAX_JOINTS
|
|
65
|
+
},
|
|
66
|
+
|
|
67
|
+
getUniforms: (props: SkinProps = {}, prevUniforms?: SkinUniforms): SkinUniforms => {
|
|
68
|
+
const {scenegraphsFromGLTF} = props;
|
|
69
|
+
|
|
70
|
+
if (!scenegraphsFromGLTF?.gltf?.skins?.[0]) {
|
|
71
|
+
return {jointMatrix: []};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const {inverseBindMatrices, joints, skeleton} = scenegraphsFromGLTF.gltf.skins[0];
|
|
75
|
+
|
|
76
|
+
const matsib = [];
|
|
77
|
+
const countib = inverseBindMatrices.value.length / 16;
|
|
78
|
+
for (let i = 0; i < countib; i++) {
|
|
79
|
+
const slice = inverseBindMatrices.value.subarray(i * 16, i * 16 + 16);
|
|
80
|
+
matsib.push(new Matrix4(Array.from(slice)));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const top = scenegraphsFromGLTF.gltfNodeIndexToNodeMap.get(skeleton);
|
|
84
|
+
const matrices: Record<string, Matrix4> = {};
|
|
85
|
+
top.preorderTraversal((node: any, {worldMatrix}: any) => {
|
|
86
|
+
matrices[node.id] = worldMatrix;
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const mats = new Float32Array(SKIN_MAX_JOINTS * 16); // 16 floats per 4x4 matrix
|
|
90
|
+
for (let i = 0; i < SKIN_MAX_JOINTS; ++i) {
|
|
91
|
+
const nodeIndex = joints[i];
|
|
92
|
+
if (nodeIndex === undefined) break;
|
|
93
|
+
|
|
94
|
+
const worldMat = matrices[scenegraphsFromGLTF.gltfNodeIndexToNodeMap.get(nodeIndex).id];
|
|
95
|
+
const invBindMat = matsib[i];
|
|
96
|
+
|
|
97
|
+
const Z = new Matrix4().copy(worldMat).multiplyRight(invBindMat);
|
|
98
|
+
|
|
99
|
+
const off = i * 16;
|
|
100
|
+
|
|
101
|
+
for (let j = 0; j < 16; j++) {
|
|
102
|
+
mats[off + j] = Z[j];
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
jointMatrix: mats
|
|
108
|
+
};
|
|
109
|
+
},
|
|
110
|
+
|
|
111
|
+
uniformTypes: {
|
|
112
|
+
jointMatrix: ['mat4x4<f32>', SKIN_MAX_JOINTS]
|
|
113
|
+
}
|
|
114
|
+
} as const satisfies ShaderModule<SkinProps, SkinUniforms>;
|
|
@@ -9,6 +9,7 @@ import {PHONG_VS, PHONG_FS} from '../phong-material/phong-shaders-glsl';
|
|
|
9
9
|
import {PHONG_WGSL} from '../phong-material/phong-shaders-wgsl';
|
|
10
10
|
|
|
11
11
|
export type GouraudMaterialProps = {
|
|
12
|
+
unlit?: boolean;
|
|
12
13
|
ambient?: number;
|
|
13
14
|
diffuse?: number;
|
|
14
15
|
/** Specularity exponent */
|
|
@@ -21,6 +22,7 @@ export const gouraudMaterial: ShaderModule<GouraudMaterialProps> = {
|
|
|
21
22
|
props: {} as GouraudMaterialProps,
|
|
22
23
|
|
|
23
24
|
name: 'gouraudMaterial',
|
|
25
|
+
bindingLayout: [{name: 'gouraudMaterial', group: 3}],
|
|
24
26
|
// Note these are switched between phong and gouraud
|
|
25
27
|
vs: PHONG_FS.replace('phongMaterial', 'gouraudMaterial'),
|
|
26
28
|
fs: PHONG_VS.replace('phongMaterial', 'gouraudMaterial'),
|
|
@@ -30,12 +32,14 @@ export const gouraudMaterial: ShaderModule<GouraudMaterialProps> = {
|
|
|
30
32
|
},
|
|
31
33
|
dependencies: [lighting],
|
|
32
34
|
uniformTypes: {
|
|
35
|
+
unlit: 'i32',
|
|
33
36
|
ambient: 'f32',
|
|
34
37
|
diffuse: 'f32',
|
|
35
38
|
shininess: 'f32',
|
|
36
39
|
specularColor: 'vec3<f32>'
|
|
37
40
|
},
|
|
38
41
|
defaultUniforms: {
|
|
42
|
+
unlit: false,
|
|
39
43
|
ambient: 0.35,
|
|
40
44
|
diffuse: 0.6,
|
|
41
45
|
shininess: 32,
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import type {Texture} from '@luma.gl/core';
|
|
6
|
+
import {ShaderModule} from '../../../lib/shader-module/shader-module';
|
|
7
|
+
|
|
8
|
+
export type IBLBindings = {
|
|
9
|
+
pbr_diffuseEnvSampler?: Texture | null;
|
|
10
|
+
pbr_specularEnvSampler?: Texture | null;
|
|
11
|
+
pbr_brdfLUT?: Texture | null;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const iblWGSL = /* wgsl */ `\
|
|
15
|
+
#ifdef USE_IBL
|
|
16
|
+
@group(2) @binding(auto) var pbr_diffuseEnvSampler: texture_cube<f32>;
|
|
17
|
+
@group(2) @binding(auto) var pbr_diffuseEnvSamplerSampler: sampler;
|
|
18
|
+
@group(2) @binding(auto) var pbr_specularEnvSampler: texture_cube<f32>;
|
|
19
|
+
@group(2) @binding(auto) var pbr_specularEnvSamplerSampler: sampler;
|
|
20
|
+
@group(2) @binding(auto) var pbr_brdfLUT: texture_2d<f32>;
|
|
21
|
+
@group(2) @binding(auto) var pbr_brdfLUTSampler: sampler;
|
|
22
|
+
#endif
|
|
23
|
+
`;
|
|
24
|
+
|
|
25
|
+
export const iblGLSL = /* glsl */ `\
|
|
26
|
+
#ifdef USE_IBL
|
|
27
|
+
uniform samplerCube pbr_diffuseEnvSampler;
|
|
28
|
+
uniform samplerCube pbr_specularEnvSampler;
|
|
29
|
+
uniform sampler2D pbr_brdfLUT;
|
|
30
|
+
#endif
|
|
31
|
+
`;
|
|
32
|
+
|
|
33
|
+
export const ibl = {
|
|
34
|
+
name: 'ibl',
|
|
35
|
+
firstBindingSlot: 32,
|
|
36
|
+
bindingLayout: [
|
|
37
|
+
{name: 'pbr_diffuseEnvSampler', group: 2},
|
|
38
|
+
{name: 'pbr_specularEnvSampler', group: 2},
|
|
39
|
+
{name: 'pbr_brdfLUT', group: 2}
|
|
40
|
+
],
|
|
41
|
+
source: iblWGSL,
|
|
42
|
+
vs: iblGLSL,
|
|
43
|
+
fs: iblGLSL
|
|
44
|
+
} as const satisfies ShaderModule<IBLBindings, {}, IBLBindings>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
import {ShaderModule} from '../../../lib/shader-module/shader-module';
|
|
6
|
+
import {lighting} from '../lights/lighting';
|
|
7
|
+
import {LAMBERT_WGSL} from './lambert-shaders-wgsl';
|
|
8
|
+
import {LAMBERT_VS, LAMBERT_FS} from './lambert-shaders-glsl';
|
|
9
|
+
|
|
10
|
+
/** Uniform props for the built-in diffuse-only Lambert material model. */
|
|
11
|
+
export type LambertMaterialProps = {
|
|
12
|
+
unlit?: boolean;
|
|
13
|
+
ambient?: number;
|
|
14
|
+
diffuse?: number;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/** A matte material model that applies diffuse-only Lambert lighting per fragment. */
|
|
18
|
+
export const lambertMaterial: ShaderModule<LambertMaterialProps> = {
|
|
19
|
+
name: 'lambertMaterial',
|
|
20
|
+
firstBindingSlot: 0,
|
|
21
|
+
bindingLayout: [{name: 'lambertMaterial', group: 3}],
|
|
22
|
+
dependencies: [lighting],
|
|
23
|
+
source: LAMBERT_WGSL,
|
|
24
|
+
vs: LAMBERT_VS,
|
|
25
|
+
fs: LAMBERT_FS,
|
|
26
|
+
defines: {
|
|
27
|
+
LIGHTING_FRAGMENT: true
|
|
28
|
+
},
|
|
29
|
+
uniformTypes: {
|
|
30
|
+
unlit: 'i32',
|
|
31
|
+
ambient: 'f32',
|
|
32
|
+
diffuse: 'f32'
|
|
33
|
+
},
|
|
34
|
+
defaultUniforms: {
|
|
35
|
+
unlit: false,
|
|
36
|
+
ambient: 0.35,
|
|
37
|
+
diffuse: 0.6
|
|
38
|
+
},
|
|
39
|
+
getUniforms(props?: LambertMaterialProps) {
|
|
40
|
+
return {...lambertMaterial.defaultUniforms, ...props};
|
|
41
|
+
}
|
|
42
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
export const LAMBERT_VS = /* glsl */ `\
|
|
6
|
+
layout(std140) uniform lambertMaterialUniforms {
|
|
7
|
+
uniform bool unlit;
|
|
8
|
+
uniform float ambient;
|
|
9
|
+
uniform float diffuse;
|
|
10
|
+
} material;
|
|
11
|
+
`;
|
|
12
|
+
|
|
13
|
+
export const LAMBERT_FS = /* glsl */ `\
|
|
14
|
+
layout(std140) uniform lambertMaterialUniforms {
|
|
15
|
+
uniform bool unlit;
|
|
16
|
+
uniform float ambient;
|
|
17
|
+
uniform float diffuse;
|
|
18
|
+
} material;
|
|
19
|
+
|
|
20
|
+
vec3 lighting_getLightColor(vec3 surfaceColor, vec3 light_direction, vec3 normal_worldspace, vec3 color) {
|
|
21
|
+
float lambertian = max(dot(light_direction, normal_worldspace), 0.0);
|
|
22
|
+
return lambertian * material.diffuse * surfaceColor * color;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
|
|
26
|
+
vec3 lightColor = surfaceColor;
|
|
27
|
+
|
|
28
|
+
if (material.unlit) {
|
|
29
|
+
return surfaceColor;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (lighting.enabled == 0) {
|
|
33
|
+
return lightColor;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
lightColor = material.ambient * surfaceColor * lighting.ambientColor;
|
|
37
|
+
|
|
38
|
+
for (int i = 0; i < lighting.pointLightCount; i++) {
|
|
39
|
+
PointLight pointLight = lighting_getPointLight(i);
|
|
40
|
+
vec3 light_position_worldspace = pointLight.position;
|
|
41
|
+
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
42
|
+
float light_attenuation = getPointLightAttenuation(pointLight, distance(light_position_worldspace, position_worldspace));
|
|
43
|
+
lightColor += lighting_getLightColor(surfaceColor, light_direction, normal_worldspace, pointLight.color / light_attenuation);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
for (int i = 0; i < lighting.spotLightCount; i++) {
|
|
47
|
+
SpotLight spotLight = lighting_getSpotLight(i);
|
|
48
|
+
vec3 light_position_worldspace = spotLight.position;
|
|
49
|
+
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
50
|
+
float light_attenuation = getSpotLightAttenuation(spotLight, position_worldspace);
|
|
51
|
+
lightColor += lighting_getLightColor(surfaceColor, light_direction, normal_worldspace, spotLight.color / light_attenuation);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
for (int i = 0; i < lighting.directionalLightCount; i++) {
|
|
55
|
+
DirectionalLight directionalLight = lighting_getDirectionalLight(i);
|
|
56
|
+
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, normal_worldspace, directionalLight.color);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return lightColor;
|
|
60
|
+
}
|
|
61
|
+
`;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
export const LAMBERT_WGSL = /* wgsl */ `\
|
|
6
|
+
struct lambertMaterialUniforms {
|
|
7
|
+
unlit: u32,
|
|
8
|
+
ambient: f32,
|
|
9
|
+
diffuse: f32,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
@group(3) @binding(auto) var<uniform> lambertMaterial : lambertMaterialUniforms;
|
|
13
|
+
|
|
14
|
+
fn lighting_getLightColor(surfaceColor: vec3<f32>, light_direction: vec3<f32>, normal_worldspace: vec3<f32>, color: vec3<f32>) -> vec3<f32> {
|
|
15
|
+
let lambertian: f32 = max(dot(light_direction, normal_worldspace), 0.0);
|
|
16
|
+
return lambertian * lambertMaterial.diffuse * surfaceColor * color;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
fn lighting_getLightColor2(surfaceColor: vec3<f32>, cameraPosition: vec3<f32>, position_worldspace: vec3<f32>, normal_worldspace: vec3<f32>) -> vec3<f32> {
|
|
20
|
+
var lightColor: vec3<f32> = surfaceColor;
|
|
21
|
+
|
|
22
|
+
if (lambertMaterial.unlit != 0u) {
|
|
23
|
+
return surfaceColor;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (lighting.enabled == 0) {
|
|
27
|
+
return lightColor;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
lightColor = lambertMaterial.ambient * surfaceColor * lighting.ambientColor;
|
|
31
|
+
|
|
32
|
+
for (var i: i32 = 0; i < lighting.pointLightCount; i++) {
|
|
33
|
+
let pointLight: PointLight = lighting_getPointLight(i);
|
|
34
|
+
let light_position_worldspace: vec3<f32> = pointLight.position;
|
|
35
|
+
let light_direction: vec3<f32> = normalize(light_position_worldspace - position_worldspace);
|
|
36
|
+
let light_attenuation = getPointLightAttenuation(
|
|
37
|
+
pointLight,
|
|
38
|
+
distance(light_position_worldspace, position_worldspace)
|
|
39
|
+
);
|
|
40
|
+
lightColor += lighting_getLightColor(
|
|
41
|
+
surfaceColor,
|
|
42
|
+
light_direction,
|
|
43
|
+
normal_worldspace,
|
|
44
|
+
pointLight.color / light_attenuation
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
for (var i: i32 = 0; i < lighting.spotLightCount; i++) {
|
|
49
|
+
let spotLight: SpotLight = lighting_getSpotLight(i);
|
|
50
|
+
let light_position_worldspace: vec3<f32> = spotLight.position;
|
|
51
|
+
let light_direction: vec3<f32> = normalize(light_position_worldspace - position_worldspace);
|
|
52
|
+
let light_attenuation = getSpotLightAttenuation(spotLight, position_worldspace);
|
|
53
|
+
lightColor += lighting_getLightColor(
|
|
54
|
+
surfaceColor,
|
|
55
|
+
light_direction,
|
|
56
|
+
normal_worldspace,
|
|
57
|
+
spotLight.color / light_attenuation
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
for (var i: i32 = 0; i < lighting.directionalLightCount; i++) {
|
|
62
|
+
let directionalLight: DirectionalLight = lighting_getDirectionalLight(i);
|
|
63
|
+
lightColor += lighting_getLightColor(
|
|
64
|
+
surfaceColor,
|
|
65
|
+
-directionalLight.direction,
|
|
66
|
+
normal_worldspace,
|
|
67
|
+
directionalLight.color
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return lightColor;
|
|
72
|
+
}
|
|
73
|
+
`;
|
|
@@ -16,59 +16,51 @@ struct PointLight {
|
|
|
16
16
|
vec3 attenuation; // 2nd order x:Constant-y:Linear-z:Exponential
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
+
struct SpotLight {
|
|
20
|
+
vec3 color;
|
|
21
|
+
vec3 position;
|
|
22
|
+
vec3 direction;
|
|
23
|
+
vec3 attenuation;
|
|
24
|
+
vec2 coneCos;
|
|
25
|
+
};
|
|
26
|
+
|
|
19
27
|
struct DirectionalLight {
|
|
20
28
|
vec3 color;
|
|
21
29
|
vec3 direction;
|
|
22
30
|
};
|
|
23
31
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
32
|
+
struct UniformLight {
|
|
33
|
+
vec3 color;
|
|
34
|
+
vec3 position;
|
|
35
|
+
vec3 direction;
|
|
36
|
+
vec3 attenuation;
|
|
37
|
+
vec2 coneCos;
|
|
38
|
+
};
|
|
27
39
|
|
|
40
|
+
layout(std140) uniform lightingUniforms {
|
|
41
|
+
int enabled;
|
|
28
42
|
int directionalLightCount;
|
|
29
43
|
int pointLightCount;
|
|
30
|
-
|
|
44
|
+
int spotLightCount;
|
|
31
45
|
vec3 ambientColor;
|
|
32
|
-
|
|
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;
|
|
46
|
+
UniformLight lights[5];
|
|
47
47
|
} lighting;
|
|
48
48
|
|
|
49
49
|
PointLight lighting_getPointLight(int index) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return PointLight(lighting.lightColor2, lighting.lightPosition2, lighting.lightAttenuation2);
|
|
58
|
-
}
|
|
50
|
+
UniformLight light = lighting.lights[index];
|
|
51
|
+
return PointLight(light.color, light.position, light.attenuation);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
SpotLight lighting_getSpotLight(int index) {
|
|
55
|
+
UniformLight light = lighting.lights[lighting.pointLightCount + index];
|
|
56
|
+
return SpotLight(light.color, light.position, light.direction, light.attenuation, light.coneCos);
|
|
59
57
|
}
|
|
60
58
|
|
|
61
59
|
DirectionalLight lighting_getDirectionalLight(int index) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return DirectionalLight(lighting.lightColor1, lighting.lightDirection1);
|
|
67
|
-
case 2:
|
|
68
|
-
default:
|
|
69
|
-
return DirectionalLight(lighting.lightColor2, lighting.lightDirection2);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
60
|
+
UniformLight light =
|
|
61
|
+
lighting.lights[lighting.pointLightCount + lighting.spotLightCount + index];
|
|
62
|
+
return DirectionalLight(light.color, light.direction);
|
|
63
|
+
}
|
|
72
64
|
|
|
73
65
|
float getPointLightAttenuation(PointLight pointLight, float distance) {
|
|
74
66
|
return pointLight.attenuation.x
|
|
@@ -76,5 +68,19 @@ float getPointLightAttenuation(PointLight pointLight, float distance) {
|
|
|
76
68
|
+ pointLight.attenuation.z * distance * distance;
|
|
77
69
|
}
|
|
78
70
|
|
|
71
|
+
float getSpotLightAttenuation(SpotLight spotLight, vec3 positionWorldspace) {
|
|
72
|
+
vec3 light_direction = normalize(positionWorldspace - spotLight.position);
|
|
73
|
+
float coneFactor = smoothstep(
|
|
74
|
+
spotLight.coneCos.y,
|
|
75
|
+
spotLight.coneCos.x,
|
|
76
|
+
dot(normalize(spotLight.direction), light_direction)
|
|
77
|
+
);
|
|
78
|
+
float distanceAttenuation = getPointLightAttenuation(
|
|
79
|
+
PointLight(spotLight.color, spotLight.position, spotLight.attenuation),
|
|
80
|
+
distance(spotLight.position, positionWorldspace)
|
|
81
|
+
);
|
|
82
|
+
return distanceAttenuation / max(coneFactor, 0.0001);
|
|
83
|
+
}
|
|
84
|
+
|
|
79
85
|
// #endif
|
|
80
86
|
`;
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
export const lightingUniformsWGSL = /* wgsl */ `\
|
|
6
6
|
// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
|
|
7
|
+
const MAX_LIGHTS: i32 = 5;
|
|
8
|
+
|
|
7
9
|
struct AmbientLight {
|
|
8
10
|
color: vec3<f32>,
|
|
9
11
|
};
|
|
@@ -14,44 +16,70 @@ struct PointLight {
|
|
|
14
16
|
attenuation: vec3<f32>, // 2nd order x:Constant-y:Linear-z:Exponential
|
|
15
17
|
};
|
|
16
18
|
|
|
19
|
+
struct SpotLight {
|
|
20
|
+
color: vec3<f32>,
|
|
21
|
+
position: vec3<f32>,
|
|
22
|
+
direction: vec3<f32>,
|
|
23
|
+
attenuation: vec3<f32>,
|
|
24
|
+
coneCos: vec2<f32>,
|
|
25
|
+
};
|
|
26
|
+
|
|
17
27
|
struct DirectionalLight {
|
|
18
28
|
color: vec3<f32>,
|
|
19
29
|
direction: vec3<f32>,
|
|
20
30
|
};
|
|
21
31
|
|
|
32
|
+
struct UniformLight {
|
|
33
|
+
color: vec3<f32>,
|
|
34
|
+
position: vec3<f32>,
|
|
35
|
+
direction: vec3<f32>,
|
|
36
|
+
attenuation: vec3<f32>,
|
|
37
|
+
coneCos: vec2<f32>,
|
|
38
|
+
};
|
|
39
|
+
|
|
22
40
|
struct lightingUniforms {
|
|
23
41
|
enabled: i32,
|
|
24
|
-
pointLightCount: i32,
|
|
25
42
|
directionalLightCount: i32,
|
|
26
|
-
|
|
43
|
+
pointLightCount: i32,
|
|
44
|
+
spotLightCount: i32,
|
|
27
45
|
ambientColor: vec3<f32>,
|
|
28
|
-
|
|
29
|
-
// TODO - support multiple lights by uncommenting arrays below
|
|
30
|
-
lightType: i32,
|
|
31
|
-
lightColor: vec3<f32>,
|
|
32
|
-
lightDirection: vec3<f32>,
|
|
33
|
-
lightPosition: vec3<f32>,
|
|
34
|
-
lightAttenuation: vec3<f32>,
|
|
35
|
-
|
|
36
|
-
// AmbientLight ambientLight;
|
|
37
|
-
// PointLight pointLight[MAX_LIGHTS];
|
|
38
|
-
// DirectionalLight directionalLight[MAX_LIGHTS];
|
|
46
|
+
lights: array<UniformLight, 5>,
|
|
39
47
|
};
|
|
40
48
|
|
|
41
|
-
|
|
42
|
-
@binding(1) @group(0) var<uniform> lighting : lightingUniforms;
|
|
49
|
+
@group(2) @binding(auto) var<uniform> lighting : lightingUniforms;
|
|
43
50
|
|
|
44
51
|
fn lighting_getPointLight(index: i32) -> PointLight {
|
|
45
|
-
|
|
52
|
+
let light = lighting.lights[index];
|
|
53
|
+
return PointLight(light.color, light.position, light.attenuation);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
fn lighting_getSpotLight(index: i32) -> SpotLight {
|
|
57
|
+
let light = lighting.lights[lighting.pointLightCount + index];
|
|
58
|
+
return SpotLight(light.color, light.position, light.direction, light.attenuation, light.coneCos);
|
|
46
59
|
}
|
|
47
60
|
|
|
48
61
|
fn lighting_getDirectionalLight(index: i32) -> DirectionalLight {
|
|
49
|
-
|
|
50
|
-
|
|
62
|
+
let light = lighting.lights[lighting.pointLightCount + lighting.spotLightCount + index];
|
|
63
|
+
return DirectionalLight(light.color, light.direction);
|
|
64
|
+
}
|
|
51
65
|
|
|
52
66
|
fn getPointLightAttenuation(pointLight: PointLight, distance: f32) -> f32 {
|
|
53
67
|
return pointLight.attenuation.x
|
|
54
68
|
+ pointLight.attenuation.y * distance
|
|
55
69
|
+ pointLight.attenuation.z * distance * distance;
|
|
56
70
|
}
|
|
71
|
+
|
|
72
|
+
fn getSpotLightAttenuation(spotLight: SpotLight, positionWorldspace: vec3<f32>) -> f32 {
|
|
73
|
+
let lightDirection = normalize(positionWorldspace - spotLight.position);
|
|
74
|
+
let coneFactor = smoothstep(
|
|
75
|
+
spotLight.coneCos.y,
|
|
76
|
+
spotLight.coneCos.x,
|
|
77
|
+
dot(normalize(spotLight.direction), lightDirection)
|
|
78
|
+
);
|
|
79
|
+
let distanceAttenuation = getPointLightAttenuation(
|
|
80
|
+
PointLight(spotLight.color, spotLight.position, spotLight.attenuation),
|
|
81
|
+
distance(spotLight.position, positionWorldspace)
|
|
82
|
+
);
|
|
83
|
+
return distanceAttenuation / max(coneFactor, 0.0001);
|
|
84
|
+
}
|
|
57
85
|
`;
|