@plasius/gpu-renderer 0.2.54 → 0.2.55
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 +15 -0
- package/README.md +4 -0
- package/dist/index.cjs +17 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +17 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/canonical-wavefront-meshes.js +3 -1
- 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
|
@@ -1595,12 +1595,14 @@ function mapMaterial(material, materialRefId, textures) {
|
|
|
1595
1595
|
}
|
|
1596
1596
|
const mapped = {
|
|
1597
1597
|
materialRefId,
|
|
1598
|
+
alphaMode: material.alphaMode,
|
|
1598
1599
|
...material.alphaMode === "blend" ? { materialKind: "transparent" } : {},
|
|
1599
1600
|
baseColor: material.baseColorFactor,
|
|
1600
1601
|
emission: material.emissiveFactor ? [...material.emissiveFactor, 1] : [0, 0, 0, 1],
|
|
1601
1602
|
roughness: material.roughnessFactor,
|
|
1602
1603
|
metallic: material.metallicFactor,
|
|
1603
|
-
|
|
1604
|
+
// The authored factor remains in baseColor.a; do not multiply it twice.
|
|
1605
|
+
opacity: 1,
|
|
1604
1606
|
clearcoat: material.clearcoatFactor,
|
|
1605
1607
|
clearcoatRoughness: material.clearcoatRoughnessFactor,
|
|
1606
1608
|
transmission: material.transmissionFactor,
|
|
@@ -8285,7 +8287,7 @@ fn sample_surface_material(
|
|
|
8285
8287
|
let baseColorTexel = sample_atlas(baseColorAtlasTexture, triangle.baseColorAtlas, uv);
|
|
8286
8288
|
let baseColor = vec4<f32>(
|
|
8287
8289
|
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)
|
|
8290
|
+
select(clamp(triangle.color.a * baseColorTexel.a, 0.0, 1.0), 1.0, triangle.textureSettings.w > 0.5)
|
|
8289
8291
|
);
|
|
8290
8292
|
let metallicRoughnessTexel = sample_atlas(
|
|
8291
8293
|
metallicRoughnessAtlasTexture,
|
|
@@ -9269,6 +9271,10 @@ function createDefaultWavefrontSceneObjects() {
|
|
|
9269
9271
|
]);
|
|
9270
9272
|
}
|
|
9271
9273
|
function normalizeWavefrontMesh(input = {}, meshIndex = 0) {
|
|
9274
|
+
const alphaMode = input.alphaMode;
|
|
9275
|
+
if (alphaMode !== void 0 && alphaMode !== "opaque" && alphaMode !== "blend") {
|
|
9276
|
+
throw new TypeError("mesh alphaMode must be opaque or blend.");
|
|
9277
|
+
}
|
|
9272
9278
|
const positions = input.positions;
|
|
9273
9279
|
const positionLength = getArrayLikeLength(positions);
|
|
9274
9280
|
if (positionLength < 9 || positionLength % 3 !== 0) {
|
|
@@ -9298,7 +9304,11 @@ function normalizeWavefrontMesh(input = {}, meshIndex = 0) {
|
|
|
9298
9304
|
input.emission ?? input.emissive ?? input.material?.emission ?? input.material?.emissive,
|
|
9299
9305
|
[0, 0, 0, 1]
|
|
9300
9306
|
);
|
|
9301
|
-
const opacity =
|
|
9307
|
+
const opacity = alphaMode === "opaque" ? 1 : clamp2(
|
|
9308
|
+
readFiniteNumber("opacity", input.opacity ?? input.material?.opacity, alphaMode === "blend" ? 1 : color[3] ?? 1),
|
|
9309
|
+
0,
|
|
9310
|
+
1
|
|
9311
|
+
);
|
|
9302
9312
|
const transmission = clamp2(
|
|
9303
9313
|
readFiniteNumber("transmission", input.transmission ?? input.material?.transmission, materialExtensions.transmission),
|
|
9304
9314
|
0,
|
|
@@ -9330,6 +9340,7 @@ function normalizeWavefrontMesh(input = {}, meshIndex = 0) {
|
|
|
9330
9340
|
0
|
|
9331
9341
|
),
|
|
9332
9342
|
medium,
|
|
9343
|
+
alphaMode,
|
|
9333
9344
|
color: Object.freeze(color),
|
|
9334
9345
|
emission: Object.freeze(emission),
|
|
9335
9346
|
roughness: clamp2(readFiniteNumber("roughness", input.roughness ?? input.material?.roughness, 0.72), 0, 1),
|
|
@@ -9481,7 +9492,7 @@ function createMeshTriangleRecords(meshes, gpuMaterialSource = null) {
|
|
|
9481
9492
|
clampUnit(mesh.normalTexture?.scale ?? mesh.normalTexture?.strength ?? 1),
|
|
9482
9493
|
clampUnit(mesh.occlusionTexture?.strength ?? 1),
|
|
9483
9494
|
clampUnit(mesh.emissiveTexture?.strength ?? 1),
|
|
9484
|
-
0
|
|
9495
|
+
mesh.alphaMode === "opaque" ? 1 : 0
|
|
9485
9496
|
]),
|
|
9486
9497
|
extensionTextures: Object.freeze(
|
|
9487
9498
|
Object.fromEntries(
|
|
@@ -9824,7 +9835,7 @@ function createWavefrontGpuMaterialSource(meshes = []) {
|
|
|
9824
9835
|
clampUnit(mesh.normalTexture?.scale ?? mesh.normalTexture?.strength ?? 1),
|
|
9825
9836
|
clampUnit(mesh.occlusionTexture?.strength ?? 1),
|
|
9826
9837
|
clampUnit(mesh.emissiveTexture?.strength ?? 1),
|
|
9827
|
-
0
|
|
9838
|
+
mesh.alphaMode === "opaque" ? 1 : 0
|
|
9828
9839
|
]);
|
|
9829
9840
|
});
|
|
9830
9841
|
return Object.freeze({
|
|
@@ -10009,7 +10020,7 @@ function createWavefrontGpuMeshSource(meshes = [], gpuMaterialSourceInput = null
|
|
|
10009
10020
|
clampUnit(mesh.normalTexture?.scale ?? mesh.normalTexture?.strength ?? 1),
|
|
10010
10021
|
clampUnit(mesh.occlusionTexture?.strength ?? 1),
|
|
10011
10022
|
clampUnit(mesh.emissiveTexture?.strength ?? 1),
|
|
10012
|
-
0
|
|
10023
|
+
mesh.alphaMode === "opaque" ? 1 : 0
|
|
10013
10024
|
]);
|
|
10014
10025
|
vertexCursor += meshVertexCount;
|
|
10015
10026
|
indexCursor += mesh.indices.length;
|