@luma.gl/shaders 10.0.0-alpha.7 → 10.0.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 +80 -17
- package/dist/dist.min.js +110 -110
- package/dist/glsl.cjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/shader-assembly/assemble-glsl-shaders.cjs +1 -1
- package/dist/lib/shader-assembly/assemble-glsl-shaders.d.ts +1 -0
- package/dist/lib/shader-assembly/assemble-glsl-shaders.d.ts.map +1 -1
- package/dist/lib/shader-assembly/assemble-glsl-shaders.js +1 -1
- package/dist/lib/shader-assembly/assemble-glsl-shaders.js.map +1 -1
- package/dist/lib/shader-assembly/assemble-wgsl-shaders.cjs +1 -1
- package/dist/lib/shader-assembly/assemble-wgsl-shaders.js +1 -1
- package/dist/lib/shader-assembly/assemble-wgsl-shaders.js.map +1 -1
- package/dist/lib/shader-assembly/shader-assembly-types.d.ts +4 -0
- package/dist/lib/shader-assembly/shader-assembly-types.d.ts.map +1 -1
- package/dist/lib/shader-assembly/shader-hooks.cjs +19 -3
- package/dist/lib/shader-assembly/shader-hooks.d.ts +1 -1
- package/dist/lib/shader-assembly/shader-hooks.d.ts.map +1 -1
- package/dist/lib/shader-assembly/shader-hooks.js +23 -3
- package/dist/lib/shader-assembly/shader-hooks.js.map +1 -1
- package/dist/lib/shader-plugin.cjs +51 -5
- package/dist/lib/shader-plugin.d.ts +22 -5
- package/dist/lib/shader-plugin.d.ts.map +1 -1
- package/dist/lib/shader-plugin.js +55 -5
- 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 +1 -1
- package/package.json +3 -3
- package/src/index.ts +2 -0
- package/src/lib/shader-assembly/assemble-glsl-shaders.ts +2 -1
- package/src/lib/shader-assembly/assemble-wgsl-shaders.ts +1 -1
- package/src/lib/shader-assembly/shader-assembly-types.ts +4 -0
- package/src/lib/shader-assembly/shader-hooks.ts +27 -3
- package/src/lib/shader-plugin.ts +80 -10
- 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/dist/dist.dev.js
CHANGED
|
@@ -1386,6 +1386,7 @@ ${fragmentString}${source7.slice(insertionIndex)}`;
|
|
|
1386
1386
|
function resolveShaderPlugins(plugins = [], shaderLanguage) {
|
|
1387
1387
|
const resolved = {
|
|
1388
1388
|
modules: [],
|
|
1389
|
+
hooks: [],
|
|
1389
1390
|
defines: {},
|
|
1390
1391
|
injections: {},
|
|
1391
1392
|
vertexInputs: {},
|
|
@@ -1450,14 +1451,45 @@ ${fragmentString}${source7.slice(insertionIndex)}`;
|
|
|
1450
1451
|
}
|
|
1451
1452
|
resolved.interStageVariables[name] = normalizedVarying;
|
|
1452
1453
|
}
|
|
1453
|
-
for (const
|
|
1454
|
+
for (const hook of plugin.hooks || []) {
|
|
1455
|
+
const declarationSource = typeof hook === "string" ? selectShaderLanguage(hook, shaderLanguage) : void 0;
|
|
1456
|
+
if (typeof hook === "string" && declarationSource === void 0) continue;
|
|
1457
|
+
const signature = typeof hook === "string" ? declarationSource.slice(declarationSource.indexOf("(")) : hook[shaderLanguage];
|
|
1458
|
+
if (signature === void 0) continue;
|
|
1459
|
+
const target = typeof hook === "string" ? declarationSource.split("(")[0] : getShaderPluginTarget(hook);
|
|
1460
|
+
if (!/^(vs|fs):[A-Za-z_][A-Za-z0-9_]*$/.test(target) || !/^\([^]*\)$/.test(signature.trim())) {
|
|
1461
|
+
throw new Error(`Invalid ShaderPlugin hook ${target}`);
|
|
1462
|
+
}
|
|
1463
|
+
const declaration = { hook: `${target}${signature.trim()}` };
|
|
1464
|
+
const existing = resolved.hooks.find((value) => value.hook.split("(")[0] === target);
|
|
1465
|
+
if (existing && existing.hook !== declaration.hook) {
|
|
1466
|
+
throw new Error(`Conflicting ShaderPlugin hook ${target}`);
|
|
1467
|
+
}
|
|
1468
|
+
if (!existing) resolved.hooks.push(declaration);
|
|
1469
|
+
}
|
|
1470
|
+
const pluginInjections = Array.isArray(plugin.injections) ? plugin.injections : Object.entries(plugin.injections || {}).flatMap(([key, source7]) => {
|
|
1471
|
+
const target = selectShaderLanguage(key, shaderLanguage);
|
|
1472
|
+
if (target === void 0) return [];
|
|
1473
|
+
const [stage, ...name] = target.split(":");
|
|
1474
|
+
if (stage !== "vs" && stage !== "fs")
|
|
1475
|
+
throw new Error(`Invalid ShaderPlugin injection ${key}`);
|
|
1476
|
+
return [
|
|
1477
|
+
{
|
|
1478
|
+
stage: stage === "vs" ? "vertex" : "fragment",
|
|
1479
|
+
target: name.join(":"),
|
|
1480
|
+
[shaderLanguage]: source7
|
|
1481
|
+
}
|
|
1482
|
+
];
|
|
1483
|
+
});
|
|
1484
|
+
for (const injection of pluginInjections) {
|
|
1454
1485
|
const source7 = injection[shaderLanguage];
|
|
1455
1486
|
if (source7 === void 0) continue;
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1487
|
+
const target = getShaderPluginTarget(injection);
|
|
1488
|
+
assertNamedShaderPluginInjectionTarget(target);
|
|
1489
|
+
if (!resolved.injections[target]) {
|
|
1490
|
+
resolved.injections[target] = [];
|
|
1459
1491
|
}
|
|
1460
|
-
const injections = resolved.injections[
|
|
1492
|
+
const injections = resolved.injections[target];
|
|
1461
1493
|
injections.push({
|
|
1462
1494
|
pluginName: plugin.name,
|
|
1463
1495
|
injection: source7,
|
|
@@ -1486,6 +1518,16 @@ ${fragmentString}${source7.slice(insertionIndex)}`;
|
|
|
1486
1518
|
);
|
|
1487
1519
|
}
|
|
1488
1520
|
}
|
|
1521
|
+
function getShaderPluginTarget(value) {
|
|
1522
|
+
if (value.stage !== "vertex" && value.stage !== "fragment" || value.target.includes(":")) {
|
|
1523
|
+
throw new Error("ShaderPlugin object targets require an explicit stage and unqualified target");
|
|
1524
|
+
}
|
|
1525
|
+
return `${value.stage === "vertex" ? "vs" : "fs"}:${value.target}`;
|
|
1526
|
+
}
|
|
1527
|
+
function selectShaderLanguage(value, language) {
|
|
1528
|
+
const match = /^(glsl|wgsl):([\s\S]+)$/.exec(value);
|
|
1529
|
+
return match ? match[1] === language ? match[2] : void 0 : value;
|
|
1530
|
+
}
|
|
1489
1531
|
|
|
1490
1532
|
// src/lib/shader-module/shader-module-uniform-layout.ts
|
|
1491
1533
|
var GLSL_UNIFORM_BLOCK_FIELD_REGEXP = /^(?:uniform\s+)?(?:(?:lowp|mediump|highp)\s+)?[A-Za-z0-9_]+(?:<[^>]+>)?\s+([A-Za-z0-9_]+)(?:\s*\[[^\]]+\])?\s*;/;
|
|
@@ -2712,10 +2754,28 @@ return ${outputName};
|
|
|
2712
2754
|
}
|
|
2713
2755
|
return result;
|
|
2714
2756
|
}
|
|
2715
|
-
function normalizeShaderHooks(hookFunctions) {
|
|
2757
|
+
function normalizeShaderHooks(hookFunctions, pluginHooks = [], language) {
|
|
2716
2758
|
const result = { vertex: {}, fragment: {} };
|
|
2717
2759
|
for (const hookFunction of hookFunctions) {
|
|
2718
|
-
|
|
2760
|
+
const text = typeof hookFunction === "string" ? hookFunction : hookFunction.hook;
|
|
2761
|
+
const qualified = /^(glsl|wgsl):([\s\S]+)$/.exec(text);
|
|
2762
|
+
if (qualified && qualified[1] !== language) continue;
|
|
2763
|
+
addShaderHookToRegistry(
|
|
2764
|
+
result,
|
|
2765
|
+
qualified ? typeof hookFunction === "string" ? qualified[2] : { ...hookFunction, hook: qualified[2] } : hookFunction
|
|
2766
|
+
);
|
|
2767
|
+
}
|
|
2768
|
+
for (const hook of pluginHooks) {
|
|
2769
|
+
const normalized = normalizeShaderHooks([hook]);
|
|
2770
|
+
for (const stage of ["vertex", "fragment"]) {
|
|
2771
|
+
for (const [name, declaration] of Object.entries(normalized[stage])) {
|
|
2772
|
+
const existing = result[stage][name];
|
|
2773
|
+
if (existing && existing.signature !== declaration.signature) {
|
|
2774
|
+
throw new Error(`Conflicting ShaderPlugin hook ${name}`);
|
|
2775
|
+
}
|
|
2776
|
+
result[stage][name] = existing || declaration;
|
|
2777
|
+
}
|
|
2778
|
+
}
|
|
2719
2779
|
}
|
|
2720
2780
|
return result;
|
|
2721
2781
|
}
|
|
@@ -2745,7 +2805,7 @@ return ${outputName};
|
|
|
2745
2805
|
const stageSeparatorIndex = hook.indexOf(":");
|
|
2746
2806
|
const shaderStage = hook.slice(0, stageSeparatorIndex);
|
|
2747
2807
|
const signature = hook.slice(stageSeparatorIndex + 1);
|
|
2748
|
-
const name = hook.
|
|
2808
|
+
const name = hook.split("(")[0].trim();
|
|
2749
2809
|
const normalizedHook = {
|
|
2750
2810
|
hook: name,
|
|
2751
2811
|
signature,
|
|
@@ -2812,7 +2872,7 @@ return ${outputName};
|
|
|
2812
2872
|
);
|
|
2813
2873
|
const coreSource = pluginVaryingAssembly.source;
|
|
2814
2874
|
let assembledSource = "";
|
|
2815
|
-
const hookFunctionMap = normalizeShaderHooks(hookFunctions);
|
|
2875
|
+
const hookFunctionMap = normalizeShaderHooks(hookFunctions, options.pluginHooks, "wgsl");
|
|
2816
2876
|
const hookInjections = {};
|
|
2817
2877
|
const declInjections = {};
|
|
2818
2878
|
const mainInjections = {};
|
|
@@ -3470,7 +3530,7 @@ ${getApplicationDefines(allDefines)}
|
|
|
3470
3530
|
`;
|
|
3471
3531
|
break;
|
|
3472
3532
|
}
|
|
3473
|
-
const hookFunctionMap = normalizeShaderHooks(hookFunctions);
|
|
3533
|
+
const hookFunctionMap = normalizeShaderHooks(hookFunctions, options.pluginHooks, "glsl");
|
|
3474
3534
|
const hookInjections = {};
|
|
3475
3535
|
const declInjections = {};
|
|
3476
3536
|
const mainInjections = {};
|
|
@@ -11673,7 +11733,8 @@ fn filter_isVisible(value: f32) -> bool {
|
|
|
11673
11733
|
},
|
|
11674
11734
|
injections: [
|
|
11675
11735
|
{
|
|
11676
|
-
|
|
11736
|
+
stage: "vertex",
|
|
11737
|
+
target: "FILTER_POSITION",
|
|
11677
11738
|
glsl: `if (!filter_isVisible(filterValues)) {
|
|
11678
11739
|
position = vec4(2.0, 2.0, 2.0, 1.0);
|
|
11679
11740
|
}`,
|
|
@@ -11774,7 +11835,8 @@ fn clip_isInBounds(coordinates: vec2<f32>) -> bool {
|
|
|
11774
11835
|
},
|
|
11775
11836
|
injections: [
|
|
11776
11837
|
{
|
|
11777
|
-
|
|
11838
|
+
stage: "vertex",
|
|
11839
|
+
target: "CLIP_POSITION",
|
|
11778
11840
|
glsl: `clipCoordinates = geometryCoordinates;
|
|
11779
11841
|
if (clipState.enabled != 0 && clipState.mode == ${CLIP_MODE_INSTANCE} &&
|
|
11780
11842
|
!clip_isInBounds(instanceCoordinates)) {
|
|
@@ -11787,7 +11849,8 @@ if (clipUniforms.enabled != 0 && clipUniforms.mode == ${CLIP_MODE_INSTANCE} &&
|
|
|
11787
11849
|
}`
|
|
11788
11850
|
},
|
|
11789
11851
|
{
|
|
11790
|
-
|
|
11852
|
+
stage: "fragment",
|
|
11853
|
+
target: "CLIP_COLOR",
|
|
11791
11854
|
glsl: `if (clipState.enabled != 0 && clipState.mode == ${CLIP_MODE_GEOMETRY} &&
|
|
11792
11855
|
!clip_isInBounds(clipCoordinates)) {
|
|
11793
11856
|
discard;
|
|
@@ -15589,7 +15652,7 @@ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
|
|
|
15589
15652
|
|
|
15590
15653
|
for(int i = 0; i < lighting.directionalLightCount; i++) {
|
|
15591
15654
|
if (i < lighting.directionalLightCount) {
|
|
15592
|
-
PBRInfo_setDirectionalLight(pbrInfo, lighting_getDirectionalLight(i).direction);
|
|
15655
|
+
PBRInfo_setDirectionalLight(pbrInfo, -lighting_getDirectionalLight(i).direction);
|
|
15593
15656
|
color += calculateFinalColor(pbrInfo, lighting_getDirectionalLight(i).color);
|
|
15594
15657
|
}
|
|
15595
15658
|
}
|
|
@@ -15877,7 +15940,7 @@ vec4 pbr_filterColorWithSpotShadows(vec4 vertexColor, vec4 spotVisibility)
|
|
|
15877
15940
|
// Apply directional light
|
|
15878
15941
|
for(int i = 0; i < lighting.directionalLightCount; i++) {
|
|
15879
15942
|
if (i < lighting.directionalLightCount) {
|
|
15880
|
-
PBRInfo_setDirectionalLight(pbrInfo, lighting_getDirectionalLight(i).direction);
|
|
15943
|
+
PBRInfo_setDirectionalLight(pbrInfo, -lighting_getDirectionalLight(i).direction);
|
|
15881
15944
|
color += calculateMaterialLightColor(
|
|
15882
15945
|
pbrInfo,
|
|
15883
15946
|
lighting_getDirectionalLight(i).color,
|
|
@@ -17406,7 +17469,7 @@ fn pbr_filterColorWithSpotShadows(vertexColor: vec4<f32>, spotVisibility: vec4f)
|
|
|
17406
17469
|
|
|
17407
17470
|
for (var i = 0; i < lighting.directionalLightCount; i++) {
|
|
17408
17471
|
if (i < lighting.directionalLightCount) {
|
|
17409
|
-
PBRInfo_setDirectionalLight(&pbrInfo, lighting_getDirectionalLight(i).direction);
|
|
17472
|
+
PBRInfo_setDirectionalLight(&pbrInfo, -lighting_getDirectionalLight(i).direction);
|
|
17410
17473
|
color += calculateFinalColor(pbrInfo, lighting_getDirectionalLight(i).color);
|
|
17411
17474
|
}
|
|
17412
17475
|
}
|
|
@@ -17766,7 +17829,7 @@ fn pbr_filterColorWithSpotShadows(vertexColor: vec4<f32>, spotVisibility: vec4f)
|
|
|
17766
17829
|
// Apply directional light
|
|
17767
17830
|
for (var i = 0; i < lighting.directionalLightCount; i++) {
|
|
17768
17831
|
if (i < lighting.directionalLightCount) {
|
|
17769
|
-
PBRInfo_setDirectionalLight(&pbrInfo, lighting_getDirectionalLight(i).direction);
|
|
17832
|
+
PBRInfo_setDirectionalLight(&pbrInfo, -lighting_getDirectionalLight(i).direction);
|
|
17770
17833
|
color += calculateMaterialLightColor(
|
|
17771
17834
|
pbrInfo,
|
|
17772
17835
|
lighting_getDirectionalLight(i).color,
|