[Chapter 8] - Need some explanation about vertex descriptor

Several things remained unclear to me in this chapter. I would be grateful if you can shed some light on these points:

  1. Why do we add a new attribute MDLVertexAttributeColor to the defaultVertexDescriptor.
  2. In the case of increasing the number of joints, for example, up to 6, what would be the format and offset of the MDLVertexAttributeJointIndices and MDLVertexAttributeJointWeightsent attributes then. And accordingly, what would be their counterparts in the VertexIn structure (we are talking about attributes ushort4 joints [[attribute(Joints)]], float4 weights [[attribute(Weights)]]).
  1. You don’t need to. You can comment it out if you want. It’s only if you ever wanted to use the vertex color, which we don’t in this book.

  2. defaultVertexDescriptor describes how to read in the vertex data. MDLVertexAttributeJointIndices refers to a single joint matrix palette. Each vertex has one of these, and it doesn’t matter how many joints the model has. So the vertex descriptor format is not dependent upon the number of joints.

The section Joint matrix palette has an image that shows the four joints and four weights. Joints is a ushort4 and holds a ushort for each of the affected joint numbers. Weights is a float4 and holds the weighting towards the joints’ transforms.

So if you have 25 joints in your model, you might have 25 and 15 and 2 in the joints field and 0.25 and 0.3 and 0.45 (adding up to 1.0) in the weights field, meaning that a particular vertex is weighted 25% to joint 25’s transform, 30% to joint 15’s transform and 45% to joint 2’s transform.

1 Like

Hello sorry for being late)
I just want to clarify, from the last example with 25 joints. If we add to the already existing condition, for example, 16 and 8 joints and distribute the weights over five joints. As a result, we get an extra one joint, right? If I understood correctly, then four joints can have a maximum influence on one vertex at the same time?

In this case, yes. One vertex can be influenced by only four joints. This is quite common for games where you want as little processing on vertices as possible.

From the Unity manual:

I think (but could be wrong) that Godot also only allows four bones to weight each vertex.

But you’re writing your own game engine, and you can do whatever you want. I don’t think you’d use vertex descriptors, as you might want to use an array for the joint weights, and you can’t use the stage_in attribute with arrays.

1 Like