@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
|
@@ -16,77 +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;
|
|
47
|
-
|
|
48
|
-
vec3 lightColor3;
|
|
49
|
-
vec3 lightPosition3;
|
|
50
|
-
vec3 lightDirection3;
|
|
51
|
-
vec3 lightAttenuation3;
|
|
52
|
-
|
|
53
|
-
vec3 lightColor4;
|
|
54
|
-
vec3 lightPosition4;
|
|
55
|
-
vec3 lightDirection4;
|
|
56
|
-
vec3 lightAttenuation4;
|
|
46
|
+
UniformLight lights[5];
|
|
57
47
|
} lighting;
|
|
58
48
|
|
|
59
49
|
PointLight lighting_getPointLight(int index) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
case 3:
|
|
68
|
-
return PointLight(lighting.lightColor3, lighting.lightPosition3, lighting.lightAttenuation3);
|
|
69
|
-
case 4:
|
|
70
|
-
default:
|
|
71
|
-
return PointLight(lighting.lightColor4, lighting.lightPosition4, lighting.lightAttenuation4);
|
|
72
|
-
}
|
|
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);
|
|
73
57
|
}
|
|
74
58
|
|
|
75
59
|
DirectionalLight lighting_getDirectionalLight(int index) {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
return DirectionalLight(lighting.lightColor1, lighting.lightDirection1);
|
|
81
|
-
case 2:
|
|
82
|
-
return DirectionalLight(lighting.lightColor2, lighting.lightDirection2);
|
|
83
|
-
case 3:
|
|
84
|
-
return DirectionalLight(lighting.lightColor3, lighting.lightDirection3);
|
|
85
|
-
case 4:
|
|
86
|
-
default:
|
|
87
|
-
return DirectionalLight(lighting.lightColor4, lighting.lightDirection4);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
60
|
+
UniformLight light =
|
|
61
|
+
lighting.lights[lighting.pointLightCount + lighting.spotLightCount + index];
|
|
62
|
+
return DirectionalLight(light.color, light.direction);
|
|
63
|
+
}
|
|
90
64
|
|
|
91
65
|
float getPointLightAttenuation(PointLight pointLight, float distance) {
|
|
92
66
|
return pointLight.attenuation.x
|
|
@@ -94,5 +68,19 @@ float getPointLightAttenuation(PointLight pointLight, float distance) {
|
|
|
94
68
|
+ pointLight.attenuation.z * distance * distance;
|
|
95
69
|
}
|
|
96
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
|
+
|
|
97
85
|
// #endif
|
|
98
86
|
`;
|
|
@@ -16,92 +16,70 @@ struct PointLight {
|
|
|
16
16
|
attenuation: vec3<f32>, // 2nd order x:Constant-y:Linear-z:Exponential
|
|
17
17
|
};
|
|
18
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
|
+
|
|
19
27
|
struct DirectionalLight {
|
|
20
28
|
color: vec3<f32>,
|
|
21
29
|
direction: vec3<f32>,
|
|
22
30
|
};
|
|
23
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
|
+
|
|
24
40
|
struct lightingUniforms {
|
|
25
41
|
enabled: i32,
|
|
26
|
-
lightType: i32,
|
|
27
|
-
|
|
28
42
|
directionalLightCount: i32,
|
|
29
43
|
pointLightCount: i32,
|
|
30
|
-
|
|
44
|
+
spotLightCount: i32,
|
|
31
45
|
ambientColor: vec3<f32>,
|
|
32
|
-
|
|
33
|
-
lightColor0: vec3<f32>,
|
|
34
|
-
lightPosition0: vec3<f32>,
|
|
35
|
-
lightDirection0: vec3<f32>,
|
|
36
|
-
lightAttenuation0: vec3<f32>,
|
|
37
|
-
|
|
38
|
-
lightColor1: vec3<f32>,
|
|
39
|
-
lightPosition1: vec3<f32>,
|
|
40
|
-
lightDirection1: vec3<f32>,
|
|
41
|
-
lightAttenuation1: vec3<f32>,
|
|
42
|
-
|
|
43
|
-
lightColor2: vec3<f32>,
|
|
44
|
-
lightPosition2: vec3<f32>,
|
|
45
|
-
lightDirection2: vec3<f32>,
|
|
46
|
-
lightAttenuation2: vec3<f32>,
|
|
47
|
-
|
|
48
|
-
lightColor3: vec3<f32>,
|
|
49
|
-
lightPosition3: vec3<f32>,
|
|
50
|
-
lightDirection3: vec3<f32>,
|
|
51
|
-
lightAttenuation3: vec3<f32>,
|
|
52
|
-
|
|
53
|
-
lightColor4: vec3<f32>,
|
|
54
|
-
lightPosition4: vec3<f32>,
|
|
55
|
-
lightDirection4: vec3<f32>,
|
|
56
|
-
lightAttenuation4: vec3<f32>,
|
|
46
|
+
lights: array<UniformLight, 5>,
|
|
57
47
|
};
|
|
58
48
|
|
|
59
|
-
|
|
60
|
-
@binding(1) @group(0) var<uniform> lighting : lightingUniforms;
|
|
49
|
+
@group(2) @binding(auto) var<uniform> lighting : lightingUniforms;
|
|
61
50
|
|
|
62
51
|
fn lighting_getPointLight(index: i32) -> PointLight {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
case 2: {
|
|
71
|
-
return PointLight(lighting.lightColor2, lighting.lightPosition2, lighting.lightAttenuation2);
|
|
72
|
-
}
|
|
73
|
-
case 3: {
|
|
74
|
-
return PointLight(lighting.lightColor3, lighting.lightPosition3, lighting.lightAttenuation3);
|
|
75
|
-
}
|
|
76
|
-
case 4, default: {
|
|
77
|
-
return PointLight(lighting.lightColor4, lighting.lightPosition4, lighting.lightAttenuation4);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
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);
|
|
80
59
|
}
|
|
81
60
|
|
|
82
61
|
fn lighting_getDirectionalLight(index: i32) -> DirectionalLight {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
case 1: {
|
|
88
|
-
return DirectionalLight(lighting.lightColor1, lighting.lightDirection1);
|
|
89
|
-
}
|
|
90
|
-
case 2: {
|
|
91
|
-
return DirectionalLight(lighting.lightColor2, lighting.lightDirection2);
|
|
92
|
-
}
|
|
93
|
-
case 3: {
|
|
94
|
-
return DirectionalLight(lighting.lightColor3, lighting.lightDirection3);
|
|
95
|
-
}
|
|
96
|
-
case 4, default: {
|
|
97
|
-
return DirectionalLight(lighting.lightColor4, lighting.lightDirection4);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
62
|
+
let light = lighting.lights[lighting.pointLightCount + lighting.spotLightCount + index];
|
|
63
|
+
return DirectionalLight(light.color, light.direction);
|
|
64
|
+
}
|
|
101
65
|
|
|
102
66
|
fn getPointLightAttenuation(pointLight: PointLight, distance: f32) -> f32 {
|
|
103
67
|
return pointLight.attenuation.x
|
|
104
68
|
+ pointLight.attenuation.y * distance
|
|
105
69
|
+ pointLight.attenuation.z * distance * distance;
|
|
106
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
|
+
}
|
|
107
85
|
`;
|