@luma.gl/shadertools 9.3.0-alpha.6 → 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 +2550 -330
- package/dist/dist.min.js +1803 -283
- package/dist/index.cjs +2495 -358
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +9 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/preprocessor/preprocessor.d.ts.map +1 -1
- package/dist/lib/preprocessor/preprocessor.js +4 -3
- 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 +12 -2
- 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 +11 -5
- 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 +7 -6
- package/dist/modules/engine/skin/skin.d.ts.map +1 -1
- package/dist/modules/engine/skin/skin.js +3 -5
- package/dist/modules/engine/skin/skin.js.map +1 -1
- 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 -55
- 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 +43 -65
- package/dist/modules/lighting/lights/lighting-wgsl.js.map +1 -1
- package/dist/modules/lighting/lights/lighting.d.ts +104 -86
- package/dist/modules/lighting/lights/lighting.d.ts.map +1 -1
- package/dist/modules/lighting/lights/lighting.js +96 -83
- 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 +706 -50
- package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts +110 -61
- 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 +2 -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 -1
- package/dist/modules/lighting/phong-material/phong-shaders-wgsl.d.ts.map +1 -1
- package/dist/modules/lighting/phong-material/phong-shaders-wgsl.js +36 -5
- 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/package.json +3 -3
- package/src/index.ts +19 -2
- package/src/lib/preprocessor/preprocessor.ts +6 -3
- package/src/lib/shader-assembler.ts +17 -2
- 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 +16 -6
- 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 +3 -5
- 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 -55
- package/src/modules/lighting/lights/lighting-wgsl.ts +43 -65
- package/src/modules/lighting/lights/lighting.ts +186 -123
- 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 +706 -50
- package/src/modules/lighting/pbr-material/pbr-material.ts +111 -18
- package/src/modules/lighting/pbr-material/pbr-projection.ts +2 -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 +36 -5
- 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
|
@@ -15,93 +15,71 @@ struct PointLight {
|
|
|
15
15
|
attenuation: vec3<f32>, // 2nd order x:Constant-y:Linear-z:Exponential
|
|
16
16
|
};
|
|
17
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
|
+
|
|
18
26
|
struct DirectionalLight {
|
|
19
27
|
color: vec3<f32>,
|
|
20
28
|
direction: vec3<f32>,
|
|
21
29
|
};
|
|
22
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
|
+
|
|
23
39
|
struct lightingUniforms {
|
|
24
40
|
enabled: i32,
|
|
25
|
-
lightType: i32,
|
|
26
|
-
|
|
27
41
|
directionalLightCount: i32,
|
|
28
42
|
pointLightCount: i32,
|
|
29
|
-
|
|
43
|
+
spotLightCount: i32,
|
|
30
44
|
ambientColor: vec3<f32>,
|
|
31
|
-
|
|
32
|
-
lightColor0: vec3<f32>,
|
|
33
|
-
lightPosition0: vec3<f32>,
|
|
34
|
-
lightDirection0: vec3<f32>,
|
|
35
|
-
lightAttenuation0: vec3<f32>,
|
|
36
|
-
|
|
37
|
-
lightColor1: vec3<f32>,
|
|
38
|
-
lightPosition1: vec3<f32>,
|
|
39
|
-
lightDirection1: vec3<f32>,
|
|
40
|
-
lightAttenuation1: vec3<f32>,
|
|
41
|
-
|
|
42
|
-
lightColor2: vec3<f32>,
|
|
43
|
-
lightPosition2: vec3<f32>,
|
|
44
|
-
lightDirection2: vec3<f32>,
|
|
45
|
-
lightAttenuation2: vec3<f32>,
|
|
46
|
-
|
|
47
|
-
lightColor3: vec3<f32>,
|
|
48
|
-
lightPosition3: vec3<f32>,
|
|
49
|
-
lightDirection3: vec3<f32>,
|
|
50
|
-
lightAttenuation3: vec3<f32>,
|
|
51
|
-
|
|
52
|
-
lightColor4: vec3<f32>,
|
|
53
|
-
lightPosition4: vec3<f32>,
|
|
54
|
-
lightDirection4: vec3<f32>,
|
|
55
|
-
lightAttenuation4: vec3<f32>,
|
|
45
|
+
lights: array<UniformLight, 5>,
|
|
56
46
|
};
|
|
57
47
|
|
|
58
|
-
|
|
59
|
-
@binding(1) @group(0) var<uniform> lighting : lightingUniforms;
|
|
48
|
+
@group(2) @binding(auto) var<uniform> lighting : lightingUniforms;
|
|
60
49
|
|
|
61
50
|
fn lighting_getPointLight(index: i32) -> PointLight {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
case 2: {
|
|
70
|
-
return PointLight(lighting.lightColor2, lighting.lightPosition2, lighting.lightAttenuation2);
|
|
71
|
-
}
|
|
72
|
-
case 3: {
|
|
73
|
-
return PointLight(lighting.lightColor3, lighting.lightPosition3, lighting.lightAttenuation3);
|
|
74
|
-
}
|
|
75
|
-
case 4, default: {
|
|
76
|
-
return PointLight(lighting.lightColor4, lighting.lightPosition4, lighting.lightAttenuation4);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
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);
|
|
79
58
|
}
|
|
80
59
|
|
|
81
60
|
fn lighting_getDirectionalLight(index: i32) -> DirectionalLight {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
case 1: {
|
|
87
|
-
return DirectionalLight(lighting.lightColor1, lighting.lightDirection1);
|
|
88
|
-
}
|
|
89
|
-
case 2: {
|
|
90
|
-
return DirectionalLight(lighting.lightColor2, lighting.lightDirection2);
|
|
91
|
-
}
|
|
92
|
-
case 3: {
|
|
93
|
-
return DirectionalLight(lighting.lightColor3, lighting.lightDirection3);
|
|
94
|
-
}
|
|
95
|
-
case 4, default: {
|
|
96
|
-
return DirectionalLight(lighting.lightColor4, lighting.lightDirection4);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
61
|
+
let light = lighting.lights[lighting.pointLightCount + lighting.spotLightCount + index];
|
|
62
|
+
return DirectionalLight(light.color, light.direction);
|
|
63
|
+
}
|
|
100
64
|
|
|
101
65
|
fn getPointLightAttenuation(pointLight: PointLight, distance: f32) -> f32 {
|
|
102
66
|
return pointLight.attenuation.x
|
|
103
67
|
+ pointLight.attenuation.y * distance
|
|
104
68
|
+ pointLight.attenuation.z * distance * distance;
|
|
105
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
|
+
}
|
|
106
84
|
`;
|
|
107
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,67 +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>;
|
|
55
|
-
lightColor3: Readonly<NumberArray3>;
|
|
56
|
-
lightPosition3: Readonly<NumberArray3>;
|
|
57
|
-
lightDirection3: Readonly<NumberArray3>;
|
|
58
|
-
lightAttenuation3: Readonly<NumberArray3>;
|
|
59
|
-
lightColor4: Readonly<NumberArray3>;
|
|
60
|
-
lightPosition4: Readonly<NumberArray3>;
|
|
61
|
-
lightDirection4: Readonly<NumberArray3>;
|
|
62
|
-
lightAttenuation4: 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>;
|
|
63
110
|
};
|
|
64
|
-
/**
|
|
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
|
+
*/
|
|
65
117
|
export declare const lighting: {
|
|
66
118
|
readonly props: LightingProps;
|
|
67
119
|
readonly uniforms: LightingUniforms;
|
|
@@ -69,63 +121,29 @@ export declare const lighting: {
|
|
|
69
121
|
readonly defines: {};
|
|
70
122
|
readonly uniformTypes: {
|
|
71
123
|
readonly enabled: "i32";
|
|
72
|
-
readonly lightType: "i32";
|
|
73
124
|
readonly directionalLightCount: "i32";
|
|
74
125
|
readonly pointLightCount: "i32";
|
|
126
|
+
readonly spotLightCount: "i32";
|
|
75
127
|
readonly ambientColor: "vec3<f32>";
|
|
76
|
-
readonly
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
readonly lightAttenuation1: "vec3<f32>";
|
|
84
|
-
readonly lightColor2: "vec3<f32>";
|
|
85
|
-
readonly lightPosition2: "vec3<f32>";
|
|
86
|
-
readonly lightDirection2: "vec3<f32>";
|
|
87
|
-
readonly lightAttenuation2: "vec3<f32>";
|
|
88
|
-
readonly lightColor3: "vec3<f32>";
|
|
89
|
-
readonly lightPosition3: "vec3<f32>";
|
|
90
|
-
readonly lightDirection3: "vec3<f32>";
|
|
91
|
-
readonly lightAttenuation3: "vec3<f32>";
|
|
92
|
-
readonly lightColor4: "vec3<f32>";
|
|
93
|
-
readonly lightPosition4: "vec3<f32>";
|
|
94
|
-
readonly lightDirection4: "vec3<f32>";
|
|
95
|
-
readonly lightAttenuation4: "vec3<f32>";
|
|
96
|
-
};
|
|
97
|
-
readonly defaultUniforms: {
|
|
98
|
-
readonly enabled: 1;
|
|
99
|
-
readonly lightType: LIGHT_TYPE.POINT;
|
|
100
|
-
readonly directionalLightCount: 0;
|
|
101
|
-
readonly pointLightCount: 0;
|
|
102
|
-
readonly ambientColor: readonly [0.1, 0.1, 0.1];
|
|
103
|
-
readonly lightColor0: readonly [1, 1, 1];
|
|
104
|
-
readonly lightPosition0: readonly [1, 1, 2];
|
|
105
|
-
readonly lightDirection0: readonly [1, 1, 1];
|
|
106
|
-
readonly lightAttenuation0: readonly [1, 0, 0];
|
|
107
|
-
readonly lightColor1: readonly [1, 1, 1];
|
|
108
|
-
readonly lightPosition1: readonly [1, 1, 2];
|
|
109
|
-
readonly lightDirection1: readonly [1, 1, 1];
|
|
110
|
-
readonly lightAttenuation1: readonly [1, 0, 0];
|
|
111
|
-
readonly lightColor2: readonly [1, 1, 1];
|
|
112
|
-
readonly lightPosition2: readonly [1, 1, 2];
|
|
113
|
-
readonly lightDirection2: readonly [1, 1, 1];
|
|
114
|
-
readonly lightAttenuation2: readonly [1, 0, 0];
|
|
115
|
-
readonly lightColor3: readonly [1, 1, 1];
|
|
116
|
-
readonly lightPosition3: readonly [1, 1, 2];
|
|
117
|
-
readonly lightDirection3: readonly [1, 1, 1];
|
|
118
|
-
readonly lightAttenuation3: readonly [1, 0, 0];
|
|
119
|
-
readonly lightColor4: readonly [1, 1, 1];
|
|
120
|
-
readonly lightPosition4: readonly [1, 1, 2];
|
|
121
|
-
readonly lightDirection4: readonly [1, 1, 1];
|
|
122
|
-
readonly lightAttenuation4: 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];
|
|
123
135
|
};
|
|
124
|
-
readonly
|
|
125
|
-
readonly
|
|
126
|
-
|
|
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\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";
|
|
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\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";
|
|
127
145
|
readonly getUniforms: typeof getUniforms;
|
|
128
146
|
};
|
|
129
|
-
declare function getUniforms(props?: LightingProps,
|
|
147
|
+
declare function getUniforms(props?: LightingProps, _prevUniforms?: Partial<LightingUniforms>): LightingUniforms;
|
|
130
148
|
export {};
|
|
131
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":"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"}
|