zeux / meshoptimizer

Mesh optimization library that makes meshes smaller and faster to render
MIT License
5.52k stars 474 forks source link

gltfpack: floating point attributes for normals #632

Closed CITIZENDOT closed 10 months ago

CITIZENDOT commented 10 months ago

Currently, positions can use floating point attributes with:

-vpf: use floating point attributes for positions

But normals are always quantized. I'm seeing little artifacts in the model with normal attributes which are not present in uncompressed model. When I reduced the quantization bits from default (8) to 4, the artifacts became severe => Artifacts are due to quantization.

I would love a flag to use floating point attributes for normals. Like below:

-vnf: use floating point attributes for normals
zeux commented 10 months ago

I would recommend -vn 12 instead.

CITIZENDOT commented 10 months ago

I have tried with -vn 16 and still seeing artifacts.

zeux commented 10 months ago

If you're still seeing them with -vn 16 then I don't think they are normal-related, so I doubt floating-point normals would improve this -- or maybe there's some issue with -vn. Do you have a model you can share?

CITIZENDOT commented 10 months ago

Do you have a model you can share?

Yes. Models are quite large: https://drive.google.com/drive/folders/1lkT9YFSFEx-MgRC-G8YAaGlb3GDlz9Ow?usp=drive_link I also added a imgur post link so you can directly see the models without having to download them. I used https://gltf-viewer.donmccurdy.com to view models.

Let me know if you have viewed the models and I'll make the folder private,

zeux commented 10 months ago

Thanks - feel free to delete the files, I'll need to debug this later.

CITIZENDOT commented 10 months ago

Thank you!

zeux commented 10 months ago

This is a similar problem to #515 -- the model uses morph target based animation by just serializing keyframes as morph targets, and currently the range of normals is always [-1, 1] when quantized, so significant normal deformations see visible artifacts regardless of the number of bits used. On that model the animations are less aggressive so the issue is mitigated by clamping, but here clamping isn't sufficient. Using floating point normals would fix this; there may or may not be better alternatives though, we'll see...