donmccurdy / three-gltf-viewer

Drag-and-drop preview for glTF 2.0 models in WebGL using three.js.
https://gltf-viewer.donmccurdy.com/
MIT License
2.09k stars 534 forks source link

GLTF render change between each load #276

Closed Pourfex closed 2 years ago

Pourfex commented 2 years ago

Problem :

Using : https://gltf-viewer.donmccurdy.com/

Render change between 2 differents loads (on some gltfs/glb) :

image image image

How To :

Load gltf file in any GLTF-Viewer based solution, see render and reload. Render differs a lot and is not consistent.

Here is a link to an example file for further investigation : https://blocinbloc-development-file-service-v2.s3.fr-par.scw.cloud/draco-debug.gltf

Expecting :

Same render between two loads.

**

If you have any insights on this, or workaround I need to setup to have same render between two loads, I'm all ears.

donmccurdy commented 2 years ago

What you're seeing here is a combination of (1) z-fighting — caused by faces lying exactly (or almost exactly) on top of one another — and (2) some variability of the order in which faces are rendered when they have the same origin.

In Blender you can see the z-fighting without reloading the model, by rotating it around a bit:

Screen Shot 2021-12-15 at 10 05 15 AM

There's a bug filed on three.js about that variability of render order (see https://github.com/mrdoob/three.js/issues/18774), but the ideal solution here would be to avoid overlapping faces in the model, by hiding the faces that aren't supposed to be visible.

Pourfex commented 2 years ago

Thanks for your reply, Very clear answer that enhance my feeling about this. I did dig the issue and other related on the threejs github, hoping to find some workaround around this.

I have a feeling that this problem cannot be handle in any loading/rendering matter, but need to be tackled with some business case rules (grey color should always be on top, ground is the least important object...) combined with GPU vertices offset (polygon offset for threejs, SL-Offset for Unity..). Am I going to the right direction here ? Or is there nothing I can do but change the model (which I cannot btw) ?

donmccurdy commented 2 years ago

If the model cannot be changed then, yes, I agree — rules for face ordering based on some knowledge of the content would likely be the best way to fix this. 👍