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

glTF support is missing features #528

Closed
romainguy opened this issue Nov 26, 2018 · 16 comments
Closed

glTF support is missing features #528

romainguy opened this issue Nov 26, 2018 · 16 comments
Assignees
Labels
bug Something isn't working

Comments

@romainguy
Copy link
Collaborator

Our glTF viewer doesn't work entirely just yet. Here's what I found so far:

  • Tangents/bitangents are not computed correctly if not present in the model
  • We always use the default sampler instead of using the sampler described in the glTF file
  • Vertex colors are ignored
  • Transforms (rotation in particular) are not always handled properly

I found these issues while trying to load various Sketchfab assets.

@romainguy romainguy added the bug Something isn't working label Nov 26, 2018
@romainguy
Copy link
Collaborator Author

Rotation issue: https://sketchfab.com/models/a4ca0e3864e143af9bf1dffc7fc8029b (you have to zoom into the black sphere to seen the scene). This model also seems to use vertex colors? Our render is definitely off.

Non-default samplers: https://sketchfab.com/models/94b24a60dc1b48248de50bf087c0f042 The tramway and some of the walls are not textured properly, most likely because we don't use the right sampler

None of the textures are loaded for this model: https://sketchfab.com/models/282f497334f64a589edee4e63ad7e428

@romainguy
Copy link
Collaborator Author

romainguy commented Nov 28, 2018

Another bug: the water in https://sketchfab.com/models/e051a32d21d6453c8fad408082492267 is not transparent. The alpha mask is also not working on the bushes in that scene.

@prideout
Copy link
Contributor

I'm working on the first bullet in the original problem description (Tangents/bitangents are not computed correctly), which is exemplified by glTF-Sample-Models/2.0/NormalTangentTest.

prideout added a commit that referenced this issue Nov 28, 2018
We started to write our own implementation of mikktspace, but it
required an unindexed mesh for input. This was awkward because assimp is
already applying a pipeline of operations that includes tangent
generation and indexing. It felt reduandant to add our own pipeline on
top of that (unindexing => tangentgen => reindexing).

Since assimp's CalcTangentsProcess method is already producing
tangents that follow the orientation implied by texture coordinates,
this simply needs to be tweaked to match glTF. (flip the bitangent)

Also fixed a bug for the case where models have neither UV's nor
tangents, where we were calling norm instead of normalize. :)
prideout added a commit that referenced this issue Nov 28, 2018
We started to write our own implementation of mikktspace, but it
required an unindexed mesh for input. This was awkward because assimp is
already applying a pipeline of operations that includes tangent
generation and indexing. It felt reduandant to add our own pipeline on
top of that (unindexing => tangentgen => reindexing).

Since assimp's CalcTangentsProcess method is already producing
tangents that follow the orientation implied by texture coordinates,
this simply needs to be tweaked to match glTF. (flip the bitangent)

Also fixed a bug for the case where models have neither UV's nor
tangents, where we were calling norm instead of normalize. :)
prideout added a commit that referenced this issue Nov 28, 2018
We started to write our own implementation of mikktspace, but it
required an unindexed mesh for input. This was awkward because assimp is
already applying a pipeline of operations that includes tangent
generation and indexing. It felt reduandant to add our own pipeline on
top of that (unindexing => tangentgen => reindexing).

Since assimp's CalcTangentsProcess method is already producing
tangents that follow the orientation implied by texture coordinates,
this simply needs to be tweaked to match glTF. (flip the bitangent)

Also fixed a bug for the case where models have neither UV's nor
tangents, where we were calling norm instead of normalize. :)
@magicwhale
Copy link
Contributor

magicwhale commented Nov 29, 2018

Rotation issue: https://sketchfab.com/models/a4ca0e3864e143af9bf1dffc7fc8029b (you have to zoom into the black sphere to seen the scene). This model also seems to use vertex colors? Our render is definitely off.

Non-default samplers: https://sketchfab.com/models/94b24a60dc1b48248de50bf087c0f042 The tramway and some of the walls are not textured properly, most likely because we don't use the right sampler

None of the textures are loaded for this model: https://sketchfab.com/models/282f497334f64a589edee4e63ad7e428

The first model seems to just have some rotation issues with the asset itself, and some of the colors aren't showing up because vertex colors aren't implemented yet.
For the second and third models, the issue seems to just be with the use of multiple UV coordinates.

