I’m working on a voxel-style model in Blender that uses UV mapping to assign vertex colors. The UVs are mapped onto the following pallete:
Then I paint the desired vertex colors by mapping the UVs accordingly:
(0.0, 0.5) = white
(0.1, 0.5) = light blue
(0.5, 0.5) = red…
My concern is that using floating-point precision for elements in such discrete steps might be a waste of data. As I understand it, GLTF uses 4-byte float types. However, something like this could use a single byte, as I only need the
[0, 9] range, then I can handle the division in the shader code:
uv / 10.0. I see in the GLTF spec that it supports float, short, and byte.
How do I export my UVs in single-byte format with the new Blender 2.8 GLTF 2.0 exporter? I scoured the docs to no avail.
Is there a way of getting rid of the
V data in my
UVs? Since they’re always
0.5, there’s no need to transmit that repetitive information.
Question 1: The core glTF format doesn’t allow single-byte format for UVs, and the Blender exporter doesn’t implement it. You could include the draft KHR_mesh_quantization extension instead, which loosens that requirement to allow single-byte UVs. https://github.com/zeux/meshoptimizer#gltfpack might do this for you, although it would also bake your
uv / 10 divisor into a texture transform — that would be well and good, except three.js doesn’t fully support per-texture transforms yet, so you’d still end up doing it in your shader.
Question 2: This isn’t allowed by the glTF spec; features like this would introduce considerable complexity for engines that need to support all possible file variants. However, I’d expect compression (Draco, Meshopt, or Gzip) to eliminate the cost of your duplicate
V data pretty effectively.
Alternatively, you could just write a custom attribute
_U, and throw whatever you want into it. It’ll be loaded as a THREE.BufferAttribute you can use in your shader. That will require some custom processing on the mesh. Both glTF-Pipeline and glTF-Transform provide examples of how to do custom glTF edits.
Great, thanks for those links! I’ll try to do some comparison between Draco compression and the custom
_U attribute you recommended. I like the idea behind quantization, but it seems a bit more complicated to implement.
I cannot believe this… after using DRACO compression, my binary file dropped from 5,000 KBs to 270KBs, and the models look identical!!
I played around with the settings, and it looks like the GLTF exporter in Blender already has UV quantization built in, which made it super easy!
I swear, when I saw the filesize I thought I must’ve made a mistake. I still can’t believe the quality of this compression!