meshoptimizer icon indicating copy to clipboard operation
meshoptimizer copied to clipboard

Simplification should recognize and handle UV mirroring seams

Open Makio64 opened this issue 1 year ago • 2 comments
trafficstars

Rare case but on some models, simplification lead to UV artefacts : UVs are getting fully streched (same value on both vertices) when many other triangles could have been optimized instead, I suggest to give a lower priority to simplify/remove vertices/faces of the mesh leading to these results.

It might also be a bug in the way the uvs get re-assigned.

The model used to illustrate this example : https://www.dropbox.com/scl/fi/po761ykdiqdmtbzd9fitf/rhino.glb?rlkey=s6jp06vtr4id0opnv76wwys1p&dl=0

Before simplify : Screenshot 2024-07-08 at 16 25 05

After simplify : Screenshot 2024-07-08 at 16 14 54

Makio64 avatar Jul 08 '24 14:07 Makio64

Are UVs mirrored here? If so then yeah it’s a known issue atm, and will get addressed eventually.

zeux avatar Jul 08 '24 15:07 zeux

Yeah I looked at the scene closer and it's indeed UV mirroring. This needs special handling in the simplifier, probably as a separate pre-process.

Re-attaching the file so that this isn't lost in the future (I also regenerated the normals here because they were just broken in the input file): rhino.zip rhino-tbn.zip

Worth noting is that if the GLB file gets re-exported with tangent data and a normal map (without a normal map gltfpack needs -kv flag), the simplifier will automatically recognize the mirroring seam and simplify correctly (of course, this ideally should work without tangent information present to begin with): image

zeux avatar Jul 08 '24 16:07 zeux

Is there currently no way to prevent this issue with the meshoptimizer directly?

Ipotrick avatar Jan 26 '25 20:01 Ipotrick

Not currently; it's on a future roadmap to provide some simpler way along the lines of what gltfpack is doing manually by exposing a way to request individual vertices on the UV seam to be treated as seams without having to duplicate vertices. Currently you either have to do what gltfpack is doing, or if your geometry has correct tangents they should automatically solve the issue as well.

zeux avatar Jan 26 '25 20:01 zeux

Dumb question, but would it work to simply pass uvs as attributes within meshopt_simplifyWithAttributes to combat this for now?

Ipotrick avatar Jan 26 '25 20:01 Ipotrick

I quickly tried it and passing uvs to meshopt_simplifyWithAttributes with a small weight and that fixes the issue i see with uv mirroring nicely 👍

Ipotrick avatar Jan 26 '25 20:01 Ipotrick

@Ipotrick I'm interested by this solution, so do you mean you're adding a very small random to the uvs ? like between ~0.000001 / -0.000001 ?

Makio64 avatar Jan 27 '25 01:01 Makio64

@Makio64 i simply list the uvs as attributes as well with a weight of 1.0f. As the uvs already dont vary very much between vertices a weight of 1.0f seems to prevent a lot of uv "miss simplifications" while not effecting overall mesh quality/ simplification level.

It does not fully fix this issue. But it does prevent it from happening in many instances.

Ipotrick avatar Jan 27 '25 02:01 Ipotrick