Another bug: the water in https://sketchfab.com/models/e051a32d21d6453c8fad408082492267 is not transparent. The alpha mask is also not working on the bushes in that scene.

I realized that I didn't implement alpha masking and blending for unlit materials, which this scene uses.

I'm working on fixing the issues now.

@romainguy
Copy link
Collaborator Author

Crash opening this file: https://sketchfab.com/models/f8d3c7506f3545108dcf7f6c170e19e1

@magicwhale
Copy link
Contributor

magicwhale commented Dec 4, 2018

It seems like that file and the files mentioned in #503 have some kind of error within the gltf file, and this is causing the viewer to crash within Assimp when it is loading the gltf.

I saw that Don McCurdy's gltf viewer is still able to show the model even though it says there are errors within the file, so we could find a way to load the files by ignoring the malformed lines.

@donmccurdy
Copy link

It seems like that file and the files mentioned in #503 have some kind of error within the gltf file, and this is causing the viewer to crash within Assimp when it is loading the gltf.

If the errors seem unreasonable, I'm glad to send feedback to Sketchfab. Some viewers (like Facebook 3D Posts) enforce a "no validation errors" policy, and if these are issues you'd rather not work around, requiring stricter conformance from exporters is acceptable. The tolerance in my viewer is more accidental than planned. :)

@romainguy
Copy link
Collaborator Author

Well crashing is never a good option :) But if the crash is inside Assimp our best bet would be to fix it there and upstream the change. We could also investigate TinyGLTF

@romainguy
Copy link
Collaborator Author

Multi UV sets support is now in. @magicwhale were you able to figure out where the other issues come from?

AdrianAtGoogle pushed a commit to AdrianAtGoogle/filament that referenced this issue Jan 30, 2019
We started to write our own implementation of mikktspace, but it
required an unindexed mesh for input. This was awkward because assimp is
already applying a pipeline of operations that includes tangent
generation and indexing. It felt reduandant to add our own pipeline on
top of that (unindexing => tangentgen => reindexing).

Since assimp's CalcTangentsProcess method is already producing
tangents that follow the orientation implied by texture coordinates,
this simply needs to be tweaked to match glTF. (flip the bitangent)

Also fixed a bug for the case where models have neither UV's nor
tangents, where we were calling norm instead of normalize. :)
@prideout prideout self-assigned this Jan 31, 2019
@cdata
Copy link

cdata commented Feb 20, 2019

@romainguy we recently proposed testing rendering parity between <model-viewer> (based on Three.js / GLTF Loader) and Filament for a number of the Khronos sample glTFs (relevant PR). We found samples that reproduce a number of the issues you referenced here. I'm leaving some of our test results below in case they might help inform your work to fix the related issues:

Tangents/bitangents are not computed correctly if not present in the model

Related sample model: Normal Tangent Mirror Test

Filament result Expected result
image

Vertex colors are ignored

Related sample model: Vertex Color Test

Filament result Expected result
image

Transforms (rotation in particular) are not always handled properly

Related sample model: Texture Transform Test

When I saw the results of this test it rang a bell. I'm not sure if you meant texture rotations, but perhaps this is relevant.

Filament result Expected result
image

@romainguy
Copy link
Collaborator Author

Thank you. Texture transforms are just not supported at all at the moment. We're moving to a different gltf loader to fix all these issues.

@romainguy
Copy link
Collaborator Author

I'm surprised by the tangents though, @prideout wasn't this fixed?

@prideout
Copy link
Contributor

Just now reproduced the issue with Normal Tangent Mirror, I'm surprised too. Will investigate.

@prideout
Copy link
Contributor

tl;dr:

For now I think I should simply modify our copy of MeshAssimp to negate the bitangent, thus moving our current workaround downward so that it doesn't affect the tangents-are-available case. This will be fixed in a more proper way in the new glTF loader that I'm working on.

details:

We render NormalTangentTest correctly (where tangents are computed via MeshAssimp) but we do not render NormalTangentMirrorTest correctly (where tangents are supplied in the model).

