Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GLTFExporter: Add support for WebGPURenderer #29509

Merged
merged 7 commits into from
Oct 17, 2024

Conversation

donmccurdy
Copy link
Collaborator

@donmccurdy donmccurdy commented Sep 26, 2024

@sunag sunag added this to the r170 milestone Sep 27, 2024
@donmccurdy donmccurdy marked this pull request as ready for review October 16, 2024 00:07
@donmccurdy
Copy link
Collaborator Author

@Mugen87 @sunag I think the remaining issues in this PR have been fixed – ready for review!

@Mugen87
Copy link
Collaborator

Mugen87 commented Oct 16, 2024

When using WebGPURenderer in misc_exporter_gltf I have encountered one issue.

(First of all it was necessary to remove the LineLoop object from the scene since this type of 3D object is not supported by WebGPURenderer in general.)

The real issue is that the coffeemat asset is not correctly imported in glTF Viewer. The following validation errors appear:

Error Message Pointer
MESH_PRIMITIVE_ATTRIBUTES_ACCESSOR_INVALID_FORMAT Invalid accessor format '{VEC3, UNSIGNED_INT}' for this attribute semantic. Must be one of ('{VEC3, FLOAT}', '{VEC3, BYTE}', '{VEC3, BYTE normalized}', ..., '{VEC3, UNSIGNED_SHORT}', '{VEC3, UNSIGNED_SHORT normalized}'). /meshes/0/primitives/0/attributes/POSITION
MESH_PRIMITIVE_ATTRIBUTES_ACCESSOR_INVALID_FORMAT Invalid accessor format '{VEC2, UNSIGNED_INT}' for this attribute semantic. Must be one of ('{VEC2, FLOAT}', '{VEC2, UNSIGNED_BYTE normalized}', '{VEC2, UNSIGNED_SHORT normalized}', ..., '{VEC2, SHORT normalized}', '{VEC2, UNSIGNED_SHORT}'). /meshes/0/primitives/0/attributes/TEXCOORD_0
MESH_PRIMITIVE_ATTRIBUTES_ACCESSOR_INVALID_FORMAT Invalid accessor format '{VEC3, UNSIGNED_INT}' for this attribute semantic. Must be one of ('{VEC3, FLOAT}', '{VEC3, BYTE}', '{VEC3, BYTE normalized}', ..., '{VEC3, UNSIGNED_SHORT}', '{VEC3, UNSIGNED_SHORT normalized}'). /meshes/1/primitives/0/attributes/POSITION
MESH_PRIMITIVE_ATTRIBUTES_ACCESSOR_INVALID_FORMAT Invalid accessor format '{VEC2, UNSIGNED_INT}' for this attribute semantic. Must be one of ('{VEC2, FLOAT}', '{VEC2, UNSIGNED_BYTE normalized}', '{VEC2, UNSIGNED_SHORT normalized}', ..., '{VEC2, SHORT normalized}', '{VEC2, UNSIGNED_SHORT}'). /meshes/1/primitives/0/attributes/TEXCOORD_0

@donmccurdy
Copy link
Collaborator Author

donmccurdy commented Oct 16, 2024

@Mugen87 the issue is caused by these vertex attribute conversions:

// patch for INT16 and UINT16
if ( attribute.normalized === false && ( array.constructor === Int16Array || array.constructor === Uint16Array ) ) {
const tempArray = new Uint32Array( array.length );
for ( let i = 0; i < array.length; i ++ ) {
tempArray[ i ] = array[ i ];
}
array = tempArray;
}

glTF does not permit the use of uint32 or int32 for vertex positions, and WebGPU does not permit 8-bit and 16-bit integer formats AFAIK, so the conversion for WebGPU is not compatible with glTF.

Related:

I guess GLTFExporter could convert the attributes to float32, or we could change the WebGPU patch to use float32, or we could wait on gpuweb/gpuweb#4549. But I think that probably doesn't need to block the current changes.

@donmccurdy
Copy link
Collaborator Author

Aside - when running this demo with WebGPURenderer there is a rendering issue on my device (macOS, M1, Arc/Chromium), before starting the export. Looks possibly related to integer geometry, too, maybe normalized uint8 and uint16 are not handled? Sort of off topic but just noting in case I forget. :)

@Mugen87
Copy link
Collaborator

Mugen87 commented Oct 16, 2024

Then I vote for an attribute conversion in the exporter.

@donmccurdy
Copy link
Collaborator Author

@Mugen87 I've pushed a fix for the int32/uint32 problem, the coffeemat.glb export renders without validation errors. However, texture decompression in WebGPUTextureUtils doesn't seem to be working quite correctly yet. Comparing before and after in https://gltf.report

before after
before after

The model includes KHR_texture_transform, perhaps WebGPUTextureUtils needs to temporarily disable UV transforms? I'd prefer that this be considered an unrelated issue and not part of the current PR, though.

@Mugen87 Mugen87 merged commit cef0049 into mrdoob:dev Oct 17, 2024
11 checks passed
@Mugen87
Copy link
Collaborator

Mugen87 commented Oct 17, 2024

With #29680, the coffeemat.glb export is imported correctly in gltf-viewer now.

The issue with ShaderBall.glb is more interesting. It uses normalized attributes and renders distorted in the example. However, removing all other objects from the scene and the error is gone. Depending on what objects you remove, ShaderBall.glb might be scaled up so the entire scene gets gray.

This seems to be more an issue of a broken world matrix. But I don't know yet where the root cause is. It might make sense to file a separate issue for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants