Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


AddGraphicsStateForVariant

Adds a new graphics state associated with a shader variant.
Read time 2 minutesLast updated 12 days ago

Definition

AddGraphicsStateForVariant(Shader, PassIdentifier, LocalKeyword[], GraphicsState)

Adds a new graphics state associated with a shader variant.
public bool AddGraphicsStateForVariant(Shader shader, PassIdentifier passId, LocalKeyword[] keywords, GraphicsStateCollection.GraphicsState setup)

Parameters

shader

Shader used in associated variant.

PassIdentifier used in associated variant.

LocalKeyword array of keywords used in associated variant.

GraphicsState to add.

Returns

Type

Description

boolReturns true if a new graphics state was added to the collection, false otherwise.

Remarks

If the specified shader variant does not yet exist in the collection, then it will be added.

Examples

using System.Collections.Generic;using UnityEngine;using UnityEngine.Experimental.Rendering;public class AddGraphicsStateExample : MonoBehaviour{ public GraphicsStateCollection graphicsStateCollection; public GraphicsStateCollection.ShaderVariant variant; void Start() { if (graphicsStateCollection.ContainsVariant(variant.shader, variant.passId, variant.keywords)) { List<GraphicsStateCollection.GraphicsState> states = new List<GraphicsStateCollection.GraphicsState>(); graphicsStateCollection.GetGraphicsStatesForVariant(variant, states); foreach (var state in states) { // Add a new modified version of each existing state for this variant GraphicsStateCollection.GraphicsState newState = state; newState.wireframe = true; graphicsStateCollection.AddGraphicsStateForVariant(variant, newState); } } else { Debug.Log("variant was not found in graphicsStateCollection! No graphics states were added."); } }}

AddGraphicsStateForVariant(ShaderVariant, GraphicsState)

Adds a new graphics state associated with a shader variant.
public bool AddGraphicsStateForVariant(GraphicsStateCollection.ShaderVariant variant, GraphicsStateCollection.GraphicsState setup)

Parameters

Shader variant that the graphics state should be associated with.

GraphicsState to add.

Returns

Type

Description

boolReturns true if a new graphics state was added to the collection, false otherwise.

Remarks

If the specified shader variant does not yet exist in the collection, then it will be added.

Examples

using System.Collections.Generic;using UnityEngine;using UnityEngine.Experimental.Rendering;public class AddGraphicsStateExample : MonoBehaviour{ public GraphicsStateCollection graphicsStateCollection; public GraphicsStateCollection.ShaderVariant variant; void Start() { if (graphicsStateCollection.ContainsVariant(variant.shader, variant.passId, variant.keywords)) { List<GraphicsStateCollection.GraphicsState> states = new List<GraphicsStateCollection.GraphicsState>(); graphicsStateCollection.GetGraphicsStatesForVariant(variant, states); foreach (var state in states) { // Add a new modified version of each existing state for this variant GraphicsStateCollection.GraphicsState newState = state; newState.wireframe = true; graphicsStateCollection.AddGraphicsStateForVariant(variant, newState); } } else { Debug.Log("variant was not found in graphicsStateCollection! No graphics states were added."); } }}