@luma.gl/shadertools 9.3.0-alpha.4 → 9.3.0-alpha.8
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 +4657 -523
- package/dist/dist.min.js +1952 -301
- package/dist/index.cjs +2804 -406
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +10 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.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 +211 -11
- 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 +140 -0
- package/dist/lib/shader-assembly/wgsl-binding-debug.js.map +1 -0
- package/dist/lib/shader-generator/glsl/generate-glsl.js +3 -0
- 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 +22 -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 +112 -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/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 +3 -0
- package/dist/modules/engine/picking/picking.d.ts.map +1 -1
- package/dist/modules/engine/picking/picking.js +3 -0
- package/dist/modules/engine/picking/picking.js.map +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 +43 -37
- 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 +7 -2
- package/dist/modules/lighting/no-material/dirlight.d.ts.map +1 -1
- package/dist/modules/lighting/no-material/dirlight.js +3 -1
- package/dist/modules/lighting/no-material/dirlight.js.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material-glsl.d.ts +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material-glsl.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material-glsl.js +524 -28
- 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 +784 -101
- package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts +110 -45
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material.js +85 -9
- 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 +13 -1
- package/dist/modules/lighting/pbr-material/pbr-projection.js.map +1 -1
- 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 +15 -4
- 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 +41 -10
- 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 +3 -3
- package/src/index.ts +20 -2
- package/src/lib/preprocessor/preprocessor.ts +44 -8
- package/src/lib/shader-assembler.ts +25 -3
- package/src/lib/shader-assembly/assemble-shaders.ts +377 -12
- package/src/lib/shader-assembly/wgsl-binding-debug.ts +216 -0
- package/src/lib/shader-generator/glsl/generate-glsl.ts +7 -1
- package/src/lib/shader-generator/wgsl/generate-wgsl.ts +6 -0
- package/src/lib/shader-module/shader-module-uniform-layout.ts +194 -0
- package/src/lib/shader-module/shader-module.ts +17 -7
- package/src/lib/utils/uniform-types.ts +24 -9
- package/src/modules/engine/picking/picking.ts +3 -0
- 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 +43 -37
- 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 +3 -1
- package/src/modules/lighting/pbr-material/pbr-material-glsl.ts +524 -28
- package/src/modules/lighting/pbr-material/pbr-material-wgsl.ts +784 -101
- package/src/modules/lighting/pbr-material/pbr-material.ts +111 -18
- package/src/modules/lighting/pbr-material/pbr-projection.ts +14 -1
- package/src/modules/lighting/phong-material/phong-material.ts +5 -0
- package/src/modules/lighting/phong-material/phong-shaders-glsl.ts +15 -4
- package/src/modules/lighting/phong-material/phong-shaders-wgsl.ts +71 -77
- package/src/modules/math/fp64/fp64-arithmetic-glsl.ts +41 -10
- 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
|
@@ -135,6 +135,9 @@ vec4 picking_filterColor(vec4 color) {
|
|
|
135
135
|
}
|
|
136
136
|
`;
|
|
137
137
|
/**
|
|
138
|
+
* Deprecated legacy picking module retained for compatibility with existing
|
|
139
|
+
* shadertools users such as deck.gl. Keep the shader contract stable.
|
|
140
|
+
*
|
|
138
141
|
* Provides support for color-coding-based picking and highlighting.
|
|
139
142
|
* In particular, supports picking a specific instance in an instanced
|
|
140
143
|
* draw call and highlighting an instance based on its picking color,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"picking.js","sourceRoot":"","sources":["../../../../src/modules/engine/picking/picking.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAKpC,aAAa;AACb,MAAM,uBAAuB,GAAiB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AA2C3D,MAAM,EAAE,GAAG,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwErB,CAAC;AAEF,MAAM,EAAE,GAAG,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyDrB,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"picking.js","sourceRoot":"","sources":["../../../../src/modules/engine/picking/picking.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAKpC,aAAa;AACb,MAAM,uBAAuB,GAAiB,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AA2C3D,MAAM,EAAE,GAAG,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwErB,CAAC;AAEF,MAAM,EAAE,GAAG,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyDrB,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,KAAK,EAAE,EAAkB;IACzB,QAAQ,EAAE,EAAqB;IAE/B,IAAI,EAAE,SAAS;IAEf,YAAY,EAAE;QACZ,QAAQ,EAAE,KAAK;QACf,WAAW,EAAE,KAAK;QAClB,iBAAiB,EAAE,KAAK;QACxB,cAAc,EAAE,KAAK;QACrB,sBAAsB,EAAE,WAAW;QACnC,cAAc,EAAE,WAAW;KAC5B;IACD,eAAe,EAAE;QACf,QAAQ,EAAE,KAAK;QACf,WAAW,EAAE,KAAK;QAClB,iBAAiB,EAAE,KAAK;QACxB,cAAc,EAAE,IAAI;QACpB,sBAAsB,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QACjC,cAAc,EAAE,uBAAuB;KACxC;IAED,EAAE;IACF,EAAE;IACF,WAAW;CACmD,CAAC;AAEjE,SAAS,WAAW,CAAC,OAAqB,EAAE,EAAE,YAA8B;IAC1E,MAAM,QAAQ,GAAG,EAAqB,CAAC;IAEvC,IAAI,IAAI,CAAC,sBAAsB,KAAK,SAAS,EAAE,CAAC;QAC9C,4EAA4E;IAC9E,CAAC;SAAM,IAAI,IAAI,CAAC,sBAAsB,KAAK,IAAI,EAAE,CAAC;QAChD,QAAQ,CAAC,iBAAiB,GAAG,KAAK,CAAC;IACrC,CAAC;SAAM,CAAC;QACN,QAAQ,CAAC,iBAAiB,GAAG,IAAI,CAAC;QAClC,MAAM,sBAAsB,GAAG,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAiB,CAAC;QACvF,QAAQ,CAAC,sBAAsB,GAAG,sBAAsB,CAAC;IAC3D,CAAC;IAED,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;QACxB,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC;QAC5D,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAC/B,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;QACf,CAAC;QACD,QAAQ,CAAC,cAAc,GAAG,KAAqB,CAAC;IAClD,CAAC;IAED,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;QAChC,QAAQ,CAAC,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC3C,QAAQ,CAAC,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACnD,CAAC;IAED,IAAI,IAAI,CAAC,cAAc,KAAK,SAAS,EAAE,CAAC;QACtC,QAAQ,CAAC,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IACzD,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export declare const source = "\nstruct skinUniforms {\n jointMatrix: array<mat4x4<f32>, 20>,\n};\n\n@group(0) @binding(auto) var<uniform> skin: skinUniforms;\n\nfn getSkinMatrix(weights: vec4f, joints: vec4u) -> mat4x4<f32> {\n return (weights.x * skin.jointMatrix[joints.x])\n + (weights.y * skin.jointMatrix[joints.y])\n + (weights.z * skin.jointMatrix[joints.z])\n + (weights.w * skin.jointMatrix[joints.w]);\n}\n";
|
|
2
|
+
export declare const vs = "\nuniform skinUniforms {\n mat4 jointMatrix[SKIN_MAX_JOINTS];\n} skin;\n\nmat4 getSkinMatrix(vec4 weights, uvec4 joints) {\n return (weights.x * skin.jointMatrix[joints.x])\n + (weights.y * skin.jointMatrix[joints.y])\n + (weights.z * skin.jointMatrix[joints.z])\n + (weights.w * skin.jointMatrix[joints.w]);\n}\n\n";
|
|
3
|
+
export declare const fs = "";
|
|
4
|
+
export type SkinProps = {
|
|
5
|
+
scenegraphsFromGLTF?: any;
|
|
6
|
+
};
|
|
7
|
+
export type SkinUniforms = {
|
|
8
|
+
jointMatrix?: any;
|
|
9
|
+
};
|
|
10
|
+
export declare const skin: {
|
|
11
|
+
readonly props: SkinProps;
|
|
12
|
+
readonly uniforms: SkinUniforms;
|
|
13
|
+
readonly name: "skin";
|
|
14
|
+
readonly bindingLayout: readonly [{
|
|
15
|
+
readonly name: "skin";
|
|
16
|
+
readonly group: 0;
|
|
17
|
+
}];
|
|
18
|
+
readonly dependencies: [];
|
|
19
|
+
readonly source: "\nstruct skinUniforms {\n jointMatrix: array<mat4x4<f32>, 20>,\n};\n\n@group(0) @binding(auto) var<uniform> skin: skinUniforms;\n\nfn getSkinMatrix(weights: vec4f, joints: vec4u) -> mat4x4<f32> {\n return (weights.x * skin.jointMatrix[joints.x])\n + (weights.y * skin.jointMatrix[joints.y])\n + (weights.z * skin.jointMatrix[joints.z])\n + (weights.w * skin.jointMatrix[joints.w]);\n}\n";
|
|
20
|
+
readonly vs: "\nuniform skinUniforms {\n mat4 jointMatrix[SKIN_MAX_JOINTS];\n} skin;\n\nmat4 getSkinMatrix(vec4 weights, uvec4 joints) {\n return (weights.x * skin.jointMatrix[joints.x])\n + (weights.y * skin.jointMatrix[joints.y])\n + (weights.z * skin.jointMatrix[joints.z])\n + (weights.w * skin.jointMatrix[joints.w]);\n}\n\n";
|
|
21
|
+
readonly fs: "";
|
|
22
|
+
readonly defines: {
|
|
23
|
+
readonly SKIN_MAX_JOINTS: 20;
|
|
24
|
+
};
|
|
25
|
+
readonly getUniforms: (props?: SkinProps, prevUniforms?: SkinUniforms) => SkinUniforms;
|
|
26
|
+
readonly uniformTypes: {
|
|
27
|
+
readonly jointMatrix: readonly ["mat4x4<f32>", 20];
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=skin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skin.d.ts","sourceRoot":"","sources":["../../../../src/modules/engine/skin/skin.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,MAAM,2ZAalB,CAAC;AAEF,eAAO,MAAM,EAAE,oVAad,CAAC;AAEF,eAAO,MAAM,EAAE,KACd,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,mBAAmB,CAAC,EAAE,GAAG,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,WAAW,CAAC,EAAE,GAAG,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,IAAI;oBACF,SAAS;uBACN,YAAY;;;;;;;;;;;;;mCAaP,SAAS,iBAAsB,YAAY,KAAG,YAAY;;;;CA+CvB,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import { Matrix4 } from '@math.gl/core';
|
|
5
|
+
const SKIN_MAX_JOINTS = 20;
|
|
6
|
+
export const source = /* wgsl */ `
|
|
7
|
+
struct skinUniforms {
|
|
8
|
+
jointMatrix: array<mat4x4<f32>, ${SKIN_MAX_JOINTS}>,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
@group(0) @binding(auto) var<uniform> skin: skinUniforms;
|
|
12
|
+
|
|
13
|
+
fn getSkinMatrix(weights: vec4f, joints: vec4u) -> mat4x4<f32> {
|
|
14
|
+
return (weights.x * skin.jointMatrix[joints.x])
|
|
15
|
+
+ (weights.y * skin.jointMatrix[joints.y])
|
|
16
|
+
+ (weights.z * skin.jointMatrix[joints.z])
|
|
17
|
+
+ (weights.w * skin.jointMatrix[joints.w]);
|
|
18
|
+
}
|
|
19
|
+
`;
|
|
20
|
+
export const vs = /* glsl */ `\
|
|
21
|
+
|
|
22
|
+
uniform skinUniforms {
|
|
23
|
+
mat4 jointMatrix[SKIN_MAX_JOINTS];
|
|
24
|
+
} skin;
|
|
25
|
+
|
|
26
|
+
mat4 getSkinMatrix(vec4 weights, uvec4 joints) {
|
|
27
|
+
return (weights.x * skin.jointMatrix[joints.x])
|
|
28
|
+
+ (weights.y * skin.jointMatrix[joints.y])
|
|
29
|
+
+ (weights.z * skin.jointMatrix[joints.z])
|
|
30
|
+
+ (weights.w * skin.jointMatrix[joints.w]);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
`;
|
|
34
|
+
export const fs = /* glsl */ `\
|
|
35
|
+
`;
|
|
36
|
+
export const skin = {
|
|
37
|
+
props: {},
|
|
38
|
+
uniforms: {},
|
|
39
|
+
name: 'skin',
|
|
40
|
+
bindingLayout: [{ name: 'skin', group: 0 }],
|
|
41
|
+
dependencies: [],
|
|
42
|
+
source,
|
|
43
|
+
vs,
|
|
44
|
+
fs,
|
|
45
|
+
defines: {
|
|
46
|
+
SKIN_MAX_JOINTS
|
|
47
|
+
},
|
|
48
|
+
getUniforms: (props = {}, prevUniforms) => {
|
|
49
|
+
const { scenegraphsFromGLTF } = props;
|
|
50
|
+
if (!scenegraphsFromGLTF?.gltf?.skins?.[0]) {
|
|
51
|
+
return { jointMatrix: [] };
|
|
52
|
+
}
|
|
53
|
+
const { inverseBindMatrices, joints, skeleton } = scenegraphsFromGLTF.gltf.skins[0];
|
|
54
|
+
const matsib = [];
|
|
55
|
+
const countib = inverseBindMatrices.value.length / 16;
|
|
56
|
+
for (let i = 0; i < countib; i++) {
|
|
57
|
+
const slice = inverseBindMatrices.value.subarray(i * 16, i * 16 + 16);
|
|
58
|
+
matsib.push(new Matrix4(Array.from(slice)));
|
|
59
|
+
}
|
|
60
|
+
const top = scenegraphsFromGLTF.gltfNodeIndexToNodeMap.get(skeleton);
|
|
61
|
+
const matrices = {};
|
|
62
|
+
top.preorderTraversal((node, { worldMatrix }) => {
|
|
63
|
+
matrices[node.id] = worldMatrix;
|
|
64
|
+
});
|
|
65
|
+
const mats = new Float32Array(SKIN_MAX_JOINTS * 16); // 16 floats per 4x4 matrix
|
|
66
|
+
for (let i = 0; i < SKIN_MAX_JOINTS; ++i) {
|
|
67
|
+
const nodeIndex = joints[i];
|
|
68
|
+
if (nodeIndex === undefined)
|
|
69
|
+
break;
|
|
70
|
+
const worldMat = matrices[scenegraphsFromGLTF.gltfNodeIndexToNodeMap.get(nodeIndex).id];
|
|
71
|
+
const invBindMat = matsib[i];
|
|
72
|
+
const Z = new Matrix4().copy(worldMat).multiplyRight(invBindMat);
|
|
73
|
+
const off = i * 16;
|
|
74
|
+
for (let j = 0; j < 16; j++) {
|
|
75
|
+
mats[off + j] = Z[j];
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
jointMatrix: mats
|
|
80
|
+
};
|
|
81
|
+
},
|
|
82
|
+
uniformTypes: {
|
|
83
|
+
jointMatrix: ['mat4x4<f32>', SKIN_MAX_JOINTS]
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
//# sourceMappingURL=skin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skin.js","sourceRoot":"","sources":["../../../../src/modules/engine/skin/skin.ts"],"names":[],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gouraud-material.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/gouraud-material/gouraud-material.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,YAAY,EAAC,oDAAiD;AAKtE,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2BAA2B;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;CAC1C,CAAC;AAEF,yIAAyI;AACzI,eAAO,MAAM,eAAe,EAAE,YAAY,CAAC,oBAAoB,
|
|
1
|
+
{"version":3,"file":"gouraud-material.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/gouraud-material/gouraud-material.ts"],"names":[],"mappings":"AAKA,OAAO,EAAC,YAAY,EAAC,oDAAiD;AAKtE,MAAM,MAAM,oBAAoB,GAAG;IACjC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,2BAA2B;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;CAC1C,CAAC;AAEF,yIAAyI;AACzI,eAAO,MAAM,eAAe,EAAE,YAAY,CAAC,oBAAoB,CAmC9D,CAAC"}
|
|
@@ -8,6 +8,7 @@ import { PHONG_WGSL } from "../phong-material/phong-shaders-wgsl.js";
|
|
|
8
8
|
export const gouraudMaterial = {
|
|
9
9
|
props: {},
|
|
10
10
|
name: 'gouraudMaterial',
|
|
11
|
+
bindingLayout: [{ name: 'gouraudMaterial', group: 3 }],
|
|
11
12
|
// Note these are switched between phong and gouraud
|
|
12
13
|
vs: PHONG_FS.replace('phongMaterial', 'gouraudMaterial'),
|
|
13
14
|
fs: PHONG_VS.replace('phongMaterial', 'gouraudMaterial'),
|
|
@@ -17,12 +18,14 @@ export const gouraudMaterial = {
|
|
|
17
18
|
},
|
|
18
19
|
dependencies: [lighting],
|
|
19
20
|
uniformTypes: {
|
|
21
|
+
unlit: 'i32',
|
|
20
22
|
ambient: 'f32',
|
|
21
23
|
diffuse: 'f32',
|
|
22
24
|
shininess: 'f32',
|
|
23
25
|
specularColor: 'vec3<f32>'
|
|
24
26
|
},
|
|
25
27
|
defaultUniforms: {
|
|
28
|
+
unlit: false,
|
|
26
29
|
ambient: 0.35,
|
|
27
30
|
diffuse: 0.6,
|
|
28
31
|
shininess: 32,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gouraud-material.js","sourceRoot":"","sources":["../../../../src/modules/lighting/gouraud-material/gouraud-material.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAIpC,OAAO,EAAC,QAAQ,EAAC,8BAA2B;AAC5C,OAAO,EAAC,QAAQ,EAAE,QAAQ,EAAC,gDAA6C;AACxE,OAAO,EAAC,UAAU,EAAC,gDAA6C;
|
|
1
|
+
{"version":3,"file":"gouraud-material.js","sourceRoot":"","sources":["../../../../src/modules/lighting/gouraud-material/gouraud-material.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAIpC,OAAO,EAAC,QAAQ,EAAC,8BAA2B;AAC5C,OAAO,EAAC,QAAQ,EAAE,QAAQ,EAAC,gDAA6C;AACxE,OAAO,EAAC,UAAU,EAAC,gDAA6C;AAWhE,yIAAyI;AACzI,MAAM,CAAC,MAAM,eAAe,GAAuC;IACjE,KAAK,EAAE,EAA0B;IAEjC,IAAI,EAAE,iBAAiB;IACvB,aAAa,EAAE,CAAC,EAAC,IAAI,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAAC,EAAC,CAAC;IACpD,oDAAoD;IACpD,EAAE,EAAE,QAAQ,CAAC,OAAO,CAAC,eAAe,EAAE,iBAAiB,CAAC;IACxD,EAAE,EAAE,QAAQ,CAAC,OAAO,CAAC,eAAe,EAAE,iBAAiB,CAAC;IACxD,MAAM,EAAE,UAAU,CAAC,UAAU,CAAC,eAAe,EAAE,iBAAiB,CAAC;IACjE,OAAO,EAAE;QACP,eAAe,EAAE,IAAI;KACtB;IACD,YAAY,EAAE,CAAC,QAAQ,CAAC;IACxB,YAAY,EAAE;QACZ,KAAK,EAAE,KAAK;QACZ,OAAO,EAAE,KAAK;QACd,OAAO,EAAE,KAAK;QACd,SAAS,EAAE,KAAK;QAChB,aAAa,EAAE,WAAW;KAC3B;IACD,eAAe,EAAE;QACf,KAAK,EAAE,KAAK;QACZ,OAAO,EAAE,IAAI;QACb,OAAO,EAAE,GAAG;QACZ,SAAS,EAAE,EAAE;QACb,aAAa,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;KAClC;IAED,WAAW,CAAC,KAA2B;QACrC,MAAM,QAAQ,GAAG,EAAC,GAAG,KAAK,EAAC,CAAC;QAC5B,IAAI,QAAQ,CAAC,aAAa,EAAE,CAAC;YAC3B,QAAQ,CAAC,aAAa,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,GAAG,CAAiB,CAAC;QACpF,CAAC;QACD,OAAO,EAAC,GAAG,eAAe,CAAC,eAAe,EAAE,GAAG,QAAQ,EAAC,CAAC;IAC3D,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Texture } from '@luma.gl/core';
|
|
2
|
+
export type IBLBindings = {
|
|
3
|
+
pbr_diffuseEnvSampler?: Texture | null;
|
|
4
|
+
pbr_specularEnvSampler?: Texture | null;
|
|
5
|
+
pbr_brdfLUT?: Texture | null;
|
|
6
|
+
};
|
|
7
|
+
export declare const iblWGSL = "#ifdef USE_IBL\n@group(2) @binding(auto) var pbr_diffuseEnvSampler: texture_cube<f32>;\n@group(2) @binding(auto) var pbr_diffuseEnvSamplerSampler: sampler;\n@group(2) @binding(auto) var pbr_specularEnvSampler: texture_cube<f32>;\n@group(2) @binding(auto) var pbr_specularEnvSamplerSampler: sampler;\n@group(2) @binding(auto) var pbr_brdfLUT: texture_2d<f32>;\n@group(2) @binding(auto) var pbr_brdfLUTSampler: sampler;\n#endif\n";
|
|
8
|
+
export declare const iblGLSL = "#ifdef USE_IBL\nuniform samplerCube pbr_diffuseEnvSampler;\nuniform samplerCube pbr_specularEnvSampler;\nuniform sampler2D pbr_brdfLUT;\n#endif\n";
|
|
9
|
+
export declare const ibl: {
|
|
10
|
+
readonly name: "ibl";
|
|
11
|
+
readonly firstBindingSlot: 32;
|
|
12
|
+
readonly bindingLayout: readonly [{
|
|
13
|
+
readonly name: "pbr_diffuseEnvSampler";
|
|
14
|
+
readonly group: 2;
|
|
15
|
+
}, {
|
|
16
|
+
readonly name: "pbr_specularEnvSampler";
|
|
17
|
+
readonly group: 2;
|
|
18
|
+
}, {
|
|
19
|
+
readonly name: "pbr_brdfLUT";
|
|
20
|
+
readonly group: 2;
|
|
21
|
+
}];
|
|
22
|
+
readonly source: "#ifdef USE_IBL\n@group(2) @binding(auto) var pbr_diffuseEnvSampler: texture_cube<f32>;\n@group(2) @binding(auto) var pbr_diffuseEnvSamplerSampler: sampler;\n@group(2) @binding(auto) var pbr_specularEnvSampler: texture_cube<f32>;\n@group(2) @binding(auto) var pbr_specularEnvSamplerSampler: sampler;\n@group(2) @binding(auto) var pbr_brdfLUT: texture_2d<f32>;\n@group(2) @binding(auto) var pbr_brdfLUTSampler: sampler;\n#endif\n";
|
|
23
|
+
readonly vs: "#ifdef USE_IBL\nuniform samplerCube pbr_diffuseEnvSampler;\nuniform samplerCube pbr_specularEnvSampler;\nuniform sampler2D pbr_brdfLUT;\n#endif\n";
|
|
24
|
+
readonly fs: "#ifdef USE_IBL\nuniform samplerCube pbr_diffuseEnvSampler;\nuniform samplerCube pbr_specularEnvSampler;\nuniform sampler2D pbr_brdfLUT;\n#endif\n";
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=ibl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ibl.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/ibl/ibl.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,eAAe,CAAC;AAG3C,MAAM,MAAM,WAAW,GAAG;IACxB,qBAAqB,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IACvC,sBAAsB,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IACxC,WAAW,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;CAC9B,CAAC;AAEF,eAAO,MAAM,OAAO,gbASnB,CAAC;AAEF,eAAO,MAAM,OAAO,sJAMnB,CAAC;AAEF,eAAO,MAAM,GAAG;;;;;;;;;;;;;;;;CAW+C,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
export const iblWGSL = /* wgsl */ `\
|
|
5
|
+
#ifdef USE_IBL
|
|
6
|
+
@group(2) @binding(auto) var pbr_diffuseEnvSampler: texture_cube<f32>;
|
|
7
|
+
@group(2) @binding(auto) var pbr_diffuseEnvSamplerSampler: sampler;
|
|
8
|
+
@group(2) @binding(auto) var pbr_specularEnvSampler: texture_cube<f32>;
|
|
9
|
+
@group(2) @binding(auto) var pbr_specularEnvSamplerSampler: sampler;
|
|
10
|
+
@group(2) @binding(auto) var pbr_brdfLUT: texture_2d<f32>;
|
|
11
|
+
@group(2) @binding(auto) var pbr_brdfLUTSampler: sampler;
|
|
12
|
+
#endif
|
|
13
|
+
`;
|
|
14
|
+
export const iblGLSL = /* glsl */ `\
|
|
15
|
+
#ifdef USE_IBL
|
|
16
|
+
uniform samplerCube pbr_diffuseEnvSampler;
|
|
17
|
+
uniform samplerCube pbr_specularEnvSampler;
|
|
18
|
+
uniform sampler2D pbr_brdfLUT;
|
|
19
|
+
#endif
|
|
20
|
+
`;
|
|
21
|
+
export const ibl = {
|
|
22
|
+
name: 'ibl',
|
|
23
|
+
firstBindingSlot: 32,
|
|
24
|
+
bindingLayout: [
|
|
25
|
+
{ name: 'pbr_diffuseEnvSampler', group: 2 },
|
|
26
|
+
{ name: 'pbr_specularEnvSampler', group: 2 },
|
|
27
|
+
{ name: 'pbr_brdfLUT', group: 2 }
|
|
28
|
+
],
|
|
29
|
+
source: iblWGSL,
|
|
30
|
+
vs: iblGLSL,
|
|
31
|
+
fs: iblGLSL
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=ibl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ibl.js","sourceRoot":"","sources":["../../../../src/modules/lighting/ibl/ibl.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAWpC,MAAM,CAAC,MAAM,OAAO,GAAG,UAAU,CAAC;;;;;;;;;CASjC,CAAC;AAEF,MAAM,CAAC,MAAM,OAAO,GAAG,UAAU,CAAC;;;;;;CAMjC,CAAC;AAEF,MAAM,CAAC,MAAM,GAAG,GAAG;IACjB,IAAI,EAAE,KAAK;IACX,gBAAgB,EAAE,EAAE;IACpB,aAAa,EAAE;QACb,EAAC,IAAI,EAAE,uBAAuB,EAAE,KAAK,EAAE,CAAC,EAAC;QACzC,EAAC,IAAI,EAAE,wBAAwB,EAAE,KAAK,EAAE,CAAC,EAAC;QAC1C,EAAC,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC,EAAC;KAChC;IACD,MAAM,EAAE,OAAO;IACf,EAAE,EAAE,OAAO;IACX,EAAE,EAAE,OAAO;CACkD,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ShaderModule } from "../../../lib/shader-module/shader-module.js";
|
|
2
|
+
/** Uniform props for the built-in diffuse-only Lambert material model. */
|
|
3
|
+
export type LambertMaterialProps = {
|
|
4
|
+
unlit?: boolean;
|
|
5
|
+
ambient?: number;
|
|
6
|
+
diffuse?: number;
|
|
7
|
+
};
|
|
8
|
+
/** A matte material model that applies diffuse-only Lambert lighting per fragment. */
|
|
9
|
+
export declare const lambertMaterial: ShaderModule<LambertMaterialProps>;
|
|
10
|
+
//# sourceMappingURL=lambert-material.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lambert-material.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/lambert-material/lambert-material.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,YAAY,EAAC,oDAAiD;AAKtE,0EAA0E;AAC1E,MAAM,MAAM,oBAAoB,GAAG;IACjC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,sFAAsF;AACtF,eAAO,MAAM,eAAe,EAAE,YAAY,CAAC,oBAAoB,CAwB9D,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
import { lighting } from "../lights/lighting.js";
|
|
5
|
+
import { LAMBERT_WGSL } from "./lambert-shaders-wgsl.js";
|
|
6
|
+
import { LAMBERT_VS, LAMBERT_FS } from "./lambert-shaders-glsl.js";
|
|
7
|
+
/** A matte material model that applies diffuse-only Lambert lighting per fragment. */
|
|
8
|
+
export const lambertMaterial = {
|
|
9
|
+
name: 'lambertMaterial',
|
|
10
|
+
firstBindingSlot: 0,
|
|
11
|
+
bindingLayout: [{ name: 'lambertMaterial', group: 3 }],
|
|
12
|
+
dependencies: [lighting],
|
|
13
|
+
source: LAMBERT_WGSL,
|
|
14
|
+
vs: LAMBERT_VS,
|
|
15
|
+
fs: LAMBERT_FS,
|
|
16
|
+
defines: {
|
|
17
|
+
LIGHTING_FRAGMENT: true
|
|
18
|
+
},
|
|
19
|
+
uniformTypes: {
|
|
20
|
+
unlit: 'i32',
|
|
21
|
+
ambient: 'f32',
|
|
22
|
+
diffuse: 'f32'
|
|
23
|
+
},
|
|
24
|
+
defaultUniforms: {
|
|
25
|
+
unlit: false,
|
|
26
|
+
ambient: 0.35,
|
|
27
|
+
diffuse: 0.6
|
|
28
|
+
},
|
|
29
|
+
getUniforms(props) {
|
|
30
|
+
return { ...lambertMaterial.defaultUniforms, ...props };
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=lambert-material.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lambert-material.js","sourceRoot":"","sources":["../../../../src/modules/lighting/lambert-material/lambert-material.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAGpC,OAAO,EAAC,QAAQ,EAAC,8BAA2B;AAC5C,OAAO,EAAC,YAAY,EAAC,kCAA+B;AACpD,OAAO,EAAC,UAAU,EAAE,UAAU,EAAC,kCAA+B;AAS9D,sFAAsF;AACtF,MAAM,CAAC,MAAM,eAAe,GAAuC;IACjE,IAAI,EAAE,iBAAiB;IACvB,gBAAgB,EAAE,CAAC;IACnB,aAAa,EAAE,CAAC,EAAC,IAAI,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAAC,EAAC,CAAC;IACpD,YAAY,EAAE,CAAC,QAAQ,CAAC;IACxB,MAAM,EAAE,YAAY;IACpB,EAAE,EAAE,UAAU;IACd,EAAE,EAAE,UAAU;IACd,OAAO,EAAE;QACP,iBAAiB,EAAE,IAAI;KACxB;IACD,YAAY,EAAE;QACZ,KAAK,EAAE,KAAK;QACZ,OAAO,EAAE,KAAK;QACd,OAAO,EAAE,KAAK;KACf;IACD,eAAe,EAAE;QACf,KAAK,EAAE,KAAK;QACZ,OAAO,EAAE,IAAI;QACb,OAAO,EAAE,GAAG;KACb;IACD,WAAW,CAAC,KAA4B;QACtC,OAAO,EAAC,GAAG,eAAe,CAAC,eAAe,EAAE,GAAG,KAAK,EAAC,CAAC;IACxD,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const LAMBERT_VS = "uniform lambertMaterialUniforms {\n uniform bool unlit;\n uniform float ambient;\n uniform float diffuse;\n} material;\n";
|
|
2
|
+
export declare const LAMBERT_FS = "uniform lambertMaterialUniforms {\n uniform bool unlit;\n uniform float ambient;\n uniform float diffuse;\n} material;\n\nvec3 lighting_getLightColor(vec3 surfaceColor, vec3 light_direction, vec3 normal_worldspace, vec3 color) {\n float lambertian = max(dot(light_direction, normal_worldspace), 0.0);\n return lambertian * material.diffuse * surfaceColor * color;\n}\n\nvec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {\n vec3 lightColor = surfaceColor;\n\n if (material.unlit) {\n return surfaceColor;\n }\n\n if (lighting.enabled == 0) {\n return lightColor;\n }\n\n lightColor = material.ambient * surfaceColor * lighting.ambientColor;\n\n for (int i = 0; i < lighting.pointLightCount; i++) {\n PointLight pointLight = lighting_getPointLight(i);\n vec3 light_position_worldspace = pointLight.position;\n vec3 light_direction = normalize(light_position_worldspace - position_worldspace);\n float light_attenuation = getPointLightAttenuation(pointLight, distance(light_position_worldspace, position_worldspace));\n lightColor += lighting_getLightColor(surfaceColor, light_direction, normal_worldspace, pointLight.color / light_attenuation);\n }\n\n for (int i = 0; i < lighting.spotLightCount; i++) {\n SpotLight spotLight = lighting_getSpotLight(i);\n vec3 light_position_worldspace = spotLight.position;\n vec3 light_direction = normalize(light_position_worldspace - position_worldspace);\n float light_attenuation = getSpotLightAttenuation(spotLight, position_worldspace);\n lightColor += lighting_getLightColor(surfaceColor, light_direction, normal_worldspace, spotLight.color / light_attenuation);\n }\n\n for (int i = 0; i < lighting.directionalLightCount; i++) {\n DirectionalLight directionalLight = lighting_getDirectionalLight(i);\n lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, normal_worldspace, directionalLight.color);\n }\n\n return lightColor;\n}\n";
|
|
3
|
+
//# sourceMappingURL=lambert-shaders-glsl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lambert-shaders-glsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/lambert-material/lambert-shaders-glsl.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,UAAU,gIAMtB,CAAC;AAEF,eAAO,MAAM,UAAU,k/DAgDtB,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
export const LAMBERT_VS = /* glsl */ `\
|
|
5
|
+
uniform lambertMaterialUniforms {
|
|
6
|
+
uniform bool unlit;
|
|
7
|
+
uniform float ambient;
|
|
8
|
+
uniform float diffuse;
|
|
9
|
+
} material;
|
|
10
|
+
`;
|
|
11
|
+
export const LAMBERT_FS = /* glsl */ `\
|
|
12
|
+
uniform lambertMaterialUniforms {
|
|
13
|
+
uniform bool unlit;
|
|
14
|
+
uniform float ambient;
|
|
15
|
+
uniform float diffuse;
|
|
16
|
+
} material;
|
|
17
|
+
|
|
18
|
+
vec3 lighting_getLightColor(vec3 surfaceColor, vec3 light_direction, vec3 normal_worldspace, vec3 color) {
|
|
19
|
+
float lambertian = max(dot(light_direction, normal_worldspace), 0.0);
|
|
20
|
+
return lambertian * material.diffuse * surfaceColor * color;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
vec3 lighting_getLightColor(vec3 surfaceColor, vec3 cameraPosition, vec3 position_worldspace, vec3 normal_worldspace) {
|
|
24
|
+
vec3 lightColor = surfaceColor;
|
|
25
|
+
|
|
26
|
+
if (material.unlit) {
|
|
27
|
+
return surfaceColor;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (lighting.enabled == 0) {
|
|
31
|
+
return lightColor;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
lightColor = material.ambient * surfaceColor * lighting.ambientColor;
|
|
35
|
+
|
|
36
|
+
for (int i = 0; i < lighting.pointLightCount; i++) {
|
|
37
|
+
PointLight pointLight = lighting_getPointLight(i);
|
|
38
|
+
vec3 light_position_worldspace = pointLight.position;
|
|
39
|
+
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
40
|
+
float light_attenuation = getPointLightAttenuation(pointLight, distance(light_position_worldspace, position_worldspace));
|
|
41
|
+
lightColor += lighting_getLightColor(surfaceColor, light_direction, normal_worldspace, pointLight.color / light_attenuation);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
for (int i = 0; i < lighting.spotLightCount; i++) {
|
|
45
|
+
SpotLight spotLight = lighting_getSpotLight(i);
|
|
46
|
+
vec3 light_position_worldspace = spotLight.position;
|
|
47
|
+
vec3 light_direction = normalize(light_position_worldspace - position_worldspace);
|
|
48
|
+
float light_attenuation = getSpotLightAttenuation(spotLight, position_worldspace);
|
|
49
|
+
lightColor += lighting_getLightColor(surfaceColor, light_direction, normal_worldspace, spotLight.color / light_attenuation);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
for (int i = 0; i < lighting.directionalLightCount; i++) {
|
|
53
|
+
DirectionalLight directionalLight = lighting_getDirectionalLight(i);
|
|
54
|
+
lightColor += lighting_getLightColor(surfaceColor, -directionalLight.direction, normal_worldspace, directionalLight.color);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return lightColor;
|
|
58
|
+
}
|
|
59
|
+
`;
|
|
60
|
+
//# sourceMappingURL=lambert-shaders-glsl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lambert-shaders-glsl.js","sourceRoot":"","sources":["../../../../src/modules/lighting/lambert-material/lambert-shaders-glsl.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,MAAM,CAAC,MAAM,UAAU,GAAG,UAAU,CAAC;;;;;;CAMpC,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgDpC,CAAC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const LAMBERT_WGSL = "struct lambertMaterialUniforms {\n unlit: u32,\n ambient: f32,\n diffuse: f32,\n};\n\n@group(3) @binding(auto) var<uniform> lambertMaterial : lambertMaterialUniforms;\n\nfn lighting_getLightColor(surfaceColor: vec3<f32>, light_direction: vec3<f32>, normal_worldspace: vec3<f32>, color: vec3<f32>) -> vec3<f32> {\n let lambertian: f32 = max(dot(light_direction, normal_worldspace), 0.0);\n return lambertian * lambertMaterial.diffuse * surfaceColor * color;\n}\n\nfn lighting_getLightColor2(surfaceColor: vec3<f32>, cameraPosition: vec3<f32>, position_worldspace: vec3<f32>, normal_worldspace: vec3<f32>) -> vec3<f32> {\n var lightColor: vec3<f32> = surfaceColor;\n\n if (lambertMaterial.unlit != 0u) {\n return surfaceColor;\n }\n\n if (lighting.enabled == 0) {\n return lightColor;\n }\n\n lightColor = lambertMaterial.ambient * surfaceColor * lighting.ambientColor;\n\n for (var i: i32 = 0; i < lighting.pointLightCount; i++) {\n let pointLight: PointLight = lighting_getPointLight(i);\n let light_position_worldspace: vec3<f32> = pointLight.position;\n let light_direction: vec3<f32> = normalize(light_position_worldspace - position_worldspace);\n let light_attenuation = getPointLightAttenuation(\n pointLight,\n distance(light_position_worldspace, position_worldspace)\n );\n lightColor += lighting_getLightColor(\n surfaceColor,\n light_direction,\n normal_worldspace,\n pointLight.color / light_attenuation\n );\n }\n\n for (var i: i32 = 0; i < lighting.spotLightCount; i++) {\n let spotLight: SpotLight = lighting_getSpotLight(i);\n let light_position_worldspace: vec3<f32> = spotLight.position;\n let light_direction: vec3<f32> = normalize(light_position_worldspace - position_worldspace);\n let light_attenuation = getSpotLightAttenuation(spotLight, position_worldspace);\n lightColor += lighting_getLightColor(\n surfaceColor,\n light_direction,\n normal_worldspace,\n spotLight.color / light_attenuation\n );\n }\n\n for (var i: i32 = 0; i < lighting.directionalLightCount; i++) {\n let directionalLight: DirectionalLight = lighting_getDirectionalLight(i);\n lightColor += lighting_getLightColor(\n surfaceColor,\n -directionalLight.direction,\n normal_worldspace,\n directionalLight.color\n );\n }\n\n return lightColor;\n}\n";
|
|
2
|
+
//# sourceMappingURL=lambert-shaders-wgsl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lambert-shaders-wgsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/lambert-material/lambert-shaders-wgsl.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,YAAY,i1EAoExB,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
export const LAMBERT_WGSL = /* wgsl */ `\
|
|
5
|
+
struct lambertMaterialUniforms {
|
|
6
|
+
unlit: u32,
|
|
7
|
+
ambient: f32,
|
|
8
|
+
diffuse: f32,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
@group(3) @binding(auto) var<uniform> lambertMaterial : lambertMaterialUniforms;
|
|
12
|
+
|
|
13
|
+
fn lighting_getLightColor(surfaceColor: vec3<f32>, light_direction: vec3<f32>, normal_worldspace: vec3<f32>, color: vec3<f32>) -> vec3<f32> {
|
|
14
|
+
let lambertian: f32 = max(dot(light_direction, normal_worldspace), 0.0);
|
|
15
|
+
return lambertian * lambertMaterial.diffuse * surfaceColor * color;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
fn lighting_getLightColor2(surfaceColor: vec3<f32>, cameraPosition: vec3<f32>, position_worldspace: vec3<f32>, normal_worldspace: vec3<f32>) -> vec3<f32> {
|
|
19
|
+
var lightColor: vec3<f32> = surfaceColor;
|
|
20
|
+
|
|
21
|
+
if (lambertMaterial.unlit != 0u) {
|
|
22
|
+
return surfaceColor;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (lighting.enabled == 0) {
|
|
26
|
+
return lightColor;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
lightColor = lambertMaterial.ambient * surfaceColor * lighting.ambientColor;
|
|
30
|
+
|
|
31
|
+
for (var i: i32 = 0; i < lighting.pointLightCount; i++) {
|
|
32
|
+
let pointLight: PointLight = lighting_getPointLight(i);
|
|
33
|
+
let light_position_worldspace: vec3<f32> = pointLight.position;
|
|
34
|
+
let light_direction: vec3<f32> = normalize(light_position_worldspace - position_worldspace);
|
|
35
|
+
let light_attenuation = getPointLightAttenuation(
|
|
36
|
+
pointLight,
|
|
37
|
+
distance(light_position_worldspace, position_worldspace)
|
|
38
|
+
);
|
|
39
|
+
lightColor += lighting_getLightColor(
|
|
40
|
+
surfaceColor,
|
|
41
|
+
light_direction,
|
|
42
|
+
normal_worldspace,
|
|
43
|
+
pointLight.color / light_attenuation
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
for (var i: i32 = 0; i < lighting.spotLightCount; i++) {
|
|
48
|
+
let spotLight: SpotLight = lighting_getSpotLight(i);
|
|
49
|
+
let light_position_worldspace: vec3<f32> = spotLight.position;
|
|
50
|
+
let light_direction: vec3<f32> = normalize(light_position_worldspace - position_worldspace);
|
|
51
|
+
let light_attenuation = getSpotLightAttenuation(spotLight, position_worldspace);
|
|
52
|
+
lightColor += lighting_getLightColor(
|
|
53
|
+
surfaceColor,
|
|
54
|
+
light_direction,
|
|
55
|
+
normal_worldspace,
|
|
56
|
+
spotLight.color / light_attenuation
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
for (var i: i32 = 0; i < lighting.directionalLightCount; i++) {
|
|
61
|
+
let directionalLight: DirectionalLight = lighting_getDirectionalLight(i);
|
|
62
|
+
lightColor += lighting_getLightColor(
|
|
63
|
+
surfaceColor,
|
|
64
|
+
-directionalLight.direction,
|
|
65
|
+
normal_worldspace,
|
|
66
|
+
directionalLight.color
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return lightColor;
|
|
71
|
+
}
|
|
72
|
+
`;
|
|
73
|
+
//# sourceMappingURL=lambert-shaders-wgsl.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lambert-shaders-wgsl.js","sourceRoot":"","sources":["../../../../src/modules/lighting/lambert-material/lambert-shaders-wgsl.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,MAAM,CAAC,MAAM,YAAY,GAAG,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoEtC,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const lightingUniformsGLSL = "precision highp int;\n\n// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))\nstruct AmbientLight {\n vec3 color;\n};\n\nstruct PointLight {\n vec3 color;\n vec3 position;\n vec3 attenuation; // 2nd order x:Constant-y:Linear-z:Exponential\n};\n\nstruct
|
|
1
|
+
export declare const lightingUniformsGLSL = "precision highp int;\n\n// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))\nstruct AmbientLight {\n vec3 color;\n};\n\nstruct PointLight {\n vec3 color;\n vec3 position;\n vec3 attenuation; // 2nd order x:Constant-y:Linear-z:Exponential\n};\n\nstruct SpotLight {\n vec3 color;\n vec3 position;\n vec3 direction;\n vec3 attenuation;\n vec2 coneCos;\n};\n\nstruct DirectionalLight {\n vec3 color;\n vec3 direction;\n};\n\nstruct UniformLight {\n vec3 color;\n vec3 position;\n vec3 direction;\n vec3 attenuation;\n vec2 coneCos;\n};\n\nuniform lightingUniforms {\n int enabled;\n int directionalLightCount;\n int pointLightCount;\n int spotLightCount;\n vec3 ambientColor;\n UniformLight lights[5];\n} lighting;\n\nPointLight lighting_getPointLight(int index) {\n UniformLight light = lighting.lights[index];\n return PointLight(light.color, light.position, light.attenuation);\n}\n\nSpotLight lighting_getSpotLight(int index) {\n UniformLight light = lighting.lights[lighting.pointLightCount + index];\n return SpotLight(light.color, light.position, light.direction, light.attenuation, light.coneCos);\n}\n\nDirectionalLight lighting_getDirectionalLight(int index) {\n UniformLight light =\n lighting.lights[lighting.pointLightCount + lighting.spotLightCount + index];\n return DirectionalLight(light.color, light.direction);\n}\n\nfloat getPointLightAttenuation(PointLight pointLight, float distance) {\n return pointLight.attenuation.x\n + pointLight.attenuation.y * distance\n + pointLight.attenuation.z * distance * distance;\n}\n\nfloat getSpotLightAttenuation(SpotLight spotLight, vec3 positionWorldspace) {\n vec3 light_direction = normalize(positionWorldspace - spotLight.position);\n float coneFactor = smoothstep(\n spotLight.coneCos.y,\n spotLight.coneCos.x,\n dot(normalize(spotLight.direction), light_direction)\n );\n float distanceAttenuation = getPointLightAttenuation(\n PointLight(spotLight.color, spotLight.position, spotLight.attenuation),\n distance(spotLight.position, positionWorldspace)\n );\n return distanceAttenuation / max(coneFactor, 0.0001);\n}\n\n// #endif\n";
|
|
2
2
|
//# sourceMappingURL=lighting-glsl.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lighting-glsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/lights/lighting-glsl.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,oBAAoB,
|
|
1
|
+
{"version":3,"file":"lighting-glsl.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/lights/lighting-glsl.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,oBAAoB,6rEAiFhC,CAAC"}
|
|
@@ -15,59 +15,51 @@ struct PointLight {
|
|
|
15
15
|
vec3 attenuation; // 2nd order x:Constant-y:Linear-z:Exponential
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
+
struct SpotLight {
|
|
19
|
+
vec3 color;
|
|
20
|
+
vec3 position;
|
|
21
|
+
vec3 direction;
|
|
22
|
+
vec3 attenuation;
|
|
23
|
+
vec2 coneCos;
|
|
24
|
+
};
|
|
25
|
+
|
|
18
26
|
struct DirectionalLight {
|
|
19
27
|
vec3 color;
|
|
20
28
|
vec3 direction;
|
|
21
29
|
};
|
|
22
30
|
|
|
31
|
+
struct UniformLight {
|
|
32
|
+
vec3 color;
|
|
33
|
+
vec3 position;
|
|
34
|
+
vec3 direction;
|
|
35
|
+
vec3 attenuation;
|
|
36
|
+
vec2 coneCos;
|
|
37
|
+
};
|
|
38
|
+
|
|
23
39
|
uniform lightingUniforms {
|
|
24
40
|
int enabled;
|
|
25
|
-
int lightType;
|
|
26
|
-
|
|
27
41
|
int directionalLightCount;
|
|
28
42
|
int pointLightCount;
|
|
29
|
-
|
|
43
|
+
int spotLightCount;
|
|
30
44
|
vec3 ambientColor;
|
|
31
|
-
|
|
32
|
-
vec3 lightColor0;
|
|
33
|
-
vec3 lightPosition0;
|
|
34
|
-
vec3 lightDirection0;
|
|
35
|
-
vec3 lightAttenuation0;
|
|
36
|
-
|
|
37
|
-
vec3 lightColor1;
|
|
38
|
-
vec3 lightPosition1;
|
|
39
|
-
vec3 lightDirection1;
|
|
40
|
-
vec3 lightAttenuation1;
|
|
41
|
-
|
|
42
|
-
vec3 lightColor2;
|
|
43
|
-
vec3 lightPosition2;
|
|
44
|
-
vec3 lightDirection2;
|
|
45
|
-
vec3 lightAttenuation2;
|
|
45
|
+
UniformLight lights[5];
|
|
46
46
|
} lighting;
|
|
47
47
|
|
|
48
48
|
PointLight lighting_getPointLight(int index) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
return PointLight(lighting.lightColor2, lighting.lightPosition2, lighting.lightAttenuation2);
|
|
57
|
-
}
|
|
49
|
+
UniformLight light = lighting.lights[index];
|
|
50
|
+
return PointLight(light.color, light.position, light.attenuation);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
SpotLight lighting_getSpotLight(int index) {
|
|
54
|
+
UniformLight light = lighting.lights[lighting.pointLightCount + index];
|
|
55
|
+
return SpotLight(light.color, light.position, light.direction, light.attenuation, light.coneCos);
|
|
58
56
|
}
|
|
59
57
|
|
|
60
58
|
DirectionalLight lighting_getDirectionalLight(int index) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return DirectionalLight(lighting.lightColor1, lighting.lightDirection1);
|
|
66
|
-
case 2:
|
|
67
|
-
default:
|
|
68
|
-
return DirectionalLight(lighting.lightColor2, lighting.lightDirection2);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
59
|
+
UniformLight light =
|
|
60
|
+
lighting.lights[lighting.pointLightCount + lighting.spotLightCount + index];
|
|
61
|
+
return DirectionalLight(light.color, light.direction);
|
|
62
|
+
}
|
|
71
63
|
|
|
72
64
|
float getPointLightAttenuation(PointLight pointLight, float distance) {
|
|
73
65
|
return pointLight.attenuation.x
|
|
@@ -75,6 +67,20 @@ float getPointLightAttenuation(PointLight pointLight, float distance) {
|
|
|
75
67
|
+ pointLight.attenuation.z * distance * distance;
|
|
76
68
|
}
|
|
77
69
|
|
|
70
|
+
float getSpotLightAttenuation(SpotLight spotLight, vec3 positionWorldspace) {
|
|
71
|
+
vec3 light_direction = normalize(positionWorldspace - spotLight.position);
|
|
72
|
+
float coneFactor = smoothstep(
|
|
73
|
+
spotLight.coneCos.y,
|
|
74
|
+
spotLight.coneCos.x,
|
|
75
|
+
dot(normalize(spotLight.direction), light_direction)
|
|
76
|
+
);
|
|
77
|
+
float distanceAttenuation = getPointLightAttenuation(
|
|
78
|
+
PointLight(spotLight.color, spotLight.position, spotLight.attenuation),
|
|
79
|
+
distance(spotLight.position, positionWorldspace)
|
|
80
|
+
);
|
|
81
|
+
return distanceAttenuation / max(coneFactor, 0.0001);
|
|
82
|
+
}
|
|
83
|
+
|
|
78
84
|
// #endif
|
|
79
85
|
`;
|
|
80
86
|
//# sourceMappingURL=lighting-glsl.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lighting-glsl.js","sourceRoot":"","sources":["../../../../src/modules/lighting/lights/lighting-glsl.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,MAAM,CAAC,MAAM,oBAAoB,GAAG,UAAU,CAAC
|
|
1
|
+
{"version":3,"file":"lighting-glsl.js","sourceRoot":"","sources":["../../../../src/modules/lighting/lights/lighting-glsl.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,MAAM,CAAC,MAAM,oBAAoB,GAAG,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiF9C,CAAC"}
|