@luma.gl/shaders 10.0.0-alpha.11 → 10.0.0-alpha.12
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 +147 -2
- package/dist/dist.min.js +235 -131
- package/dist/glsl.cjs.map +1 -1
- package/dist/index.cjs +6 -0
- package/dist/index.cjs.map +2 -2
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/modules/lighting/lightmap/lightmap-filter.cjs +93 -0
- package/dist/modules/lighting/lightmap/lightmap-filter.d.ts +35 -0
- package/dist/modules/lighting/lightmap/lightmap-filter.d.ts.map +1 -0
- package/dist/modules/lighting/lightmap/lightmap-filter.js +71 -0
- package/dist/modules/lighting/lightmap/lightmap-filter.js.map +1 -0
- package/dist/modules/lighting/lightmap/lightmap.cjs +89 -0
- package/dist/modules/lighting/lightmap/lightmap.d.ts +405 -0
- package/dist/modules/lighting/lightmap/lightmap.d.ts.map +1 -0
- package/dist/modules/lighting/lightmap/lightmap.js +67 -0
- package/dist/modules/lighting/lightmap/lightmap.js.map +1 -0
- package/dist/types/shader-type-decoder.cjs +12 -2
- package/dist/types/shader-type-decoder.d.ts +7 -7
- package/dist/types/shader-type-decoder.d.ts.map +1 -1
- package/dist/types/shader-type-decoder.js +13 -2
- package/dist/types/shader-type-decoder.js.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/wgsl.cjs.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +4 -0
- package/src/modules/lighting/lightmap/lightmap-filter.ts +73 -0
- package/src/modules/lighting/lightmap/lightmap.ts +76 -0
- package/src/types/shader-type-decoder.ts +22 -9
package/dist/dist.dev.js
CHANGED
|
@@ -86,6 +86,8 @@ var __exports__ = (() => {
|
|
|
86
86
|
integrateSurfaceWeather: () => integrateSurfaceWeather,
|
|
87
87
|
lambertMaterial: () => lambertMaterial,
|
|
88
88
|
lighting: () => lighting,
|
|
89
|
+
lightmapBake: () => lightmapBake,
|
|
90
|
+
lightmapFilter: () => lightmapFilter,
|
|
89
91
|
mergeShaderPluginModules: () => mergeShaderPluginModules,
|
|
90
92
|
normalizeByteColor3: () => normalizeByteColor3,
|
|
91
93
|
normalizeByteColor4: () => normalizeByteColor4,
|
|
@@ -1197,8 +1199,13 @@ ${fragmentString}${source7.slice(insertionIndex)}`;
|
|
|
1197
1199
|
}
|
|
1198
1200
|
return decoded;
|
|
1199
1201
|
}
|
|
1202
|
+
var attributeShaderTypeInfoCache = /* @__PURE__ */ new Map();
|
|
1200
1203
|
function getAttributeShaderTypeInfo(attributeType) {
|
|
1201
1204
|
const resolvedAttributeType = resolveAttributeShaderTypeAlias(attributeType);
|
|
1205
|
+
const cached = attributeShaderTypeInfoCache.get(resolvedAttributeType);
|
|
1206
|
+
if (cached) {
|
|
1207
|
+
return cached;
|
|
1208
|
+
}
|
|
1202
1209
|
const decoded = TYPE_INFO[resolvedAttributeType];
|
|
1203
1210
|
if (!decoded) {
|
|
1204
1211
|
throw new Error(`Unsupported attribute shader type: ${attributeType}`);
|
|
@@ -1207,13 +1214,15 @@ ${fragmentString}${source7.slice(insertionIndex)}`;
|
|
|
1207
1214
|
const integer = primitiveType === "i32" || primitiveType === "u32";
|
|
1208
1215
|
const signed = primitiveType !== "u32";
|
|
1209
1216
|
const byteLength = PRIMITIVE_TYPE_SIZES[primitiveType] * components;
|
|
1210
|
-
|
|
1217
|
+
const result = Object.freeze({
|
|
1211
1218
|
primitiveType,
|
|
1212
1219
|
components,
|
|
1213
1220
|
byteLength,
|
|
1214
1221
|
integer,
|
|
1215
1222
|
signed
|
|
1216
|
-
};
|
|
1223
|
+
});
|
|
1224
|
+
attributeShaderTypeInfoCache.set(resolvedAttributeType, result);
|
|
1225
|
+
return result;
|
|
1217
1226
|
}
|
|
1218
1227
|
var ShaderTypeDecoder = class {
|
|
1219
1228
|
getVariableShaderTypeInfo(format) {
|
|
@@ -1322,6 +1331,9 @@ ${fragmentString}${source7.slice(insertionIndex)}`;
|
|
|
1322
1331
|
"mat4x3<u32>": { type: "u32", components: 12 },
|
|
1323
1332
|
"mat4x4<u32>": { type: "u32", components: 16 }
|
|
1324
1333
|
};
|
|
1334
|
+
for (const info of Object.values(UNIFORM_FORMATS)) {
|
|
1335
|
+
Object.freeze(info);
|
|
1336
|
+
}
|
|
1325
1337
|
var WGSL_ATTRIBUTE_TYPE_ALIAS_MAP = {
|
|
1326
1338
|
vec2i: "vec2<i32>",
|
|
1327
1339
|
vec3i: "vec3<i32>",
|
|
@@ -21592,6 +21604,139 @@ void pbrAmbientOcclusion_setFactor(vec2 pixelPosition) {
|
|
|
21592
21604
|
}`
|
|
21593
21605
|
)
|
|
21594
21606
|
};
|
|
21607
|
+
|
|
21608
|
+
// src/modules/lighting/lightmap/lightmap.ts
|
|
21609
|
+
var lightmapBake = {
|
|
21610
|
+
name: "lightmapBake",
|
|
21611
|
+
dependencies: [pbrMaterial],
|
|
21612
|
+
bindingLayout: [{ name: "lightmapBake", group: 0 }],
|
|
21613
|
+
uniformTypes: { uvSet: "i32", uvTransform: "mat3x3<f32>", chartId: "f32" },
|
|
21614
|
+
defaultUniforms: { uvSet: 1, uvTransform: [1, 0, 0, 0, 1, 0, 0, 0, 1], chartId: 1 },
|
|
21615
|
+
getUniforms: (props) => props,
|
|
21616
|
+
source: `
|
|
21617
|
+
struct LightmapBakeUniforms {uvSet: i32, uvTransform: mat3x3f, chartId: f32};
|
|
21618
|
+
@group(0) @binding(auto) var<uniform> lightmapBake: LightmapBakeUniforms;
|
|
21619
|
+
|
|
21620
|
+
fn lightmap_getIrradiance(position: vec3f, normal: vec3f, directionalVisibility: f32, pointVisibility: vec4f, spotVisibility: vec4f) -> vec3f {
|
|
21621
|
+
if (lighting.enabled == 0) {return vec3f(0.0);}
|
|
21622
|
+
var irradiance = lighting.ambientColor;
|
|
21623
|
+
for (var index = 0; index < lighting.directionalLightCount; index++) {
|
|
21624
|
+
let light = lighting_getDirectionalLight(index);
|
|
21625
|
+
irradiance += light.color * max(dot(normal, -normalize(light.direction)), 0.0) * select(1.0, directionalVisibility, index == 0);
|
|
21626
|
+
}
|
|
21627
|
+
for (var index = 0; index < lighting.pointLightCount; index++) {
|
|
21628
|
+
let light = lighting_getPointLight(index);
|
|
21629
|
+
let offset = light.position - position;
|
|
21630
|
+
let visibility = select(1.0, pointVisibility[min(index, 3)], index < 4);
|
|
21631
|
+
irradiance += light.color * max(dot(normal, normalize(offset)), 0.0) * visibility / max(getPointLightAttenuation(light, length(offset)), 0.0001);
|
|
21632
|
+
}
|
|
21633
|
+
for (var index = 0; index < lighting.spotLightCount; index++) {
|
|
21634
|
+
let light = lighting_getSpotLight(index);
|
|
21635
|
+
irradiance += light.color * max(dot(normal, normalize(light.position - position)), 0.0) * select(1.0, spotVisibility[min(index, 3)], index < 4) / max(getSpotLightAttenuation(light, position), 0.0001);
|
|
21636
|
+
}
|
|
21637
|
+
return irradiance;
|
|
21638
|
+
}
|
|
21639
|
+
`,
|
|
21640
|
+
vs: `layout(std140) uniform lightmapBakeUniforms {
|
|
21641
|
+
int uvSet;
|
|
21642
|
+
mat3 uvTransform;
|
|
21643
|
+
float chartId;
|
|
21644
|
+
} lightmapBake;`,
|
|
21645
|
+
fs: `layout(std140) uniform lightmapBakeUniforms {
|
|
21646
|
+
int uvSet;
|
|
21647
|
+
mat3 uvTransform;
|
|
21648
|
+
float chartId;
|
|
21649
|
+
} lightmapBake;
|
|
21650
|
+
|
|
21651
|
+
vec3 lightmap_getIrradiance(vec3 position, vec3 normal, float directionalVisibility, vec4 pointVisibility, vec4 spotVisibility) {
|
|
21652
|
+
if (lighting.enabled == 0) {return vec3(0.0);}
|
|
21653
|
+
vec3 irradiance = lighting.ambientColor;
|
|
21654
|
+
for (int index = 0; index < lighting.directionalLightCount; index++) {
|
|
21655
|
+
DirectionalLight light = lighting_getDirectionalLight(index);
|
|
21656
|
+
irradiance += light.color * max(dot(normal, -normalize(light.direction)), 0.0) * (index == 0 ? directionalVisibility : 1.0);
|
|
21657
|
+
}
|
|
21658
|
+
for (int index = 0; index < lighting.pointLightCount; index++) {
|
|
21659
|
+
PointLight light = lighting_getPointLight(index);
|
|
21660
|
+
vec3 offset = light.position - position;
|
|
21661
|
+
irradiance += light.color * max(dot(normal, normalize(offset)), 0.0) * (index < 4 ? pointVisibility[index] : 1.0) / max(getPointLightAttenuation(light, length(offset)), 0.0001);
|
|
21662
|
+
}
|
|
21663
|
+
for (int index = 0; index < lighting.spotLightCount; index++) {
|
|
21664
|
+
SpotLight light = lighting_getSpotLight(index);
|
|
21665
|
+
irradiance += light.color * max(dot(normal, normalize(light.position - position)), 0.0) * (index < 4 ? spotVisibility[index] : 1.0) / max(getSpotLightAttenuation(light, position), 0.0001);
|
|
21666
|
+
}
|
|
21667
|
+
return irradiance;
|
|
21668
|
+
}
|
|
21669
|
+
`
|
|
21670
|
+
};
|
|
21671
|
+
|
|
21672
|
+
// src/modules/lighting/lightmap/lightmap-filter.ts
|
|
21673
|
+
var lightmapFilter = {
|
|
21674
|
+
name: "lightmapFilter",
|
|
21675
|
+
bindingLayout: [
|
|
21676
|
+
{ name: "lightmapFilter", group: 0 },
|
|
21677
|
+
{ name: "currentTexture", group: 0 },
|
|
21678
|
+
{ name: "previousTexture", group: 0 },
|
|
21679
|
+
{ name: "chartTexture", group: 0 }
|
|
21680
|
+
],
|
|
21681
|
+
uniformTypes: { weight: "f32", mode: "i32" },
|
|
21682
|
+
defaultUniforms: { weight: 1, mode: 0 },
|
|
21683
|
+
getUniforms: (props) => props,
|
|
21684
|
+
source: `
|
|
21685
|
+
struct LightmapFilterUniforms {weight: f32, mode: i32};
|
|
21686
|
+
@group(0) @binding(auto) var<uniform> lightmapFilter: LightmapFilterUniforms;
|
|
21687
|
+
@group(0) @binding(auto) var currentTexture: texture_2d<f32>;
|
|
21688
|
+
@group(0) @binding(auto) var previousTexture: texture_2d<f32>;
|
|
21689
|
+
@group(0) @binding(auto) var chartTexture: texture_2d<f32>;
|
|
21690
|
+
fn lightmapFilter_getColor(coordinates: vec2i) -> vec4f {
|
|
21691
|
+
let current = textureLoad(currentTexture, coordinates, 0);
|
|
21692
|
+
if (lightmapFilter.mode == 0) {
|
|
21693
|
+
let previous = textureLoad(previousTexture, coordinates, 0);
|
|
21694
|
+
return vec4f(mix(previous.rgb, current.rgb, lightmapFilter.weight), current.a);
|
|
21695
|
+
}
|
|
21696
|
+
if (lightmapFilter.mode == 2 || current.a > 0.0) {return current;}
|
|
21697
|
+
let chart = textureLoad(chartTexture, coordinates, 0).r;
|
|
21698
|
+
if (chart <= 0.0) {return current;}
|
|
21699
|
+
let size = vec2i(textureDimensions(currentTexture));
|
|
21700
|
+
for (var y = -1; y <= 1; y++) {
|
|
21701
|
+
for (var x = -1; x <= 1; x++) {
|
|
21702
|
+
let neighbor = coordinates + vec2i(x, y);
|
|
21703
|
+
if (all(neighbor >= vec2i(0)) && all(neighbor < size)) {
|
|
21704
|
+
let candidate = textureLoad(currentTexture, neighbor, 0);
|
|
21705
|
+
if (candidate.a == chart) {return candidate;}
|
|
21706
|
+
}
|
|
21707
|
+
}
|
|
21708
|
+
}
|
|
21709
|
+
return current;
|
|
21710
|
+
}`,
|
|
21711
|
+
fs: `
|
|
21712
|
+
layout(std140) uniform lightmapFilterUniforms {
|
|
21713
|
+
float weight;
|
|
21714
|
+
int mode;
|
|
21715
|
+
} lightmapFilter;
|
|
21716
|
+
uniform sampler2D currentTexture;
|
|
21717
|
+
uniform sampler2D previousTexture;
|
|
21718
|
+
uniform sampler2D chartTexture;
|
|
21719
|
+
vec4 lightmapFilter_getColor(ivec2 coordinates) {
|
|
21720
|
+
vec4 current = texelFetch(currentTexture, coordinates, 0);
|
|
21721
|
+
if (lightmapFilter.mode == 0) {
|
|
21722
|
+
return vec4(mix(texelFetch(previousTexture, coordinates, 0).rgb, current.rgb, lightmapFilter.weight), current.a);
|
|
21723
|
+
}
|
|
21724
|
+
if (lightmapFilter.mode == 2 || current.a > 0.0) {return current;}
|
|
21725
|
+
float chart = texelFetch(chartTexture, coordinates, 0).r;
|
|
21726
|
+
ivec2 size = textureSize(currentTexture, 0);
|
|
21727
|
+
if (chart <= 0.0) return current;
|
|
21728
|
+
for (int y = -1; y <= 1; y++) {
|
|
21729
|
+
for (int x = -1; x <= 1; x++) {
|
|
21730
|
+
ivec2 neighbor = coordinates + ivec2(x,y);
|
|
21731
|
+
if (all(greaterThanEqual(neighbor, ivec2(0))) && all(lessThan(neighbor,size))) {
|
|
21732
|
+
vec4 candidate = texelFetch(currentTexture, neighbor, 0);
|
|
21733
|
+
if (candidate.a == chart) {return candidate;}
|
|
21734
|
+
}
|
|
21735
|
+
}
|
|
21736
|
+
}
|
|
21737
|
+
return current;
|
|
21738
|
+
}`
|
|
21739
|
+
};
|
|
21595
21740
|
return __toCommonJS(bundle_exports);
|
|
21596
21741
|
})();
|
|
21597
21742
|
return __exports__;
|