When MeshAssimp generates tangents and bitangents, it basically makes tangents follow texcoord U, and bitangents follow texcoord V. The resulting tangent vectors are fairly consistent with a couple popular viewers that I tried, but the bitangent vectors are not. Other viewers use different approaches:

  • ThreeJS (and therefore Don McCurdy's viewer) does this
  • The Khronos ref viewer does this
  • The spec recommends mikktspace (which Blender uses I think) which does this

@donmccurdy
Copy link

ThreeJS (and therefore Don McCurdy's viewer) does this

Note that this change is very recent, and won't be visible in my viewer until threejs r102 is released. But I think BabylonJS (and this viewer) do the same.

prideout added a commit that referenced this issue Feb 20, 2019
Assimp's CalcTangentSpace deviates from de facto glTF 2.0 so we were
compensating for this with an unconditional fixup in MeshAssimp. However
the fixup should apply only when CalcTangentSpace is active, i.e. when
the model is missing tangents.

This makes it so that NormalTangentMirrorTest (has tangents) and
NormalTangentTest (needs tangents) both look reasonable.

I also noticed that MeshAssimp was inexplicably applying
aiProcess_CalcTangentSpace twice: once as a flag, and once as a
post-process. I removed the latter.

This will be fixed in the upcoming cgltf-based loader, which will
use our officially-sanctioned utility method in VertexBuffer.

See #528
prideout added a commit that referenced this issue Feb 20, 2019
Assimp's CalcTangentSpace deviates from de facto glTF 2.0 so we were
compensating for this with an unconditional fixup in MeshAssimp. However
the fixup should apply only when CalcTangentSpace is active, i.e. when
the model is missing tangents.

This makes it so that NormalTangentMirrorTest (has tangents) and
NormalTangentTest (needs tangents) both look reasonable.

I also noticed that MeshAssimp was inexplicably applying
aiProcess_CalcTangentSpace twice: once as a flag, and once as a
post-process. I removed the latter.

This will be fixed in the upcoming cgltf-based loader, which will
use our officially-sanctioned utility method in VertexBuffer.

See #528
prideout added a commit that referenced this issue Feb 25, 2019
This moves our existing VertexBuffer utility into a new "geometry"
library and adds new functionality for computing tangents based on UV's.
The UV-based method comes from Eric Lengyel.

We considered mikktspace (which thankfully has a zlib-style license) but
it would require re-indexing via meshoptimizer and is therefore a bit
heavyweight.

The new library has no dependencies and will add only 7 KB to Filament's
Android aar file.

Fixes #858 and preps for #528.
prideout added a commit that referenced this issue Feb 25, 2019
This moves our existing VertexBuffer utility into a new "geometry"
library and adds new functionality for computing tangents based on UV's.
The UV-based method comes from Eric Lengyel.

We considered mikktspace (which thankfully has a zlib-style license) but
it would require re-indexing via meshoptimizer and is therefore a bit
heavyweight.

The new library has no dependencies and will add only 7 KB to Filament's
Android aar file.

Fixes #858 and preps for #528.
prideout added a commit that referenced this issue Feb 25, 2019
This moves our existing VertexBuffer utility into a new "geometry"
library and adds new functionality for computing tangents based on UV's.
The UV-based method comes from Eric Lengyel.

We considered mikktspace (which thankfully has a zlib-style license) but
it would require re-indexing via meshoptimizer and is therefore a bit
heavyweight.

The new library has no dependencies and will add only 7 KB to Filament's
Android aar file.

Fixes #858 and preps for #528.
prideout added a commit that referenced this issue Feb 26, 2019
This moves our existing VertexBuffer utility into a new "geometry"
library and adds new functionality for computing tangents based on UV's.
The UV-based method comes from Eric Lengyel.

We considered mikktspace (which thankfully has a zlib-style license) but
it would require re-indexing via meshoptimizer and is therefore a bit
heavyweight.

The new library has no dependencies and will add only 7 KB to Filament's
Android aar file.

Fixes #858 and preps for #528.
prideout added a commit that referenced this issue Feb 27, 2019
This moves our existing VertexBuffer utility into a new "geometry"
library and adds new functionality for computing tangents based on UV's.
The UV-based method comes from Eric Lengyel.

We considered mikktspace (which thankfully has a zlib-style license) but
it would require re-indexing via meshoptimizer and is therefore a bit
heavyweight.

The new library has no dependencies and will add only 7 KB to Filament's
Android aar file.

Fixes #858 and preps for #528.
@romainguy
Copy link
Collaborator Author

Closing this for now. There are still a couple of unsupported features like blend shapes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants