🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

vertex winding order, clockwise or counter-clockwise?

Started by
5 comments, last by a light breeze 2 years, 1 month ago

Is there a standard for the ordering of triangle vertices?

We have two possible orderings (clockwise, counter-clockwise), but switching between them, potentially on a per-model basis, seems like a really bad choice.

I remember asking a 3d artist about this, and she didn't really know, leading me to the conclusion that this is something that only the graphics programmers need to know/care about.

I'm using glTF2 for model import, but will I need to create my own offline tool to process models to the correct format, or can I make some general assumptions?

Thanks! ?

Advertisement

The hardware and the drivers are agnostic, you set them and they use it. For a default D3D and Vulkan use right handed coordinate systems with CCW ordering, OGL is left handed with CW ordering. All can be adjusted by setting a state flag.

For software and tools, it varies. Unreal uses CCW, Unity uses CW. Blender defaults to CW, Maya and 3D Studio both currently default to CCW but IIRC 3DS changed their defaults about 15 years ago. Graphics formats have their own preference, with more modern formats letting you both specify the winding order that was used and the vertex normals.

The major engines have exporters that will shift formats to the target system's preferred format as part of their export step.

Many tools and technologies are trending toward CCW and right handed systems as the default, but it is not universal and for tools you must anticipate both options.

frob said:
For a default D3D and Vulkan use right handed coordinate systems with CCW ordering, OGL is left handed with CW ordering. All can be adjusted by setting a state flag.

Are you sure about that? OpenGL is definitely right handed with CCW==front face. AFAIK D3D is left handed.

Kronos says:

On a freshly created OpenGL Context, the default front face is GL_CCW

I didn't look it up and am now less sure of the defaults, other than recalling they're opposite.

Either way, always set it and don't worry about defaults.

@undefined I read a long article about handedness. D3D is left-handed. I don't know about Vulkan, because it does some things differently than GL e.g. by inverting the viewport transform. OpenGL is left-handed if we speak about NDC, but traditionally we have been using right-handed camera transformations.

But I don't understand what this has to do with vertex-winding order, is it because z-axis is inverted? Maybe someone can explain - like what should I do in my engine if I switch between OpenGL and Vulkan as backends?

The rendering API doesn't really care, but in gltf the winding order is counterclockwise. This is reversed if you flip a mesh by scaling it by a negative amount, either along one axis or on all three.

Source: https://www.khronos.org/registry/glTF/specs/2.0/glTF-2.0.html

When a mesh primitive uses any triangle-based topology (i.e., triangles, triangle strip, or triangle fan), the determinant of the node’s global transform defines the winding order of that primitive. If the determinant is a positive value, the winding order triangle faces is counterclockwise; in the opposite case, the winding order is clockwise.

Also, gltf is right-handed. This matters because switching the handedness of a mesh without changing the mesh data flips the mesh, and therefore also flips the winding order.

This topic is closed to new replies.

Advertisement