@luma.gl/shadertools 9.2.6 → 9.3.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dist.dev.js +4798 -6439
- package/dist/dist.min.js +2047 -311
- package/dist/index.cjs +3033 -507
- 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/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 +214 -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 +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 +209 -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 +4 -2
- 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 +581 -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 +850 -107
- package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts +172 -41
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material.js +109 -1
- 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/preprocessor/preprocessor.ts +44 -8
- package/src/lib/shader-assembler.ts +25 -3
- package/src/lib/shader-assembly/assemble-shaders.ts +384 -12
- package/src/lib/shader-assembly/wgsl-binding-debug.ts +216 -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 +346 -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 +4 -2
- package/src/modules/lighting/pbr-material/pbr-material-glsl.ts +581 -28
- package/src/modules/lighting/pbr-material/pbr-material-wgsl.ts +850 -107
- package/src/modules/lighting/pbr-material/pbr-material.ts +185 -5
- 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
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
// Copyright (c) vis.gl contributors
|
|
4
4
|
export const lightingUniformsWGSL = /* wgsl */ `\
|
|
5
5
|
// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
|
|
6
|
+
const MAX_LIGHTS: i32 = 5;
|
|
7
|
+
|
|
6
8
|
struct AmbientLight {
|
|
7
9
|
color: vec3<f32>,
|
|
8
10
|
};
|
|
@@ -13,45 +15,71 @@ struct PointLight {
|
|
|
13
15
|
attenuation: vec3<f32>, // 2nd order x:Constant-y:Linear-z:Exponential
|
|
14
16
|
};
|
|
15
17
|
|
|
18
|
+
struct SpotLight {
|
|
19
|
+
color: vec3<f32>,
|
|
20
|
+
position: vec3<f32>,
|
|
21
|
+
direction: vec3<f32>,
|
|
22
|
+
attenuation: vec3<f32>,
|
|
23
|
+
coneCos: vec2<f32>,
|
|
24
|
+
};
|
|
25
|
+
|
|
16
26
|
struct DirectionalLight {
|
|
17
27
|
color: vec3<f32>,
|
|
18
28
|
direction: vec3<f32>,
|
|
19
29
|
};
|
|
20
30
|
|
|
31
|
+
struct UniformLight {
|
|
32
|
+
color: vec3<f32>,
|
|
33
|
+
position: vec3<f32>,
|
|
34
|
+
direction: vec3<f32>,
|
|
35
|
+
attenuation: vec3<f32>,
|
|
36
|
+
coneCos: vec2<f32>,
|
|
37
|
+
};
|
|
38
|
+
|
|
21
39
|
struct lightingUniforms {
|
|
22
40
|
enabled: i32,
|
|
23
|
-
pointLightCount: i32,
|
|
24
41
|
directionalLightCount: i32,
|
|
25
|
-
|
|
42
|
+
pointLightCount: i32,
|
|
43
|
+
spotLightCount: i32,
|
|
26
44
|
ambientColor: vec3<f32>,
|
|
27
|
-
|
|
28
|
-
// TODO - support multiple lights by uncommenting arrays below
|
|
29
|
-
lightType: i32,
|
|
30
|
-
lightColor: vec3<f32>,
|
|
31
|
-
lightDirection: vec3<f32>,
|
|
32
|
-
lightPosition: vec3<f32>,
|
|
33
|
-
lightAttenuation: vec3<f32>,
|
|
34
|
-
|
|
35
|
-
// AmbientLight ambientLight;
|
|
36
|
-
// PointLight pointLight[MAX_LIGHTS];
|
|
37
|
-
// DirectionalLight directionalLight[MAX_LIGHTS];
|
|
45
|
+
lights: array<UniformLight, 5>,
|
|
38
46
|
};
|
|
39
47
|
|
|
40
|
-
|
|
41
|
-
@binding(1) @group(0) var<uniform> lighting : lightingUniforms;
|
|
48
|
+
@group(2) @binding(auto) var<uniform> lighting : lightingUniforms;
|
|
42
49
|
|
|
43
50
|
fn lighting_getPointLight(index: i32) -> PointLight {
|
|
44
|
-
|
|
51
|
+
let light = lighting.lights[index];
|
|
52
|
+
return PointLight(light.color, light.position, light.attenuation);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
fn lighting_getSpotLight(index: i32) -> SpotLight {
|
|
56
|
+
let light = lighting.lights[lighting.pointLightCount + index];
|
|
57
|
+
return SpotLight(light.color, light.position, light.direction, light.attenuation, light.coneCos);
|
|
45
58
|
}
|
|
46
59
|
|
|
47
60
|
fn lighting_getDirectionalLight(index: i32) -> DirectionalLight {
|
|
48
|
-
|
|
49
|
-
|
|
61
|
+
let light = lighting.lights[lighting.pointLightCount + lighting.spotLightCount + index];
|
|
62
|
+
return DirectionalLight(light.color, light.direction);
|
|
63
|
+
}
|
|
50
64
|
|
|
51
65
|
fn getPointLightAttenuation(pointLight: PointLight, distance: f32) -> f32 {
|
|
52
66
|
return pointLight.attenuation.x
|
|
53
67
|
+ pointLight.attenuation.y * distance
|
|
54
68
|
+ pointLight.attenuation.z * distance * distance;
|
|
55
69
|
}
|
|
70
|
+
|
|
71
|
+
fn getSpotLightAttenuation(spotLight: SpotLight, positionWorldspace: vec3<f32>) -> f32 {
|
|
72
|
+
let lightDirection = normalize(positionWorldspace - spotLight.position);
|
|
73
|
+
let coneFactor = smoothstep(
|
|
74
|
+
spotLight.coneCos.y,
|
|
75
|
+
spotLight.coneCos.x,
|
|
76
|
+
dot(normalize(spotLight.direction), lightDirection)
|
|
77
|
+
);
|
|
78
|
+
let distanceAttenuation = getPointLightAttenuation(
|
|
79
|
+
PointLight(spotLight.color, spotLight.position, spotLight.attenuation),
|
|
80
|
+
distance(spotLight.position, positionWorldspace)
|
|
81
|
+
);
|
|
82
|
+
return distanceAttenuation / max(coneFactor, 0.0001);
|
|
83
|
+
}
|
|
56
84
|
`;
|
|
57
85
|
//# sourceMappingURL=lighting-wgsl.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lighting-wgsl.js","sourceRoot":"","sources":["../../../../src/modules/lighting/lights/lighting-wgsl.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,MAAM,CAAC,MAAM,oBAAoB,GAAG,UAAU,CAAC
|
|
1
|
+
{"version":3,"file":"lighting-wgsl.js","sourceRoot":"","sources":["../../../../src/modules/lighting/lights/lighting-wgsl.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,MAAM,CAAC,MAAM,oBAAoB,GAAG,UAAU,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgF9C,CAAC"}
|
|
@@ -1,59 +1,119 @@
|
|
|
1
|
-
import type { NumberArray3 } from '@math.gl/core';
|
|
2
|
-
/**
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
DIRECTIONAL = 1
|
|
6
|
-
}
|
|
7
|
-
/** Lighting helper types */
|
|
8
|
-
export type Light = AmbientLight | PointLight | DirectionalLight;
|
|
1
|
+
import type { NumberArray2, NumberArray3 } from '@math.gl/core';
|
|
2
|
+
/** Supported light source descriptions accepted by the lighting shader module. */
|
|
3
|
+
export type Light = AmbientLight | PointLight | SpotLight | DirectionalLight;
|
|
4
|
+
/** Ambient light contribution shared across the entire scene. */
|
|
9
5
|
export type AmbientLight = {
|
|
6
|
+
/** Discriminator used to identify ambient lights in `lights: Light[]`. */
|
|
10
7
|
type: 'ambient';
|
|
8
|
+
/** RGB light color in the existing `0..255` convention used by luma.gl materials. */
|
|
11
9
|
color?: Readonly<NumberArray3>;
|
|
10
|
+
/** Scalar intensity multiplier applied to the light color. */
|
|
12
11
|
intensity?: number;
|
|
13
12
|
};
|
|
13
|
+
/** Omnidirectional point light emitted from a world-space position. */
|
|
14
14
|
export type PointLight = {
|
|
15
|
+
/** Discriminator used to identify point lights in `lights: Light[]`. */
|
|
15
16
|
type: 'point';
|
|
17
|
+
/** World-space light position. */
|
|
16
18
|
position: Readonly<NumberArray3>;
|
|
19
|
+
/** RGB light color in the existing `0..255` convention used by luma.gl materials. */
|
|
17
20
|
color?: Readonly<NumberArray3>;
|
|
21
|
+
/** Scalar intensity multiplier applied to the light color. */
|
|
18
22
|
intensity?: number;
|
|
23
|
+
/** Constant, linear, and quadratic attenuation coefficients. */
|
|
19
24
|
attenuation?: Readonly<NumberArray3>;
|
|
20
25
|
};
|
|
26
|
+
/** Directional light defined only by its incoming world-space direction. */
|
|
21
27
|
export type DirectionalLight = {
|
|
28
|
+
/** Discriminator used to identify directional lights in `lights: Light[]`. */
|
|
22
29
|
type: 'directional';
|
|
30
|
+
/** World-space light direction. */
|
|
23
31
|
direction: Readonly<NumberArray3>;
|
|
32
|
+
/** RGB light color in the existing `0..255` convention used by luma.gl materials. */
|
|
24
33
|
color?: Readonly<NumberArray3>;
|
|
34
|
+
/** Scalar intensity multiplier applied to the light color. */
|
|
25
35
|
intensity?: number;
|
|
26
36
|
};
|
|
37
|
+
/** Cone-shaped light emitted from a position and focused along a direction. */
|
|
38
|
+
export type SpotLight = {
|
|
39
|
+
/** Discriminator used to identify spot lights in `lights: Light[]`. */
|
|
40
|
+
type: 'spot';
|
|
41
|
+
/** World-space light position. */
|
|
42
|
+
position: Readonly<NumberArray3>;
|
|
43
|
+
/** World-space light direction. */
|
|
44
|
+
direction: Readonly<NumberArray3>;
|
|
45
|
+
/** RGB light color in the existing `0..255` convention used by luma.gl materials. */
|
|
46
|
+
color?: Readonly<NumberArray3>;
|
|
47
|
+
/** Scalar intensity multiplier applied to the light color. */
|
|
48
|
+
intensity?: number;
|
|
49
|
+
/** Constant, linear, and quadratic attenuation coefficients. */
|
|
50
|
+
attenuation?: Readonly<NumberArray3>;
|
|
51
|
+
/** Inner spotlight cone angle in radians. */
|
|
52
|
+
innerConeAngle?: number;
|
|
53
|
+
/** Outer spotlight cone angle in radians. */
|
|
54
|
+
outerConeAngle?: number;
|
|
55
|
+
};
|
|
56
|
+
/** Public JavaScript props accepted by the `lighting` shader module. */
|
|
27
57
|
export type LightingProps = {
|
|
58
|
+
/** Enables or disables lighting calculations for the module. */
|
|
28
59
|
enabled?: boolean;
|
|
60
|
+
/** Preferred API for supplying mixed ambient, point, spot, and directional lights. */
|
|
29
61
|
lights?: Light[];
|
|
30
|
-
/**
|
|
62
|
+
/**
|
|
63
|
+
* Legacy ambient-light prop.
|
|
64
|
+
* @deprecated Use `lights` with `{type: 'ambient', ...}` entries instead.
|
|
65
|
+
*/
|
|
31
66
|
ambientLight?: AmbientLight;
|
|
32
|
-
/**
|
|
67
|
+
/**
|
|
68
|
+
* Legacy point-light prop.
|
|
69
|
+
* @deprecated Use `lights` with `{type: 'point', ...}` entries instead.
|
|
70
|
+
*/
|
|
33
71
|
pointLights?: PointLight[];
|
|
34
|
-
/**
|
|
72
|
+
/**
|
|
73
|
+
* Legacy spot-light prop.
|
|
74
|
+
* @deprecated Use `lights` with `{type: 'spot', ...}` entries instead.
|
|
75
|
+
*/
|
|
76
|
+
spotLights?: SpotLight[];
|
|
77
|
+
/**
|
|
78
|
+
* Legacy directional-light prop.
|
|
79
|
+
* @deprecated Use `lights` with `{type: 'directional', ...}` entries instead.
|
|
80
|
+
*/
|
|
35
81
|
directionalLights?: DirectionalLight[];
|
|
36
82
|
};
|
|
83
|
+
/** Packed per-light data written into the module's fixed-size uniform array. */
|
|
84
|
+
export type LightingLightUniform = {
|
|
85
|
+
/** Light color converted to normalized shader-space RGB. */
|
|
86
|
+
color: Readonly<NumberArray3>;
|
|
87
|
+
/** World-space light position or a default placeholder for non-positional lights. */
|
|
88
|
+
position: Readonly<NumberArray3>;
|
|
89
|
+
/** World-space light direction or a default placeholder for positional lights. */
|
|
90
|
+
direction: Readonly<NumberArray3>;
|
|
91
|
+
/** Constant, linear, and quadratic attenuation coefficients. */
|
|
92
|
+
attenuation: Readonly<NumberArray3>;
|
|
93
|
+
/** Cosines of the inner and outer spotlight cone angles. */
|
|
94
|
+
coneCos: Readonly<NumberArray2>;
|
|
95
|
+
};
|
|
96
|
+
/** Fully normalized uniform values produced by the `lighting` shader module. */
|
|
37
97
|
export type LightingUniforms = {
|
|
98
|
+
/** `1` when lighting is enabled, otherwise `0`. */
|
|
38
99
|
enabled: number;
|
|
39
|
-
|
|
100
|
+
/** Number of packed directional lights in the `lights` array. */
|
|
40
101
|
directionalLightCount: number;
|
|
102
|
+
/** Number of packed point lights in the `lights` array. */
|
|
41
103
|
pointLightCount: number;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
lightPosition1: Readonly<NumberArray3>;
|
|
49
|
-
lightDirection1: Readonly<NumberArray3>;
|
|
50
|
-
lightAttenuation1: Readonly<NumberArray3>;
|
|
51
|
-
lightColor2: Readonly<NumberArray3>;
|
|
52
|
-
lightPosition2: Readonly<NumberArray3>;
|
|
53
|
-
lightDirection2: Readonly<NumberArray3>;
|
|
54
|
-
lightAttenuation2: Readonly<NumberArray3>;
|
|
104
|
+
/** Number of packed spot lights in the `lights` array. */
|
|
105
|
+
spotLightCount: number;
|
|
106
|
+
/** Accumulated ambient color converted to normalized shader-space RGB. */
|
|
107
|
+
ambientColor: Readonly<NumberArray3>;
|
|
108
|
+
/** Packed trailing array of non-ambient light structs. */
|
|
109
|
+
lights: ReadonlyArray<LightingLightUniform>;
|
|
55
110
|
};
|
|
56
|
-
/**
|
|
111
|
+
/**
|
|
112
|
+
* Portable lighting shader module shared by the Phong, Gouraud, and PBR material modules.
|
|
113
|
+
*
|
|
114
|
+
* The public JavaScript API accepts `lights: Light[]`, while the uniform buffer packs
|
|
115
|
+
* non-ambient lights into a fixed-size trailing array for portability across WebGL2 and WebGPU.
|
|
116
|
+
*/
|
|
57
117
|
export declare const lighting: {
|
|
58
118
|
readonly props: LightingProps;
|
|
59
119
|
readonly uniforms: LightingUniforms;
|
|
@@ -61,47 +121,29 @@ export declare const lighting: {
|
|
|
61
121
|
readonly defines: {};
|
|
62
122
|
readonly uniformTypes: {
|
|
63
123
|
readonly enabled: "i32";
|
|
64
|
-
readonly lightType: "i32";
|
|
65
124
|
readonly directionalLightCount: "i32";
|
|
66
125
|
readonly pointLightCount: "i32";
|
|
126
|
+
readonly spotLightCount: "i32";
|
|
67
127
|
readonly ambientColor: "vec3<f32>";
|
|
68
|
-
readonly
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
readonly lightAttenuation1: "vec3<f32>";
|
|
76
|
-
readonly lightColor2: "vec3<f32>";
|
|
77
|
-
readonly lightPosition2: "vec3<f32>";
|
|
78
|
-
readonly lightDirection2: "vec3<f32>";
|
|
79
|
-
readonly lightAttenuation2: "vec3<f32>";
|
|
80
|
-
};
|
|
81
|
-
readonly defaultUniforms: {
|
|
82
|
-
readonly enabled: 1;
|
|
83
|
-
readonly lightType: LIGHT_TYPE.POINT;
|
|
84
|
-
readonly directionalLightCount: 0;
|
|
85
|
-
readonly pointLightCount: 0;
|
|
86
|
-
readonly ambientColor: readonly [0.1, 0.1, 0.1];
|
|
87
|
-
readonly lightColor0: readonly [1, 1, 1];
|
|
88
|
-
readonly lightPosition0: readonly [1, 1, 2];
|
|
89
|
-
readonly lightDirection0: readonly [1, 1, 1];
|
|
90
|
-
readonly lightAttenuation0: readonly [1, 0, 0];
|
|
91
|
-
readonly lightColor1: readonly [1, 1, 1];
|
|
92
|
-
readonly lightPosition1: readonly [1, 1, 2];
|
|
93
|
-
readonly lightDirection1: readonly [1, 1, 1];
|
|
94
|
-
readonly lightAttenuation1: readonly [1, 0, 0];
|
|
95
|
-
readonly lightColor2: readonly [1, 1, 1];
|
|
96
|
-
readonly lightPosition2: readonly [1, 1, 2];
|
|
97
|
-
readonly lightDirection2: readonly [1, 1, 1];
|
|
98
|
-
readonly lightAttenuation2: readonly [1, 0, 0];
|
|
128
|
+
readonly lights: readonly [{
|
|
129
|
+
readonly color: "vec3<f32>";
|
|
130
|
+
readonly position: "vec3<f32>";
|
|
131
|
+
readonly direction: "vec3<f32>";
|
|
132
|
+
readonly attenuation: "vec3<f32>";
|
|
133
|
+
readonly coneCos: "vec2<f32>";
|
|
134
|
+
}, 5];
|
|
99
135
|
};
|
|
100
|
-
readonly
|
|
101
|
-
readonly
|
|
102
|
-
|
|
136
|
+
readonly defaultUniforms: LightingUniforms;
|
|
137
|
+
readonly bindingLayout: readonly [{
|
|
138
|
+
readonly name: "lighting";
|
|
139
|
+
readonly group: 2;
|
|
140
|
+
}];
|
|
141
|
+
readonly firstBindingSlot: 0;
|
|
142
|
+
readonly source: "// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))\nconst MAX_LIGHTS: i32 = 5;\n\nstruct AmbientLight {\n color: vec3<f32>,\n};\n\nstruct PointLight {\n color: vec3<f32>,\n position: vec3<f32>,\n attenuation: vec3<f32>, // 2nd order x:Constant-y:Linear-z:Exponential\n};\n\nstruct SpotLight {\n color: vec3<f32>,\n position: vec3<f32>,\n direction: vec3<f32>,\n attenuation: vec3<f32>,\n coneCos: vec2<f32>,\n};\n\nstruct DirectionalLight {\n color: vec3<f32>,\n direction: vec3<f32>,\n};\n\nstruct UniformLight {\n color: vec3<f32>,\n position: vec3<f32>,\n direction: vec3<f32>,\n attenuation: vec3<f32>,\n coneCos: vec2<f32>,\n};\n\nstruct lightingUniforms {\n enabled: i32,\n directionalLightCount: i32,\n pointLightCount: i32,\n spotLightCount: i32,\n ambientColor: vec3<f32>,\n lights: array<UniformLight, 5>,\n};\n\n@group(2) @binding(auto) var<uniform> lighting : lightingUniforms;\n\nfn lighting_getPointLight(index: i32) -> PointLight {\n let light = lighting.lights[index];\n return PointLight(light.color, light.position, light.attenuation);\n}\n\nfn lighting_getSpotLight(index: i32) -> SpotLight {\n let light = lighting.lights[lighting.pointLightCount + index];\n return SpotLight(light.color, light.position, light.direction, light.attenuation, light.coneCos);\n}\n\nfn lighting_getDirectionalLight(index: i32) -> DirectionalLight {\n let light = lighting.lights[lighting.pointLightCount + lighting.spotLightCount + index];\n return DirectionalLight(light.color, light.direction);\n}\n\nfn getPointLightAttenuation(pointLight: PointLight, distance: f32) -> f32 {\n return pointLight.attenuation.x\n + pointLight.attenuation.y * distance\n + pointLight.attenuation.z * distance * distance;\n}\n\nfn getSpotLightAttenuation(spotLight: SpotLight, positionWorldspace: vec3<f32>) -> f32 {\n let lightDirection = normalize(positionWorldspace - spotLight.position);\n let coneFactor = smoothstep(\n spotLight.coneCos.y,\n spotLight.coneCos.x,\n dot(normalize(spotLight.direction), lightDirection)\n );\n let 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";
|
|
143
|
+
readonly vs: "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\nlayout(std140) uniform 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";
|
|
144
|
+
readonly fs: "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\nlayout(std140) uniform 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";
|
|
103
145
|
readonly getUniforms: typeof getUniforms;
|
|
104
146
|
};
|
|
105
|
-
declare function getUniforms(props?: LightingProps,
|
|
147
|
+
declare function getUniforms(props?: LightingProps, _prevUniforms?: Partial<LightingUniforms>): LightingUniforms;
|
|
106
148
|
export {};
|
|
107
149
|
//# sourceMappingURL=lighting.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lighting.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/lights/lighting.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"lighting.d.ts","sourceRoot":"","sources":["../../../../src/modules/lighting/lights/lighting.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAC,YAAY,EAAE,YAAY,EAAC,MAAM,eAAe,CAAC;AAQ9D,kFAAkF;AAClF,MAAM,MAAM,KAAK,GAAG,YAAY,GAAG,UAAU,GAAG,SAAS,GAAG,gBAAgB,CAAC;AAE7E,iEAAiE;AACjE,MAAM,MAAM,YAAY,GAAG;IACzB,0EAA0E;IAC1E,IAAI,EAAE,SAAS,CAAC;IAChB,qFAAqF;IACrF,KAAK,CAAC,EAAE,Q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,aAAa;uBACV,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyBoC,CAAC;AAEvE,iBAAS,WAAW,CAClB,KAAK,CAAC,EAAE,aAAa,EACrB,aAAa,GAAE,OAAO,CAAC,gBAAgB,CAAM,GAC5C,gBAAgB,CAuClB"}
|
|
@@ -8,14 +8,19 @@ import { lightingUniformsWGSL } from "./lighting-wgsl.js";
|
|
|
8
8
|
const MAX_LIGHTS = 5;
|
|
9
9
|
/** Whether to divide */
|
|
10
10
|
const COLOR_FACTOR = 255.0;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
11
|
+
const LIGHT_UNIFORM_TYPE = {
|
|
12
|
+
color: 'vec3<f32>',
|
|
13
|
+
position: 'vec3<f32>',
|
|
14
|
+
direction: 'vec3<f32>',
|
|
15
|
+
attenuation: 'vec3<f32>',
|
|
16
|
+
coneCos: 'vec2<f32>'
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Portable lighting shader module shared by the Phong, Gouraud, and PBR material modules.
|
|
20
|
+
*
|
|
21
|
+
* The public JavaScript API accepts `lights: Light[]`, while the uniform buffer packs
|
|
22
|
+
* non-ambient lights into a fixed-size trailing array for portability across WebGL2 and WebGPU.
|
|
23
|
+
*/
|
|
19
24
|
export const lighting = {
|
|
20
25
|
props: {},
|
|
21
26
|
uniforms: {},
|
|
@@ -25,108 +30,112 @@ export const lighting = {
|
|
|
25
30
|
},
|
|
26
31
|
uniformTypes: {
|
|
27
32
|
enabled: 'i32',
|
|
28
|
-
lightType: 'i32',
|
|
29
33
|
directionalLightCount: 'i32',
|
|
30
34
|
pointLightCount: 'i32',
|
|
35
|
+
spotLightCount: 'i32',
|
|
31
36
|
ambientColor: 'vec3<f32>',
|
|
32
|
-
|
|
33
|
-
lightColor0: 'vec3<f32>',
|
|
34
|
-
lightPosition0: 'vec3<f32>',
|
|
35
|
-
// TODO - could combine direction and attenuation
|
|
36
|
-
lightDirection0: 'vec3<f32>',
|
|
37
|
-
lightAttenuation0: 'vec3<f32>',
|
|
38
|
-
lightColor1: 'vec3<f32>',
|
|
39
|
-
lightPosition1: 'vec3<f32>',
|
|
40
|
-
lightDirection1: 'vec3<f32>',
|
|
41
|
-
lightAttenuation1: 'vec3<f32>',
|
|
42
|
-
lightColor2: 'vec3<f32>',
|
|
43
|
-
lightPosition2: 'vec3<f32>',
|
|
44
|
-
lightDirection2: 'vec3<f32>',
|
|
45
|
-
lightAttenuation2: 'vec3<f32>'
|
|
46
|
-
},
|
|
47
|
-
defaultUniforms: {
|
|
48
|
-
enabled: 1,
|
|
49
|
-
lightType: LIGHT_TYPE.POINT,
|
|
50
|
-
directionalLightCount: 0,
|
|
51
|
-
pointLightCount: 0,
|
|
52
|
-
ambientColor: [0.1, 0.1, 0.1],
|
|
53
|
-
lightColor0: [1, 1, 1],
|
|
54
|
-
lightPosition0: [1, 1, 2],
|
|
55
|
-
// TODO - could combine direction and attenuation
|
|
56
|
-
lightDirection0: [1, 1, 1],
|
|
57
|
-
lightAttenuation0: [1, 0, 0],
|
|
58
|
-
lightColor1: [1, 1, 1],
|
|
59
|
-
lightPosition1: [1, 1, 2],
|
|
60
|
-
lightDirection1: [1, 1, 1],
|
|
61
|
-
lightAttenuation1: [1, 0, 0],
|
|
62
|
-
lightColor2: [1, 1, 1],
|
|
63
|
-
lightPosition2: [1, 1, 2],
|
|
64
|
-
lightDirection2: [1, 1, 1],
|
|
65
|
-
lightAttenuation2: [1, 0, 0]
|
|
37
|
+
lights: [LIGHT_UNIFORM_TYPE, MAX_LIGHTS]
|
|
66
38
|
},
|
|
39
|
+
defaultUniforms: createDefaultLightingUniforms(),
|
|
40
|
+
bindingLayout: [{ name: 'lighting', group: 2 }],
|
|
41
|
+
firstBindingSlot: 0,
|
|
67
42
|
source: lightingUniformsWGSL,
|
|
68
43
|
vs: lightingUniformsGLSL,
|
|
69
44
|
fs: lightingUniformsGLSL,
|
|
70
45
|
getUniforms
|
|
71
46
|
};
|
|
72
|
-
function getUniforms(props,
|
|
47
|
+
function getUniforms(props, _prevUniforms = {}) {
|
|
73
48
|
// Copy props so we can modify
|
|
74
49
|
props = props ? { ...props } : props;
|
|
75
50
|
// TODO legacy
|
|
76
51
|
if (!props) {
|
|
77
|
-
return
|
|
52
|
+
return createDefaultLightingUniforms();
|
|
78
53
|
}
|
|
79
54
|
// Support for array of lights. Type of light is detected by type field
|
|
80
55
|
if (props.lights) {
|
|
81
56
|
props = { ...props, ...extractLightTypes(props.lights), lights: undefined };
|
|
82
57
|
}
|
|
83
58
|
// Specify lights separately
|
|
84
|
-
const { ambientLight, pointLights, directionalLights } = props || {};
|
|
59
|
+
const { ambientLight, pointLights, spotLights, directionalLights } = props || {};
|
|
85
60
|
const hasLights = ambientLight ||
|
|
86
61
|
(pointLights && pointLights.length > 0) ||
|
|
62
|
+
(spotLights && spotLights.length > 0) ||
|
|
87
63
|
(directionalLights && directionalLights.length > 0);
|
|
88
64
|
// TODO - this may not be the correct decision
|
|
89
65
|
if (!hasLights) {
|
|
90
|
-
return {
|
|
66
|
+
return {
|
|
67
|
+
...createDefaultLightingUniforms(),
|
|
68
|
+
enabled: 0
|
|
69
|
+
};
|
|
91
70
|
}
|
|
92
71
|
const uniforms = {
|
|
93
|
-
...
|
|
94
|
-
...
|
|
95
|
-
...getLightSourceUniforms({ ambientLight, pointLights, directionalLights })
|
|
72
|
+
...createDefaultLightingUniforms(),
|
|
73
|
+
...getLightSourceUniforms({ ambientLight, pointLights, spotLights, directionalLights })
|
|
96
74
|
};
|
|
97
75
|
if (props.enabled !== undefined) {
|
|
98
76
|
uniforms.enabled = props.enabled ? 1 : 0;
|
|
99
77
|
}
|
|
100
78
|
return uniforms;
|
|
101
79
|
}
|
|
102
|
-
function getLightSourceUniforms({ ambientLight, pointLights = [], directionalLights = [] }) {
|
|
103
|
-
const
|
|
104
|
-
lightSourceUniforms.ambientColor = convertColor(ambientLight);
|
|
80
|
+
function getLightSourceUniforms({ ambientLight, pointLights = [], spotLights = [], directionalLights = [] }) {
|
|
81
|
+
const lights = createDefaultLightUniforms();
|
|
105
82
|
let currentLight = 0;
|
|
83
|
+
let pointLightCount = 0;
|
|
84
|
+
let spotLightCount = 0;
|
|
85
|
+
let directionalLightCount = 0;
|
|
106
86
|
for (const pointLight of pointLights) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
87
|
+
if (currentLight >= MAX_LIGHTS) {
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
lights[currentLight] = {
|
|
91
|
+
...lights[currentLight],
|
|
92
|
+
color: convertColor(pointLight),
|
|
93
|
+
position: pointLight.position,
|
|
94
|
+
attenuation: pointLight.attenuation || [1, 0, 0]
|
|
95
|
+
};
|
|
96
|
+
currentLight++;
|
|
97
|
+
pointLightCount++;
|
|
98
|
+
}
|
|
99
|
+
for (const spotLight of spotLights) {
|
|
100
|
+
if (currentLight >= MAX_LIGHTS) {
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
lights[currentLight] = {
|
|
104
|
+
...lights[currentLight],
|
|
105
|
+
color: convertColor(spotLight),
|
|
106
|
+
position: spotLight.position,
|
|
107
|
+
direction: spotLight.direction,
|
|
108
|
+
attenuation: spotLight.attenuation || [1, 0, 0],
|
|
109
|
+
coneCos: getSpotConeCos(spotLight)
|
|
110
|
+
};
|
|
112
111
|
currentLight++;
|
|
112
|
+
spotLightCount++;
|
|
113
113
|
}
|
|
114
114
|
for (const directionalLight of directionalLights) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
115
|
+
if (currentLight >= MAX_LIGHTS) {
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
lights[currentLight] = {
|
|
119
|
+
...lights[currentLight],
|
|
120
|
+
color: convertColor(directionalLight),
|
|
121
|
+
direction: directionalLight.direction
|
|
122
|
+
};
|
|
119
123
|
currentLight++;
|
|
124
|
+
directionalLightCount++;
|
|
120
125
|
}
|
|
121
|
-
if (
|
|
122
|
-
log.warn(
|
|
126
|
+
if (pointLights.length + spotLights.length + directionalLights.length > MAX_LIGHTS) {
|
|
127
|
+
log.warn(`MAX_LIGHTS exceeded, truncating to ${MAX_LIGHTS}`)();
|
|
123
128
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
129
|
+
return {
|
|
130
|
+
ambientColor: convertColor(ambientLight),
|
|
131
|
+
directionalLightCount,
|
|
132
|
+
pointLightCount,
|
|
133
|
+
spotLightCount,
|
|
134
|
+
lights
|
|
135
|
+
};
|
|
127
136
|
}
|
|
128
137
|
function extractLightTypes(lights) {
|
|
129
|
-
const lightSources = { pointLights: [], directionalLights: [] };
|
|
138
|
+
const lightSources = { pointLights: [], spotLights: [], directionalLights: [] };
|
|
130
139
|
for (const light of lights || []) {
|
|
131
140
|
switch (light.type) {
|
|
132
141
|
case 'ambient':
|
|
@@ -140,6 +149,9 @@ function extractLightTypes(lights) {
|
|
|
140
149
|
case 'point':
|
|
141
150
|
lightSources.pointLights?.push(light);
|
|
142
151
|
break;
|
|
152
|
+
case 'spot':
|
|
153
|
+
lightSources.spotLights?.push(light);
|
|
154
|
+
break;
|
|
143
155
|
default:
|
|
144
156
|
// eslint-disable-next-line
|
|
145
157
|
// console.warn(light.type);
|
|
@@ -152,4 +164,31 @@ function convertColor(colorDef = {}) {
|
|
|
152
164
|
const { color = [0, 0, 0], intensity = 1.0 } = colorDef;
|
|
153
165
|
return color.map(component => (component * intensity) / COLOR_FACTOR);
|
|
154
166
|
}
|
|
167
|
+
function createDefaultLightingUniforms() {
|
|
168
|
+
return {
|
|
169
|
+
enabled: 1,
|
|
170
|
+
directionalLightCount: 0,
|
|
171
|
+
pointLightCount: 0,
|
|
172
|
+
spotLightCount: 0,
|
|
173
|
+
ambientColor: [0.1, 0.1, 0.1],
|
|
174
|
+
lights: createDefaultLightUniforms()
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
function createDefaultLightUniforms() {
|
|
178
|
+
return Array.from({ length: MAX_LIGHTS }, () => createDefaultLightUniform());
|
|
179
|
+
}
|
|
180
|
+
function createDefaultLightUniform() {
|
|
181
|
+
return {
|
|
182
|
+
color: [1, 1, 1],
|
|
183
|
+
position: [1, 1, 2],
|
|
184
|
+
direction: [1, 1, 1],
|
|
185
|
+
attenuation: [1, 0, 0],
|
|
186
|
+
coneCos: [1, 0]
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
function getSpotConeCos(spotLight) {
|
|
190
|
+
const innerConeAngle = spotLight.innerConeAngle ?? 0;
|
|
191
|
+
const outerConeAngle = spotLight.outerConeAngle ?? Math.PI / 4;
|
|
192
|
+
return [Math.cos(innerConeAngle), Math.cos(outerConeAngle)];
|
|
193
|
+
}
|
|
155
194
|
//# sourceMappingURL=lighting.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lighting.js","sourceRoot":"","sources":["../../../../src/modules/lighting/lights/lighting.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,OAAO,EAAC,GAAG,EAAC,MAAM,eAAe,CAAC;AAElC,OAAO,EAAC,oBAAoB,EAAC,2BAAwB;AACrD,OAAO,EAAC,oBAAoB,EAAC,2BAAwB;AAGrD,mEAAmE;AACnE,MAAM,UAAU,GAAG,CAAC,CAAC;AAErB,wBAAwB;AACxB,MAAM,YAAY,GAAG,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"lighting.js","sourceRoot":"","sources":["../../../../src/modules/lighting/lights/lighting.ts"],"names":[],"mappings":"AAAA,UAAU;AACV,+BAA+B;AAC/B,oCAAoC;AAEpC,OAAO,EAAC,GAAG,EAAC,MAAM,eAAe,CAAC;AAElC,OAAO,EAAC,oBAAoB,EAAC,2BAAwB;AACrD,OAAO,EAAC,oBAAoB,EAAC,2BAAwB;AAGrD,mEAAmE;AACnE,MAAM,U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