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

Vertex colors don't load #27

Closed
camnewnham opened this issue Aug 4, 2021 · 8 comments
Closed

Vertex colors don't load #27

camnewnham opened this issue Aug 4, 2021 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@camnewnham
Copy link
Contributor

camnewnham commented Aug 4, 2021

Description

I've been working on #16 and run into an issue where vertex colors don't load either for meshes or point clouds.

The vertex attribute descriptors appear correct:
VertexAttribute=Color, VertexAttributeFormat=UInt8, numComponents=4, elementSize=4

Attempting to access unityMesh.colors results in:

Unsupported conversion of vertex data (format 6 to 0, dimensions 4 to 4)
UnityEngine.Mesh:get_colors ()

If the resulting array (from unityMesh.colors) is read the results are all rgba(0,0,0,0), hence the black.

This applies to both point clouds (in my WIP implementation) and meshes (in main)

There's minimal discussion of MeshData online, but I did see this which suggests it could be a Unity issue.

Colors do load correctly in GLTFast when models are not draco compressed.

Environment

Unity 2020.3.15f2
DracoUnity main 9f5161b

Expected Behaviour

In three.js:
image
Point Cloud (vertex colors) on left, Mesh (vertex colors) in center, Mesh (no colors) on right.

Actual Behaviour

In GLTFast/DracoUnity:
image

@camnewnham
Copy link
Contributor Author

Here is an example file for reproduction:

bunny_mesh_color.zip
The regular .glb works correctly. The draco compressed .glb does not load colors in glTFast/Unity

In threejs:
image

In Unity/glTFast:
image

@atteneder
Copy link
Owner

first suspicion: Unity cannot work with uint8 vertex colors.

@atteneder
Copy link
Owner

first suspicion: Unity cannot work with uint8 vertex colors.

confirmed! I hacked in a uint8->float conversion and then it's correct:

image

Next steps:

  • Figure out if it's even possible to render non-default data types with existing shaders (for colors, but all other vertex attributes as well)

If not:

  • Convert incompatible data types into compatible ones in a Job in C#

The "if not" part, unfortunately, is quite some work.

Easy workaround should be to encode colors as floats (untested)

@atteneder atteneder self-assigned this Sep 11, 2021
@atteneder atteneder added the bug Something isn't working label Sep 11, 2021
@atteneder
Copy link
Owner

As it turned out, Unity can work with normalized uint8 colors, if you properly declare them as VertexAttributeFormat.UNorm8 (instead of VertexAttributeFormat.UInt8)

@camnewnham I'll release this fix soonish, but would appreciate if you could run a quick test with current main branch. Thanks!

@benvvalk
Copy link

benvvalk commented Sep 13, 2021

Thanks so much for the fix, @atteneder! I have a Piglet customer who is having the same issue (vertex colors not correctly loaded from their Draco-encoded model).

I'll test the HEAD version of DracoUnity with Piglet and let you know if it works!

@benvvalk
Copy link

It works!

I just confirmed that the vertex colors load correctly in Piglet using the HEAD DracoUnity version. I tested with Unity 2020.3.9f1, using the bunny model above and also with the example model that my customer shared privately.

@camnewnham
Copy link
Contributor Author

camnewnham commented Sep 13, 2021

Thanks @atteneder, good find!
Confirming that this works for me.

@JamWils
Copy link

JamWils commented Apr 15, 2023

I know this is old, but thank you for the fix! I had UInt8 and was wondering why they were all black. UNorm8 made sure all of the vertex color data was passed to the new mesh data I was building.

atteneder added a commit to Unity-Technologies/DracoUnity that referenced this issue Sep 9, 2024
* fix: Sub-package install timeout never actually triggered.

* refactor: Removing code smell

* chore: Bumping sub-package versions
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

4 participants