# VertexAttributeDescriptor

> Information about a single VertexAttribute of a Mesh vertex.

## Definition

* **Type:** Struct
* **Namespace:** [UnityEngine.Rendering](/engine/6000.7/script-reference/unityengine/rendering.md)
* **Assembly:** UnityEngine.CoreModule
* **Implements:** [IEquatable\<VertexAttributeDescriptor>](https://learn.microsoft.com/dotnet/api/system.iequatable-1)

```csharp
public struct VertexAttributeDescriptor : IEquatable<VertexAttributeDescriptor>
```

## Remarks

[Mesh](/engine/6000.7/script-reference/unityengine/mesh.md) vertex data comprised of different Vertex Attributes. For example, a vertex can include a Position, Normal, TexCoord0, and Color. Meshes usually use a known format for data layout, for example, a position is most often a 3-component float vector ([Vector3](/engine/6000.7/script-reference/unityengine/vector3.md)), but you can also specify non-standard data formats and their layout for a Mesh.

You can use `VertexAttributeDescriptor` to specify custom mesh data layout in [Mesh.SetVertexBufferParams](/engine/6000.7/script-reference/unityengine/mesh/setvertexbufferparams.md).

Vertex data is laid out in separate "streams" (each stream goes into a separate vertex buffer in the underlying graphics API). Unity supports up to four vertex streams, but you usually use only one stream. Separate streams are most useful when some vertex attributes don't need to be processed, or you need to give the vertex attributes a specific data layout.

Within each stream, attributes of a vertex are laid out one after another, in this order: [VertexAttribute.Position](/engine/6000.7/script-reference/unityengine/rendering/vertexattribute/position.md), [VertexAttribute.Normal](/engine/6000.7/script-reference/unityengine/rendering/vertexattribute/normal.md), [VertexAttribute.Tangent](/engine/6000.7/script-reference/unityengine/rendering/vertexattribute/tangent.md), [VertexAttribute.Color](/engine/6000.7/script-reference/unityengine/rendering/vertexattribute/color.md), [VertexAttribute.TexCoord0](/engine/6000.7/script-reference/unityengine/rendering/vertexattribute/texcoord0.md), ..., [VertexAttribute.TexCoord7](/engine/6000.7/script-reference/unityengine/rendering/vertexattribute/texcoord7.md), [VertexAttribute.BlendWeight](/engine/6000.7/script-reference/unityengine/rendering/vertexattribute/blendweight.md), [VertexAttribute.BlendIndices](/engine/6000.7/script-reference/unityengine/rendering/vertexattribute/blendindices.md).

If you include `BlendWeight` or `BlendIndices` attributes in your vertex data, the following applies:

* If you use a layout other than Unity's default stream layout, Unity might reorder your vertex attributes or incorrectly render your vertices in a [SkinnedMeshRenderer](/engine/6000.7/script-reference/unityengine/skinnedmeshrenderer.md).
* Unity puts position, normal, and tangent into the same vertex stream, and uses `float32` format regardless of the format you specify.

1. In the first stream, add [VertexAttribute.Position](/engine/6000.7/script-reference/unityengine/rendering/vertexattribute/position.md), [VertexAttribute.Normal](/engine/6000.7/script-reference/unityengine/rendering/vertexattribute/normal.md) and [VertexAttribute.Tangent](/engine/6000.7/script-reference/unityengine/rendering/vertexattribute/tangent.md).
2. In the second stream, add [VertexAttribute.Color](/engine/6000.7/script-reference/unityengine/rendering/vertexattribute/color.md), and [VertexAttribute.TexCoord0](/engine/6000.7/script-reference/unityengine/rendering/vertexattribute/texcoord0.md) to [VertexAttribute.TexCoord7](/engine/6000.7/script-reference/unityengine/rendering/vertexattribute/texcoord7.md).
3. In the third stream, add [VertexAttribute.BlendWeight](/engine/6000.7/script-reference/unityengine/rendering/vertexattribute/blendweight.md) and [VertexAttribute.BlendIndices](/engine/6000.7/script-reference/unityengine/rendering/vertexattribute/blendindices.md).

All the attributes in the second stream are optional. If you don't include any `Color` or `TexCoord` attributes, add `BlendWeight` and `BlendIndices` to the second stream instead.

Not all [VertexAttributeDescriptor.format](/engine/6000.7/script-reference/unityengine/rendering/vertexattributedescriptor/format.md) and [VertexAttributeDescriptor.dimension](/engine/6000.7/script-reference/unityengine/rendering/vertexattributedescriptor/dimension.md) combinations are valid. Specifically, the data size of a vertex attribute must be a multiple of 4 bytes. For example, a [VertexAttributeFormat.Float16](/engine/6000.7/script-reference/unityengine/rendering/vertexattributeformat/float16.md) format with dimension `3` is not valid. Additional Resources: [SystemInfo.SupportsVertexAttributeFormat](/engine/6000.7/script-reference/unityengine/systeminfo/supportsvertexattributeformat.md).

```csharp
var mesh = new Mesh();
// specify vertex layout with:
// - floating point positions,
// - half-precision (FP16) normals with two components,
// - low precision (UNorm8) tangents
var layout = new[]
{
    new VertexAttributeDescriptor(VertexAttribute.Position, VertexAttributeFormat.Float32, 3),
    new VertexAttributeDescriptor(VertexAttribute.Normal, VertexAttributeFormat.Float16, 2),
    new VertexAttributeDescriptor(VertexAttribute.Tangent, VertexAttributeFormat.UNorm8, 4),
};
var vertexCount = 10;
mesh.SetVertexBufferParams(vertexCount, layout);
```

A C# struct (for use with [Mesh.SetVertexBufferData](/engine/6000.7/script-reference/unityengine/mesh/setvertexbufferdata.md)) matching this vertex layout could look like this:

```csharp
[System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]
struct ExampleVertex
{
    public Vector3 pos;
    public ushort normalX, normalY;
    public Color32 tangent;
}
```

Additional Resources: [Mesh.SetVertexBufferParams](/engine/6000.7/script-reference/unityengine/mesh/setvertexbufferparams.md), [Mesh.SetVertexBufferData](/engine/6000.7/script-reference/unityengine/mesh/setvertexbufferdata.md), [Mesh.GetVertexAttributes](/engine/6000.7/script-reference/unityengine/mesh/getvertexattributes.md).

## Constructors

| Constructor                                                                                                                                                                                                                       | Description                                                                                                                         |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| [VertexAttributeDescriptor(UnityEngine.Rendering.VertexAttribute,UnityEngine.Rendering.VertexAttributeFormat,System.Int32,System.Int32)](/engine/6000.7/script-reference/unityengine/rendering/vertexattributedescriptor/ctor.md) | Create a [VertexAttributeDescriptor](/engine/6000.7/script-reference/unityengine/rendering/vertexattributedescriptor.md) structure. |

## Properties

| Property                                                                                                  | Description                                            |
| --------------------------------------------------------------------------------------------------------- | ------------------------------------------------------ |
| [attribute](/engine/6000.7/script-reference/unityengine/rendering/vertexattributedescriptor/attribute.md) | The vertex attribute.                                  |
| [dimension](/engine/6000.7/script-reference/unityengine/rendering/vertexattributedescriptor/dimension.md) | Dimensionality of the vertex attribute.                |
| [format](/engine/6000.7/script-reference/unityengine/rendering/vertexattributedescriptor/format.md)       | Format of the vertex attribute.                        |
| [stream](/engine/6000.7/script-reference/unityengine/rendering/vertexattributedescriptor/stream.md)       | Which vertex buffer stream the attribute should be in. |
