@luma.gl/shaders 10.0.0-alpha.7 → 10.0.0-alpha.9
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 +233 -249
- package/dist/dist.min.js +124 -124
- package/dist/glsl.cjs.map +2 -2
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/shader-assembler-base.cjs +3 -4
- package/dist/lib/shader-assembler-base.d.ts +4 -5
- package/dist/lib/shader-assembler-base.d.ts.map +1 -1
- package/dist/lib/shader-assembler-base.js +3 -4
- package/dist/lib/shader-assembler-base.js.map +1 -1
- package/dist/lib/shader-assembly/assemble-glsl-shaders.cjs +6 -17
- package/dist/lib/shader-assembly/assemble-glsl-shaders.d.ts +5 -4
- package/dist/lib/shader-assembly/assemble-glsl-shaders.d.ts.map +1 -1
- package/dist/lib/shader-assembly/assemble-glsl-shaders.js +14 -19
- package/dist/lib/shader-assembly/assemble-glsl-shaders.js.map +1 -1
- package/dist/lib/shader-assembly/assemble-wgsl-shaders.cjs +6 -25
- package/dist/lib/shader-assembly/assemble-wgsl-shaders.d.ts +5 -6
- package/dist/lib/shader-assembly/assemble-wgsl-shaders.d.ts.map +1 -1
- package/dist/lib/shader-assembly/assemble-wgsl-shaders.js +14 -27
- package/dist/lib/shader-assembly/assemble-wgsl-shaders.js.map +1 -1
- package/dist/lib/shader-assembly/shader-assembly-shared.d.ts +2 -2
- package/dist/lib/shader-assembly/shader-assembly-shared.d.ts.map +1 -1
- package/dist/lib/shader-assembly/shader-assembly-shared.js.map +1 -1
- package/dist/lib/shader-assembly/shader-assembly-types.d.ts +11 -7
- package/dist/lib/shader-assembly/shader-assembly-types.d.ts.map +1 -1
- package/dist/lib/shader-assembly/shader-hooks.cjs +26 -29
- package/dist/lib/shader-assembly/shader-hooks.d.ts +34 -32
- package/dist/lib/shader-assembly/shader-hooks.d.ts.map +1 -1
- package/dist/lib/shader-assembly/shader-hooks.js +29 -33
- package/dist/lib/shader-assembly/shader-hooks.js.map +1 -1
- package/dist/lib/shader-assembly/shader-injections.cjs +26 -2
- package/dist/lib/shader-assembly/shader-injections.d.ts +20 -7
- package/dist/lib/shader-assembly/shader-injections.d.ts.map +1 -1
- package/dist/lib/shader-assembly/shader-injections.js +24 -0
- package/dist/lib/shader-assembly/shader-injections.js.map +1 -1
- package/dist/lib/shader-module/shader-module.cjs +3 -9
- package/dist/lib/shader-module/shader-module.d.ts +4 -8
- package/dist/lib/shader-module/shader-module.d.ts.map +1 -1
- package/dist/lib/shader-module/shader-module.js +3 -6
- package/dist/lib/shader-module/shader-module.js.map +1 -1
- package/dist/lib/shader-plugin.cjs +38 -17
- package/dist/lib/shader-plugin.d.ts +9 -17
- package/dist/lib/shader-plugin.d.ts.map +1 -1
- package/dist/lib/shader-plugin.js +43 -16
- package/dist/lib/shader-plugin.js.map +1 -1
- package/dist/modules/engine/clip/clip.cjs +4 -2
- package/dist/modules/engine/clip/clip.d.ts.map +1 -1
- package/dist/modules/engine/clip/clip.js +4 -2
- package/dist/modules/engine/clip/clip.js.map +1 -1
- package/dist/modules/engine/filter/filter.cjs +2 -1
- package/dist/modules/engine/filter/filter.d.ts.map +1 -1
- package/dist/modules/engine/filter/filter.js +2 -1
- package/dist/modules/engine/filter/filter.js.map +1 -1
- package/dist/modules/lighting/lights/lighting.d.ts +1 -1
- package/dist/modules/lighting/lights/lighting.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material-glsl.cjs +2 -2
- 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 +2 -2
- package/dist/modules/lighting/pbr-material/pbr-material-wgsl.cjs +2 -2
- package/dist/modules/lighting/pbr-material/pbr-material-wgsl.d.ts +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material-wgsl.d.ts.map +1 -1
- package/dist/modules/lighting/pbr-material/pbr-material-wgsl.js +2 -2
- package/dist/modules/lighting/pbr-material/pbr-material.d.ts +2 -2
- package/dist/types/texture-formats.d.ts +1 -1
- package/dist/types/texture-formats.d.ts.map +1 -1
- package/dist/wgsl.cjs.map +2 -2
- package/package.json +3 -3
- package/src/index.ts +5 -4
- package/src/lib/shader-assembler-base.ts +5 -6
- package/src/lib/shader-assembly/assemble-glsl-shaders.ts +27 -26
- package/src/lib/shader-assembly/assemble-wgsl-shaders.ts +28 -43
- package/src/lib/shader-assembly/shader-assembly-shared.ts +5 -5
- package/src/lib/shader-assembly/shader-assembly-types.ts +11 -7
- package/src/lib/shader-assembly/shader-hooks.ts +65 -68
- package/src/lib/shader-assembly/shader-injections.ts +52 -8
- package/src/lib/shader-module/shader-module.ts +7 -14
- package/src/lib/shader-plugin.ts +59 -48
- package/src/modules/engine/clip/clip.ts +4 -2
- package/src/modules/engine/filter/filter.ts +2 -1
- package/src/modules/lighting/lights/lighting.ts +1 -1
- package/src/modules/lighting/pbr-material/pbr-material-glsl.ts +2 -2
- package/src/modules/lighting/pbr-material/pbr-material-wgsl.ts +2 -2
- package/src/types/texture-formats.ts +2 -0
package/src/lib/shader-plugin.ts
CHANGED
|
@@ -2,33 +2,15 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
|
-
import type {
|
|
5
|
+
import type {ShaderHook} from './shader-assembly/shader-hooks';
|
|
6
|
+
import {
|
|
7
|
+
resolveShaderInjections,
|
|
8
|
+
type ShaderInjection,
|
|
9
|
+
type ResolvedShaderInjection
|
|
10
|
+
} from './shader-assembly/shader-injections';
|
|
6
11
|
import type {ShaderModule} from './shader-module/shader-module';
|
|
7
12
|
import {shaderTypeDecoder, type AttributeShaderType} from '../types';
|
|
8
13
|
|
|
9
|
-
/** Named shader anchor or hook target accepted by ShaderPlugin injections. */
|
|
10
|
-
export type ShaderPluginInjectionTarget =
|
|
11
|
-
| 'vs:#decl'
|
|
12
|
-
| 'vs:#main-start'
|
|
13
|
-
| 'vs:#main-end'
|
|
14
|
-
| 'fs:#decl'
|
|
15
|
-
| 'fs:#main-start'
|
|
16
|
-
| 'fs:#main-end'
|
|
17
|
-
| `vs:${string}`
|
|
18
|
-
| `fs:${string}`;
|
|
19
|
-
|
|
20
|
-
/** Named shader source injection contributed by a ShaderPlugin. */
|
|
21
|
-
export type ShaderPluginInjection = {
|
|
22
|
-
/** Named shader anchor or hook that receives this source. */
|
|
23
|
-
target: ShaderPluginInjectionTarget;
|
|
24
|
-
/** GLSL source for this target. Omit to skip this injection when assembling GLSL. */
|
|
25
|
-
glsl?: string;
|
|
26
|
-
/** WGSL source for this target. Omit to skip this injection when assembling WGSL. */
|
|
27
|
-
wgsl?: string;
|
|
28
|
-
/** Relative injection order within the target. */
|
|
29
|
-
order?: number;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
14
|
/** Portable interpolation modes for ShaderPlugin inter-stage variables. */
|
|
33
15
|
export type ShaderPluginInterStageVariableInterpolation = 'smooth' | 'flat';
|
|
34
16
|
|
|
@@ -54,8 +36,10 @@ export type ShaderPlugin = {
|
|
|
54
36
|
module?: ShaderModule<any, any, any>;
|
|
55
37
|
/** Boolean or numeric preprocessor defines added to shader assembly. */
|
|
56
38
|
defines?: Record<string, boolean | number>;
|
|
57
|
-
/** Named
|
|
58
|
-
injections?:
|
|
39
|
+
/** Named injections as explicit-stage objects or optionally language-qualified string keys. */
|
|
40
|
+
injections?: ShaderInjection[] | Record<string, string>;
|
|
41
|
+
/** Callable extension points with a shared name and language-specific source. */
|
|
42
|
+
hooks?: ShaderHook[];
|
|
59
43
|
/** Shader-facing vertex inputs added by this plugin. Buffer ownership remains with the caller. */
|
|
60
44
|
vertexInputs?: Record<string, AttributeShaderType>;
|
|
61
45
|
/** Values transported from the selected vertex entry point to the fragment entry point. */
|
|
@@ -66,19 +50,18 @@ export type ShaderPlugin = {
|
|
|
66
50
|
export type ResolvedShaderPlugins = {
|
|
67
51
|
/** Resolved shader modules in plugin declaration order. */
|
|
68
52
|
modules: ShaderModule[];
|
|
53
|
+
/** Language-selected hook declarations. */
|
|
54
|
+
hooks: ShaderHook[];
|
|
69
55
|
/** Resolved boolean or numeric preprocessor defines. */
|
|
70
56
|
defines: Record<string, boolean | number>;
|
|
71
57
|
/** Resolved named code injections grouped by target. */
|
|
72
|
-
injections: Record<string,
|
|
58
|
+
injections: Record<string, ResolvedShaderInjection[]>;
|
|
73
59
|
/** Resolved shader-facing vertex inputs in plugin declaration order. */
|
|
74
60
|
vertexInputs: Record<string, AttributeShaderType>;
|
|
75
61
|
/** Resolved inter-stage variables in plugin declaration order. */
|
|
76
62
|
interStageVariables: Record<string, ResolvedShaderPluginInterStageVariable>;
|
|
77
63
|
};
|
|
78
64
|
|
|
79
|
-
const SHADER_PLUGIN_INJECTION_TARGET_REGEX =
|
|
80
|
-
/^(vs|fs):(?:#(?:decl|main-start|main-end)|[A-Za-z_][\w-]*)$/;
|
|
81
|
-
|
|
82
65
|
/** Resolve plugin interfaces and select injection source for one shader language. */
|
|
83
66
|
export function resolveShaderPlugins(
|
|
84
67
|
plugins: readonly ShaderPlugin[] = [],
|
|
@@ -86,6 +69,7 @@ export function resolveShaderPlugins(
|
|
|
86
69
|
): ResolvedShaderPlugins {
|
|
87
70
|
const resolved: ResolvedShaderPlugins = {
|
|
88
71
|
modules: [],
|
|
72
|
+
hooks: [],
|
|
89
73
|
defines: {},
|
|
90
74
|
injections: {},
|
|
91
75
|
vertexInputs: {},
|
|
@@ -177,19 +161,49 @@ function appendShaderPlugin(
|
|
|
177
161
|
resolved.interStageVariables[name] = normalizedVarying;
|
|
178
162
|
}
|
|
179
163
|
|
|
180
|
-
for (const
|
|
181
|
-
const
|
|
182
|
-
if (
|
|
183
|
-
|
|
184
|
-
if (
|
|
185
|
-
|
|
164
|
+
for (const hook of plugin.hooks || []) {
|
|
165
|
+
const implementation = hook[shaderLanguage];
|
|
166
|
+
if (!implementation) continue;
|
|
167
|
+
const target = `${hook.stage === 'vertex' ? 'vs' : 'fs'}:${hook.name}`;
|
|
168
|
+
if (!/^(vs|fs):[A-Za-z_][A-Za-z0-9_]*$/.test(target)) {
|
|
169
|
+
throw new Error(`Invalid ShaderPlugin hook ${target}`);
|
|
170
|
+
}
|
|
171
|
+
const existing = resolved.hooks.find(
|
|
172
|
+
value => value.stage === hook.stage && value.name === hook.name
|
|
173
|
+
);
|
|
174
|
+
const previous = existing?.[shaderLanguage];
|
|
175
|
+
if (
|
|
176
|
+
previous &&
|
|
177
|
+
(previous.parameters !== implementation.parameters ||
|
|
178
|
+
(previous.returnType || 'void') !== (implementation.returnType || 'void') ||
|
|
179
|
+
previous.header !== implementation.header ||
|
|
180
|
+
previous.footer !== implementation.footer)
|
|
181
|
+
) {
|
|
182
|
+
throw new Error(`Conflicting ShaderPlugin hook ${target}`);
|
|
186
183
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
})
|
|
184
|
+
if (!existing)
|
|
185
|
+
resolved.hooks.push({name: hook.name, stage: hook.stage, [shaderLanguage]: implementation});
|
|
186
|
+
}
|
|
187
|
+
const pluginInjections = Array.isArray(plugin.injections)
|
|
188
|
+
? plugin.injections
|
|
189
|
+
: Object.entries(plugin.injections || {}).flatMap(([key, source]): ShaderInjection[] => {
|
|
190
|
+
const target = selectShaderLanguage(key, shaderLanguage);
|
|
191
|
+
if (target === undefined) return [];
|
|
192
|
+
const [stage, ...name] = target.split(':');
|
|
193
|
+
if (stage !== 'vs' && stage !== 'fs')
|
|
194
|
+
throw new Error(`Invalid ShaderPlugin injection ${key}`);
|
|
195
|
+
return [
|
|
196
|
+
{
|
|
197
|
+
stage: stage === 'vs' ? ('vertex' as const) : ('fragment' as const),
|
|
198
|
+
target: name.join(':'),
|
|
199
|
+
[shaderLanguage]: source
|
|
200
|
+
}
|
|
201
|
+
];
|
|
202
|
+
});
|
|
203
|
+
const selectedInjections = resolveShaderInjections(pluginInjections, shaderLanguage, plugin.name);
|
|
204
|
+
for (const [target, injections] of Object.entries(selectedInjections)) {
|
|
205
|
+
resolved.injections[target] ||= [];
|
|
206
|
+
resolved.injections[target].push(...injections);
|
|
193
207
|
}
|
|
194
208
|
}
|
|
195
209
|
|
|
@@ -212,10 +226,7 @@ function normalizeShaderPluginInterStageVariable(
|
|
|
212
226
|
return {type: varying.type, interpolation};
|
|
213
227
|
}
|
|
214
228
|
|
|
215
|
-
function
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
`ShaderPlugin injection target "${target}" must be a named shader anchor or hook`
|
|
219
|
-
);
|
|
220
|
-
}
|
|
229
|
+
function selectShaderLanguage(value: string, language: 'glsl' | 'wgsl'): string | undefined {
|
|
230
|
+
const match = /^(glsl|wgsl):([\s\S]+)$/.exec(value);
|
|
231
|
+
return match ? (match[1] === language ? match[2] : undefined) : value;
|
|
221
232
|
}
|
|
@@ -106,7 +106,8 @@ export const clipShaderPlugin: ShaderPlugin = {
|
|
|
106
106
|
},
|
|
107
107
|
injections: [
|
|
108
108
|
{
|
|
109
|
-
|
|
109
|
+
stage: 'vertex',
|
|
110
|
+
target: 'CLIP_POSITION',
|
|
110
111
|
glsl: `\
|
|
111
112
|
clipCoordinates = geometryCoordinates;
|
|
112
113
|
if (clipState.enabled != 0 && clipState.mode == ${CLIP_MODE_INSTANCE} &&
|
|
@@ -121,7 +122,8 @@ if (clipUniforms.enabled != 0 && clipUniforms.mode == ${CLIP_MODE_INSTANCE} &&
|
|
|
121
122
|
}`
|
|
122
123
|
},
|
|
123
124
|
{
|
|
124
|
-
|
|
125
|
+
stage: 'fragment',
|
|
126
|
+
target: 'CLIP_COLOR',
|
|
125
127
|
glsl: `\
|
|
126
128
|
if (clipState.enabled != 0 && clipState.mode == ${CLIP_MODE_GEOMETRY} &&
|
|
127
129
|
!clip_isInBounds(clipCoordinates)) {
|
|
@@ -49,7 +49,7 @@ export type PointLight = {
|
|
|
49
49
|
export type DirectionalLight = {
|
|
50
50
|
/** Discriminator used to identify directional lights in `lights: Light[]`. */
|
|
51
51
|
type: 'directional';
|
|
52
|
-
/** World-space light
|
|
52
|
+
/** World-space direction in which light travels. */
|
|
53
53
|
direction: Readonly<NumberArray3>;
|
|
54
54
|
/** RGB light color in the existing `0..255` convention used by luma.gl materials. */
|
|
55
55
|
color?: Readonly<NumberArray3>;
|
|
@@ -1249,7 +1249,7 @@ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
|
|
|
1249
1249
|
|
|
1250
1250
|
for(int i = 0; i < lighting.directionalLightCount; i++) {
|
|
1251
1251
|
if (i < lighting.directionalLightCount) {
|
|
1252
|
-
PBRInfo_setDirectionalLight(pbrInfo, lighting_getDirectionalLight(i).direction);
|
|
1252
|
+
PBRInfo_setDirectionalLight(pbrInfo, -lighting_getDirectionalLight(i).direction);
|
|
1253
1253
|
color += calculateFinalColor(pbrInfo, lighting_getDirectionalLight(i).color);
|
|
1254
1254
|
}
|
|
1255
1255
|
}
|
|
@@ -1537,7 +1537,7 @@ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
|
|
|
1537
1537
|
// Apply directional light
|
|
1538
1538
|
for(int i = 0; i < lighting.directionalLightCount; i++) {
|
|
1539
1539
|
if (i < lighting.directionalLightCount) {
|
|
1540
|
-
PBRInfo_setDirectionalLight(pbrInfo, lighting_getDirectionalLight(i).direction);
|
|
1540
|
+
PBRInfo_setDirectionalLight(pbrInfo, -lighting_getDirectionalLight(i).direction);
|
|
1541
1541
|
color += calculateMaterialLightColor(
|
|
1542
1542
|
pbrInfo,
|
|
1543
1543
|
lighting_getDirectionalLight(i).color,
|
|
@@ -1468,7 +1468,7 @@ fn pbr_filterColorWithSpotShadows(vertexColor: vec4<f32>, spotVisibility: vec4f)
|
|
|
1468
1468
|
|
|
1469
1469
|
for (var i = 0; i < lighting.directionalLightCount; i++) {
|
|
1470
1470
|
if (i < lighting.directionalLightCount) {
|
|
1471
|
-
PBRInfo_setDirectionalLight(&pbrInfo, lighting_getDirectionalLight(i).direction);
|
|
1471
|
+
PBRInfo_setDirectionalLight(&pbrInfo, -lighting_getDirectionalLight(i).direction);
|
|
1472
1472
|
color += calculateFinalColor(pbrInfo, lighting_getDirectionalLight(i).color);
|
|
1473
1473
|
}
|
|
1474
1474
|
}
|
|
@@ -1828,7 +1828,7 @@ fn pbr_filterColorWithSpotShadows(vertexColor: vec4<f32>, spotVisibility: vec4f)
|
|
|
1828
1828
|
// Apply directional light
|
|
1829
1829
|
for (var i = 0; i < lighting.directionalLightCount; i++) {
|
|
1830
1830
|
if (i < lighting.directionalLightCount) {
|
|
1831
|
-
PBRInfo_setDirectionalLight(&pbrInfo, lighting_getDirectionalLight(i).direction);
|
|
1831
|
+
PBRInfo_setDirectionalLight(&pbrInfo, -lighting_getDirectionalLight(i).direction);
|
|
1832
1832
|
color += calculateMaterialLightColor(
|
|
1833
1833
|
pbrInfo,
|
|
1834
1834
|
lighting_getDirectionalLight(i).color,
|
|
@@ -85,6 +85,8 @@ export type TextureFormatCompressed =
|
|
|
85
85
|
| 'pvrtc-rgba4unorm-webgl'
|
|
86
86
|
| 'pvrtc-rgb2unorm-webgl'
|
|
87
87
|
| 'pvrtc-rgba2unorm-webgl'
|
|
88
|
+
| 'etc1-rgb-unorm-webgl'
|
|
89
|
+
// Legacy misspelling retained for compatibility.
|
|
88
90
|
| 'etc1-rbg-unorm-webgl'
|
|
89
91
|
| 'atc-rgb-unorm-webgl'
|
|
90
92
|
| 'atc-rgba-unorm-webgl'
|