Version: Unity 6.5 Alpha (6000.5)
LanguageEnglish
  • C#
Experimental: this API is experimental and might be changed or removed in the future.

GraphicsStateCollection.AddGraphicsStateForVariant

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Declaration

public Boolean AddGraphicsStateForVariant(Shader shader, UnityEngine.Rendering.PassIdentifier passId, UnityEngine.Rendering.LocalKeyword[] keywords, UnityEngine.Experimental.Rendering.GraphicsStateCollection/GraphicsState setup);

Parameters

Parameter Description
shader Shader used in associated variant.
passId PassIdentifier used in associated variant.
keywords LocalKeyword array of keywords used in associated variant.
variant Shader variant that the graphics state should be associated with.
setup GraphicsState to add.

Returns

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

Description

Adds a new graphics state associated with a shader variant.

If the specified shader variant does not yet exist in the collection, then it will be added. Note: WebGPU does not fully support manually adding graphics states, results might be unexpected. Additional resources: GetGraphicsStatesForVariant.

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."); } } }