Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


AddVariants

Adds one or more new shader variants to the collection.
Read time 2 minutesLast updated 4 days ago

Definition

AddVariants(Material, int)

Adds one or more new shader variants to the collection.
public bool AddVariants(Material mat, int subshaderIndex = -1)

Parameters


subshaderIndex

The index of the subshader within the shader used in the variant.

Returns

Type

Description

boolTrue if at least one new variant was added, false otherwise.

Remarks

If
subshaderIndex
is not specified, then one ShaderVariantCollection.ShaderVariant will attempt to be added for each shader pass in every SubShader of the
material
parameter's Shader. Otherwise, at most Shader.GetPassCountInSubshader number of variants will be added using the specified
subshaderIndex
.
All generated shader variants will use the set of Material.enabledKeywords combined with the global shader keywords that are currently enabled in the active context, unless explicitly provided via
globalKeywords
.

AddVariants(Material, GlobalKeyword[], int)

Adds one or more new shader variants to the collection.
public bool AddVariants(Material mat, GlobalKeyword[] globalKeywords, int subshaderIndex = -1)

Parameters


globalKeywords

GlobalKeyword array of global keywords to use with the material's enabled keywords in the variants.

subshaderIndex

The index of the subshader within the shader used in the variant.

Returns

Type

Description

boolTrue if at least one new variant was added, false otherwise.

Remarks

If
subshaderIndex
is not specified, then one ShaderVariantCollection.ShaderVariant will attempt to be added for each shader pass in every SubShader of the
material
parameter's Shader. Otherwise, at most Shader.GetPassCountInSubshader number of variants will be added using the specified
subshaderIndex
.
All generated shader variants will use the set of Material.enabledKeywords combined with the global shader keywords that are currently enabled in the active context, unless explicitly provided via
globalKeywords
.