KhronosGroup / glTF

glTF – Runtime 3D Asset Delivery
Other
7.15k stars 1.14k forks source link

Clarify zero-length tangent vectors #1461

Closed lexaknyazev closed 3 years ago

lexaknyazev commented 6 years ago

This issue has been brought up several times in different glTF tools repos. In some cases, exporters write tangent vector as zero.

We need the spec to clarify whether it's allowed and to provide some implementation guidelines for better ecosystem consistency.

emackey commented 6 years ago

Also zero-length normal vectors. The Blender exporter writes zero-length normals for degenerate triangles.

emackey commented 5 years ago

Today I tried creating a model with degenerate TEXCOORD_0 triangles. It was a cube where the entire UV map was [0.5, 0.5]. Good news, the Blender-IO project would not write any invalid tangents for the test model. This "degenerate UV" case is the only case I could think of where an artist would legitimately come up with questionable tangent vectors, and even here Blender won't produce zero-length tangents.

So, I think it's fine to disallow zero-length tangents in the spec. No changes to the Blender exporter appear to be needed.

Blender does produce zero-length normals quite reproducibly as a result of degenerate triangles, for example starting and then escaping out of an extrude of one face of a cube. The validator flags this as an error. It can be cleaned up with Mesh -> Cleanup -> Degenerate Dissolve.

donmccurdy commented 5 years ago

I'm OK with disallowing zero-length tangents as well.

gleblebedev commented 5 years ago

Not unit size normal vectors could be used to store ambient occlusion information. A normal with a zero length indicates that vertex should not be lit by a light source.

emackey commented 5 years ago

@gleblebedev For an individual game engine, tricks like that can be quite useful, but in glTF the goals include broad compatibility across a wide range of platforms and engines. The spec already states that normals must be "normalized" (meaning unit-length), and I think it's just an oversight that tangents were not already specified that way as well. Various open-source implementations and sample viewers for glTF will automatically normalize both these vectors to protect against invalid data.

Degenerate geometry should not be included in a glTF. Unlit geometry should be tagged with the KHR_materials_unlit extension. Ambient occlusion has a texture channel allocated when needed.