@plasius/gpu-renderer 0.2.54 → 0.2.56
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/CHANGELOG.md +30 -0
- package/README.md +7 -0
- package/dist/index.cjs +21 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +21 -15
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/canonical-wavefront-meshes.js +11 -10
- package/src/index.d.ts +5 -0
- package/src/wavefront-mesh-sources.js +3 -3
- package/src/wavefront-scene-normalizers.js +10 -1
- package/src/wavefront-shader-materials.js +1 -1
package/dist/index.js
CHANGED
|
@@ -1558,14 +1558,6 @@ function textureSample(binding, textures, label, extra = {}) {
|
|
|
1558
1558
|
}
|
|
1559
1559
|
function cloneMaterialExtensions(material, textures) {
|
|
1560
1560
|
const extensions = { ...material.extensions ?? {} };
|
|
1561
|
-
if (material.workflow === "unlit") {
|
|
1562
|
-
const unlitKey = "KHR_materials_unlit";
|
|
1563
|
-
const unlitValue = extensions[unlitKey] ?? extensions.unlit ?? {};
|
|
1564
|
-
if (typeof unlitValue !== "object" || unlitValue === null || Array.isArray(unlitValue)) {
|
|
1565
|
-
throw new TypeError(`Canonical material extension ${unlitKey} must be an object.`);
|
|
1566
|
-
}
|
|
1567
|
-
extensions[unlitKey] = { ...unlitValue, enabled: true };
|
|
1568
|
-
}
|
|
1569
1561
|
for (const [bindingName, extensionName, textureKey] of EXTENSION_TEXTURE_BINDINGS) {
|
|
1570
1562
|
const binding = material.textures?.[bindingName];
|
|
1571
1563
|
if (!binding) {
|
|
@@ -1590,17 +1582,22 @@ function mapMaterial(material, materialRefId, textures) {
|
|
|
1590
1582
|
if (material.alphaMode === "mask") {
|
|
1591
1583
|
throw new Error("Canonical alphaMode mask is unsupported by WavefrontMeshInput.");
|
|
1592
1584
|
}
|
|
1593
|
-
if (material.workflow
|
|
1585
|
+
if (material.workflow === "unlit" || Object.hasOwn(material.extensions ?? {}, "KHR_materials_unlit") || Object.hasOwn(material.extensions ?? {}, "unlit")) {
|
|
1586
|
+
throw new Error("Canonical unlit materials are unsupported by WavefrontMeshInput; retain an unlit-capable rendering path.");
|
|
1587
|
+
}
|
|
1588
|
+
if (material.workflow !== "metallic-roughness") {
|
|
1594
1589
|
throw new Error(`Unsupported canonical material workflow: ${material.workflow}.`);
|
|
1595
1590
|
}
|
|
1596
1591
|
const mapped = {
|
|
1597
1592
|
materialRefId,
|
|
1593
|
+
alphaMode: material.alphaMode,
|
|
1598
1594
|
...material.alphaMode === "blend" ? { materialKind: "transparent" } : {},
|
|
1599
1595
|
baseColor: material.baseColorFactor,
|
|
1600
1596
|
emission: material.emissiveFactor ? [...material.emissiveFactor, 1] : [0, 0, 0, 1],
|
|
1601
1597
|
roughness: material.roughnessFactor,
|
|
1602
1598
|
metallic: material.metallicFactor,
|
|
1603
|
-
|
|
1599
|
+
// The authored factor remains in baseColor.a; do not multiply it twice.
|
|
1600
|
+
opacity: 1,
|
|
1604
1601
|
clearcoat: material.clearcoatFactor,
|
|
1605
1602
|
clearcoatRoughness: material.clearcoatRoughnessFactor,
|
|
1606
1603
|
transmission: material.transmissionFactor,
|
|
@@ -8285,7 +8282,7 @@ fn sample_surface_material(
|
|
|
8285
8282
|
let baseColorTexel = sample_atlas(baseColorAtlasTexture, triangle.baseColorAtlas, uv);
|
|
8286
8283
|
let baseColor = vec4<f32>(
|
|
8287
8284
|
clamp(triangle.color.rgb * srgb_to_linear_vec3(baseColorTexel.rgb), vec3<f32>(0.0), vec3<f32>(1.0)),
|
|
8288
|
-
clamp(triangle.color.a * baseColorTexel.a, 0.0, 1.0)
|
|
8285
|
+
select(clamp(triangle.color.a * baseColorTexel.a, 0.0, 1.0), 1.0, triangle.textureSettings.w > 0.5)
|
|
8289
8286
|
);
|
|
8290
8287
|
let metallicRoughnessTexel = sample_atlas(
|
|
8291
8288
|
metallicRoughnessAtlasTexture,
|
|
@@ -9269,6 +9266,10 @@ function createDefaultWavefrontSceneObjects() {
|
|
|
9269
9266
|
]);
|
|
9270
9267
|
}
|
|
9271
9268
|
function normalizeWavefrontMesh(input = {}, meshIndex = 0) {
|
|
9269
|
+
const alphaMode = input.alphaMode;
|
|
9270
|
+
if (alphaMode !== void 0 && alphaMode !== "opaque" && alphaMode !== "blend") {
|
|
9271
|
+
throw new TypeError("mesh alphaMode must be opaque or blend.");
|
|
9272
|
+
}
|
|
9272
9273
|
const positions = input.positions;
|
|
9273
9274
|
const positionLength = getArrayLikeLength(positions);
|
|
9274
9275
|
if (positionLength < 9 || positionLength % 3 !== 0) {
|
|
@@ -9298,7 +9299,11 @@ function normalizeWavefrontMesh(input = {}, meshIndex = 0) {
|
|
|
9298
9299
|
input.emission ?? input.emissive ?? input.material?.emission ?? input.material?.emissive,
|
|
9299
9300
|
[0, 0, 0, 1]
|
|
9300
9301
|
);
|
|
9301
|
-
const opacity =
|
|
9302
|
+
const opacity = alphaMode === "opaque" ? 1 : clamp2(
|
|
9303
|
+
readFiniteNumber("opacity", input.opacity ?? input.material?.opacity, alphaMode === "blend" ? 1 : color[3] ?? 1),
|
|
9304
|
+
0,
|
|
9305
|
+
1
|
|
9306
|
+
);
|
|
9302
9307
|
const transmission = clamp2(
|
|
9303
9308
|
readFiniteNumber("transmission", input.transmission ?? input.material?.transmission, materialExtensions.transmission),
|
|
9304
9309
|
0,
|
|
@@ -9330,6 +9335,7 @@ function normalizeWavefrontMesh(input = {}, meshIndex = 0) {
|
|
|
9330
9335
|
0
|
|
9331
9336
|
),
|
|
9332
9337
|
medium,
|
|
9338
|
+
alphaMode,
|
|
9333
9339
|
color: Object.freeze(color),
|
|
9334
9340
|
emission: Object.freeze(emission),
|
|
9335
9341
|
roughness: clamp2(readFiniteNumber("roughness", input.roughness ?? input.material?.roughness, 0.72), 0, 1),
|
|
@@ -9481,7 +9487,7 @@ function createMeshTriangleRecords(meshes, gpuMaterialSource = null) {
|
|
|
9481
9487
|
clampUnit(mesh.normalTexture?.scale ?? mesh.normalTexture?.strength ?? 1),
|
|
9482
9488
|
clampUnit(mesh.occlusionTexture?.strength ?? 1),
|
|
9483
9489
|
clampUnit(mesh.emissiveTexture?.strength ?? 1),
|
|
9484
|
-
0
|
|
9490
|
+
mesh.alphaMode === "opaque" ? 1 : 0
|
|
9485
9491
|
]),
|
|
9486
9492
|
extensionTextures: Object.freeze(
|
|
9487
9493
|
Object.fromEntries(
|
|
@@ -9824,7 +9830,7 @@ function createWavefrontGpuMaterialSource(meshes = []) {
|
|
|
9824
9830
|
clampUnit(mesh.normalTexture?.scale ?? mesh.normalTexture?.strength ?? 1),
|
|
9825
9831
|
clampUnit(mesh.occlusionTexture?.strength ?? 1),
|
|
9826
9832
|
clampUnit(mesh.emissiveTexture?.strength ?? 1),
|
|
9827
|
-
0
|
|
9833
|
+
mesh.alphaMode === "opaque" ? 1 : 0
|
|
9828
9834
|
]);
|
|
9829
9835
|
});
|
|
9830
9836
|
return Object.freeze({
|
|
@@ -10009,7 +10015,7 @@ function createWavefrontGpuMeshSource(meshes = [], gpuMaterialSourceInput = null
|
|
|
10009
10015
|
clampUnit(mesh.normalTexture?.scale ?? mesh.normalTexture?.strength ?? 1),
|
|
10010
10016
|
clampUnit(mesh.occlusionTexture?.strength ?? 1),
|
|
10011
10017
|
clampUnit(mesh.emissiveTexture?.strength ?? 1),
|
|
10012
|
-
0
|
|
10018
|
+
mesh.alphaMode === "opaque" ? 1 : 0
|
|
10013
10019
|
]);
|
|
10014
10020
|
vertexCursor += meshVertexCount;
|
|
10015
10021
|
indexCursor += mesh.indices.length;
|