# AddVariant

> Adds a new shader variant to the collection.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine.Rendering](/engine/6000.7/script-reference/unityengine/rendering.md)
* **Assembly:** UnityEngine.CoreModule

## AddVariant(Shader, PassIdentifier, LocalKeyword\[])

Adds a new shader variant to the collection.

```csharp
public bool AddVariant(Shader shader, PassIdentifier passId, LocalKeyword[] keywords)
```

### Parameters

**** (\[Shader]\(/engine/6000.7/script-reference/unityengine/shader)): Shader used in the variant.**** (\[PassIdentifier]\(/engine/6000.7/script-reference/unityengine/rendering/passidentifier)): PassIdentifier used in the variant.**** (\[LocalKeyword\[]]\(/engine/6000.7/script-reference/unityengine/rendering/localkeyword)): [LocalKeyword](/engine/6000.7/script-reference/unityengine/rendering/localkeyword.md) array of keywords used in the variant.

### Returns

| Type                                                          | Description                                       |
| ------------------------------------------------------------- | ------------------------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | True if a new variant was added, false otherwise. |

### Remarks

If only the `material` is provided, then the generated [ShaderVariantCollection.ShaderVariant](/engine/6000.7/script-reference/unityengine/shadervariantcollection/shadervariant.md) will use the set of [Material.enabledKeywords](/engine/6000.7/script-reference/unityengine/material/enabledkeywords.md) combined with the global shader keywords that are **currently enabled** in the active context, unless explicitly provided via `globalKeywords`.

Additional Resources: [GraphicsStateCollection.AddVariants](/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/addvariants.md), [GraphicsStateCollection.RemoveVariant](/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/removevariant.md), [GraphicsStateCollection.ContainsVariant](/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/containsvariant.md).

## AddVariant(Material, PassIdentifier)

Adds a new shader variant to the collection.

```csharp
public bool AddVariant(Material mat, PassIdentifier passId)
```

### Parameters

**** (\[Material]\(/engine/6000.7/script-reference/unityengine/material)): **** (\[PassIdentifier]\(/engine/6000.7/script-reference/unityengine/rendering/passidentifier)): PassIdentifier used in the variant.

### Returns

| Type                                                          | Description                                       |
| ------------------------------------------------------------- | ------------------------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | True if a new variant was added, false otherwise. |

### Remarks

If only the `material` is provided, then the generated [ShaderVariantCollection.ShaderVariant](/engine/6000.7/script-reference/unityengine/shadervariantcollection/shadervariant.md) will use the set of [Material.enabledKeywords](/engine/6000.7/script-reference/unityengine/material/enabledkeywords.md) combined with the global shader keywords that are **currently enabled** in the active context, unless explicitly provided via `globalKeywords`.

Additional Resources: [GraphicsStateCollection.AddVariants](/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/addvariants.md), [GraphicsStateCollection.RemoveVariant](/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/removevariant.md), [GraphicsStateCollection.ContainsVariant](/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/containsvariant.md).

## AddVariant(Material, PassIdentifier, GlobalKeyword\[])

Adds a new shader variant to the collection.

```csharp
public bool AddVariant(Material mat, PassIdentifier passId, GlobalKeyword[] globalKeywords)
```

### Parameters

**** (\[Material]\(/engine/6000.7/script-reference/unityengine/material)): **** (\[PassIdentifier]\(/engine/6000.7/script-reference/unityengine/rendering/passidentifier)): PassIdentifier used in the variant.**** (\[GlobalKeyword\[]]\(/engine/6000.7/script-reference/unityengine/rendering/globalkeyword)): [GlobalKeyword](/engine/6000.7/script-reference/unityengine/rendering/globalkeyword.md) array of global keywords to use with the material's enabled keywords in the variant.

### Returns

| Type                                                          | Description                                       |
| ------------------------------------------------------------- | ------------------------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | True if a new variant was added, false otherwise. |

### Remarks

If only the `material` is provided, then the generated [ShaderVariantCollection.ShaderVariant](/engine/6000.7/script-reference/unityengine/shadervariantcollection/shadervariant.md) will use the set of [Material.enabledKeywords](/engine/6000.7/script-reference/unityengine/material/enabledkeywords.md) combined with the global shader keywords that are **currently enabled** in the active context, unless explicitly provided via `globalKeywords`.

Additional Resources: [GraphicsStateCollection.AddVariants](/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/addvariants.md), [GraphicsStateCollection.RemoveVariant](/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/removevariant.md), [GraphicsStateCollection.ContainsVariant](/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/containsvariant.md).
