@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
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// luma.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// Copyright (c) vis.gl contributors
|
|
4
|
+
|
|
5
|
+
export const LAMBERT_WGSL = /* wgsl */ `\
|
|
6
|
+
struct lambertMaterialUniforms {
|
|
7
|
+
unlit: u32,
|
|
8
|
+
ambient: f32,
|
|
9
|
+
diffuse: f32,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
@group(3) @binding(auto) var<uniform> lambertMaterial : lambertMaterialUniforms;
|
|
13
|
+
|
|
14
|
+
fn lighting_getLightColor(surfaceColor: vec3<f32>, light_direction: vec3<f32>, normal_worldspace: vec3<f32>, color: vec3<f32>) -> vec3<f32> {
|
|
15
|
+
let lambertian: f32 = max(dot(light_direction, normal_worldspace), 0.0);
|
|
16
|
+
return lambertian * lambertMaterial.diffuse * surfaceColor * color;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
fn lighting_getLightColor2(surfaceColor: vec3<f32>, cameraPosition: vec3<f32>, position_worldspace: vec3<f32>, normal_worldspace: vec3<f32>) -> vec3<f32> {
|
|
20
|
+
var lightColor: vec3<f32> = surfaceColor;
|
|
21
|
+
|
|
22
|
+
if (lambertMaterial.unlit != 0u) {
|
|
23
|
+
return surfaceColor;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (lighting.enabled == 0) {
|
|
27
|
+
return lightColor;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
lightColor = lambertMaterial.ambient * surfaceColor * lighting.ambientColor;
|
|
31
|
+
|
|
32
|
+
for (var i: i32 = 0; i < lighting.pointLightCount; i++) {
|
|
33
|
+
let pointLight: PointLight = lighting_getPointLight(i);
|
|
34
|
+
let light_position_worldspace: vec3<f32> = pointLight.position;
|
|
35
|
+
let light_direction: vec3<f32> = normalize(light_position_worldspace - position_worldspace);
|
|
36
|
+
let light_attenuation = getPointLightAttenuation(
|
|
37
|
+
pointLight,
|
|
38
|
+
distance(light_position_worldspace, position_worldspace)
|
|
39
|
+
);
|
|
40
|
+
lightColor += lighting_getLightColor(
|
|
41
|
+
surfaceColor,
|
|
42
|
+
light_direction,
|
|
43
|
+
normal_worldspace,
|
|
44
|
+
pointLight.color / light_attenuation
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
for (var i: i32 = 0; i < lighting.spotLightCount; i++) {
|
|
49
|
+
let spotLight: SpotLight = lighting_getSpotLight(i);
|
|
50
|
+
let light_position_worldspace: vec3<f32> = spotLight.position;
|
|
51
|
+
let light_direction: vec3<f32> = normalize(light_position_worldspace - position_worldspace);
|
|
52
|
+
let light_attenuation = getSpotLightAttenuation(spotLight, position_worldspace);
|
|
53
|
+
lightColor += lighting_getLightColor(
|
|
54
|
+
surfaceColor,
|
|
55
|
+
light_direction,
|
|
56
|
+
normal_worldspace,
|
|
57
|
+
spotLight.color / light_attenuation
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
for (var i: i32 = 0; i < lighting.directionalLightCount; i++) {
|
|
62
|
+
let directionalLight: DirectionalLight = lighting_getDirectionalLight(i);
|
|
63
|
+
lightColor += lighting_getLightColor(
|
|
64
|
+
surfaceColor,
|
|
65
|
+
-directionalLight.direction,
|
|
66
|
+
normal_worldspace,
|
|
67
|
+
directionalLight.color
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return lightColor;
|
|
72
|
+
}
|
|
73
|
+
`;
|
|
@@ -16,59 +16,51 @@ struct PointLight {
|
|
|
16
16
|
vec3 attenuation; // 2nd order x:Constant-y:Linear-z:Exponential
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
+
struct SpotLight {
|
|
20
|
+
vec3 color;
|
|
21
|
+
vec3 position;
|
|
22
|
+
vec3 direction;
|
|
23
|
+
vec3 attenuation;
|
|
24
|
+
vec2 coneCos;
|
|
25
|
+
};
|
|
26
|
+
|
|
19
27
|
struct DirectionalLight {
|
|
20
28
|
vec3 color;
|
|
21
29
|
vec3 direction;
|
|
22
30
|
};
|
|
23
31
|
|
|
32
|
+
struct UniformLight {
|
|
33
|
+
vec3 color;
|
|
34
|
+
vec3 position;
|
|
35
|
+
vec3 direction;
|
|
36
|
+
vec3 attenuation;
|
|
37
|
+
vec2 coneCos;
|
|
38
|
+
};
|
|
39
|
+
|
|
24
40
|
uniform lightingUniforms {
|
|
25
41
|
int enabled;
|
|
26
|
-
int lightType;
|
|
27
|
-
|
|
28
42
|
int directionalLightCount;
|
|
29
43
|
int pointLightCount;
|
|
30
|
-
|
|
44
|
+
int spotLightCount;
|
|
31
45
|
vec3 ambientColor;
|
|
32
|
-
|
|
33
|
-
vec3 lightColor0;
|
|
34
|
-
vec3 lightPosition0;
|
|
35
|
-
vec3 lightDirection0;
|
|
36
|
-
vec3 lightAttenuation0;
|
|
37
|
-
|
|
38
|
-
vec3 lightColor1;
|
|
39
|
-
vec3 lightPosition1;
|
|
40
|
-
vec3 lightDirection1;
|
|
41
|
-
vec3 lightAttenuation1;
|
|
42
|
-
|
|
43
|
-
vec3 lightColor2;
|
|
44
|
-
vec3 lightPosition2;
|
|
45
|
-
vec3 lightDirection2;
|
|
46
|
-
vec3 lightAttenuation2;
|
|
46
|
+
UniformLight lights[5];
|
|
47
47
|
} lighting;
|
|
48
48
|
|
|
49
49
|
PointLight lighting_getPointLight(int index) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return PointLight(lighting.lightColor2, lighting.lightPosition2, lighting.lightAttenuation2);
|
|
58
|
-
}
|
|
50
|
+
UniformLight light = lighting.lights[index];
|
|
51
|
+
return PointLight(light.color, light.position, light.attenuation);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
SpotLight lighting_getSpotLight(int index) {
|
|
55
|
+
UniformLight light = lighting.lights[lighting.pointLightCount + index];
|
|
56
|
+
return SpotLight(light.color, light.position, light.direction, light.attenuation, light.coneCos);
|
|
59
57
|
}
|
|
60
58
|
|
|
61
59
|
DirectionalLight lighting_getDirectionalLight(int index) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return DirectionalLight(lighting.lightColor1, lighting.lightDirection1);
|
|
67
|
-
case 2:
|
|
68
|
-
default:
|
|
69
|
-
return DirectionalLight(lighting.lightColor2, lighting.lightDirection2);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
60
|
+
UniformLight light =
|
|
61
|
+
lighting.lights[lighting.pointLightCount + lighting.spotLightCount + index];
|
|
62
|
+
return DirectionalLight(light.color, light.direction);
|
|
63
|
+
}
|
|
72
64
|
|
|
73
65
|
float getPointLightAttenuation(PointLight pointLight, float distance) {
|
|
74
66
|
return pointLight.attenuation.x
|
|
@@ -76,5 +68,19 @@ float getPointLightAttenuation(PointLight pointLight, float distance) {
|
|
|
76
68
|
+ pointLight.attenuation.z * distance * distance;
|
|
77
69
|
}
|
|
78
70
|
|
|
71
|
+
float getSpotLightAttenuation(SpotLight spotLight, vec3 positionWorldspace) {
|
|
72
|
+
vec3 light_direction = normalize(positionWorldspace - spotLight.position);
|
|
73
|
+
float coneFactor = smoothstep(
|
|
74
|
+
spotLight.coneCos.y,
|
|
75
|
+
spotLight.coneCos.x,
|
|
76
|
+
dot(normalize(spotLight.direction), light_direction)
|
|
77
|
+
);
|
|
78
|
+
float distanceAttenuation = getPointLightAttenuation(
|
|
79
|
+
PointLight(spotLight.color, spotLight.position, spotLight.attenuation),
|
|
80
|
+
distance(spotLight.position, positionWorldspace)
|
|
81
|
+
);
|
|
82
|
+
return distanceAttenuation / max(coneFactor, 0.0001);
|
|
83
|
+
}
|
|
84
|
+
|
|
79
85
|
// #endif
|
|
80
86
|
`;
|
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
export const lightingUniformsWGSL = /* wgsl */ `\
|
|
6
6
|
// #if (defined(SHADER_TYPE_FRAGMENT) && defined(LIGHTING_FRAGMENT)) || (defined(SHADER_TYPE_VERTEX) && defined(LIGHTING_VERTEX))
|
|
7
|
+
const MAX_LIGHTS: i32 = 5;
|
|
8
|
+
|
|
7
9
|
struct AmbientLight {
|
|
8
10
|
color: vec3<f32>,
|
|
9
11
|
};
|
|
@@ -14,44 +16,70 @@ struct PointLight {
|
|
|
14
16
|
attenuation: vec3<f32>, // 2nd order x:Constant-y:Linear-z:Exponential
|
|
15
17
|
};
|
|
16
18
|
|
|
19
|
+
struct SpotLight {
|
|
20
|
+
color: vec3<f32>,
|
|
21
|
+
position: vec3<f32>,
|
|
22
|
+
direction: vec3<f32>,
|
|
23
|
+
attenuation: vec3<f32>,
|
|
24
|
+
coneCos: vec2<f32>,
|
|
25
|
+
};
|
|
26
|
+
|
|
17
27
|
struct DirectionalLight {
|
|
18
28
|
color: vec3<f32>,
|
|
19
29
|
direction: vec3<f32>,
|
|
20
30
|
};
|
|
21
31
|
|
|
32
|
+
struct UniformLight {
|
|
33
|
+
color: vec3<f32>,
|
|
34
|
+
position: vec3<f32>,
|
|
35
|
+
direction: vec3<f32>,
|
|
36
|
+
attenuation: vec3<f32>,
|
|
37
|
+
coneCos: vec2<f32>,
|
|
38
|
+
};
|
|
39
|
+
|
|
22
40
|
struct lightingUniforms {
|
|
23
41
|
enabled: i32,
|
|
24
|
-
pointLightCount: i32,
|
|
25
42
|
directionalLightCount: i32,
|
|
26
|
-
|
|
43
|
+
pointLightCount: i32,
|
|
44
|
+
spotLightCount: i32,
|
|
27
45
|
ambientColor: vec3<f32>,
|
|
28
|
-
|
|
29
|
-
// TODO - support multiple lights by uncommenting arrays below
|
|
30
|
-
lightType: i32,
|
|
31
|
-
lightColor: vec3<f32>,
|
|
32
|
-
lightDirection: vec3<f32>,
|
|
33
|
-
lightPosition: vec3<f32>,
|
|
34
|
-
lightAttenuation: vec3<f32>,
|
|
35
|
-
|
|
36
|
-
// AmbientLight ambientLight;
|
|
37
|
-
// PointLight pointLight[MAX_LIGHTS];
|
|
38
|
-
// DirectionalLight directionalLight[MAX_LIGHTS];
|
|
46
|
+
lights: array<UniformLight, 5>,
|
|
39
47
|
};
|
|
40
48
|
|
|
41
|
-
|
|
42
|
-
@binding(1) @group(0) var<uniform> lighting : lightingUniforms;
|
|
49
|
+
@group(2) @binding(auto) var<uniform> lighting : lightingUniforms;
|
|
43
50
|
|
|
44
51
|
fn lighting_getPointLight(index: i32) -> PointLight {
|
|
45
|
-
|
|
52
|
+
let light = lighting.lights[index];
|
|
53
|
+
return PointLight(light.color, light.position, light.attenuation);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
fn lighting_getSpotLight(index: i32) -> SpotLight {
|
|
57
|
+
let light = lighting.lights[lighting.pointLightCount + index];
|
|
58
|
+
return SpotLight(light.color, light.position, light.direction, light.attenuation, light.coneCos);
|
|
46
59
|
}
|
|
47
60
|
|
|
48
61
|
fn lighting_getDirectionalLight(index: i32) -> DirectionalLight {
|
|
49
|
-
|
|
50
|
-
|
|
62
|
+
let light = lighting.lights[lighting.pointLightCount + lighting.spotLightCount + index];
|
|
63
|
+
return DirectionalLight(light.color, light.direction);
|
|
64
|
+
}
|
|
51
65
|
|
|
52
66
|
fn getPointLightAttenuation(pointLight: PointLight, distance: f32) -> f32 {
|
|
53
67
|
return pointLight.attenuation.x
|
|
54
68
|
+ pointLight.attenuation.y * distance
|
|
55
69
|
+ pointLight.attenuation.z * distance * distance;
|
|
56
70
|
}
|
|
71
|
+
|
|
72
|
+
fn getSpotLightAttenuation(spotLight: SpotLight, positionWorldspace: vec3<f32>) -> f32 {
|
|
73
|
+
let lightDirection = normalize(positionWorldspace - spotLight.position);
|
|
74
|
+
let coneFactor = smoothstep(
|
|
75
|
+
spotLight.coneCos.y,
|
|
76
|
+
spotLight.coneCos.x,
|
|
77
|
+
dot(normalize(spotLight.direction), lightDirection)
|
|
78
|
+
);
|
|
79
|
+
let distanceAttenuation = getPointLightAttenuation(
|
|
80
|
+
PointLight(spotLight.color, spotLight.position, spotLight.attenuation),
|
|
81
|
+
distance(spotLight.position, positionWorldspace)
|
|
82
|
+
);
|
|
83
|
+
return distanceAttenuation / max(coneFactor, 0.0001);
|
|
84
|
+
}
|
|
57
85
|
`;
|