Version: Unity 6.5 (6000.5)
LanguageEnglish
  • C#

Utility.ShaderStageToFlags

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 static ShaderStageFlags ShaderStageToFlags(ShaderStage stage);

Parameters

Parameter Description
stage The stage to convert into flags.

Returns

ShaderStageFlags The value from ShaderStageFlags enum that corresponds to the given stage.

Description

Converts a ShaderStage value into a ShaderStageFlags value.

Use this method to convert the given shader stage to use with an API that can work with multiple shader stages simultaneously.

using UnityEngine;
using UnityEngine.Shaders;

/*
    Attach this script to a GameObject and enter Play mode. "Shader stages: Basic, Tessellation" will be printed in the console.
*/

public class ShaderTypes : MonoBehaviour
{
    void Start()
    {
        ShaderStageFlags stages = (ShaderStageFlags.Graphics & (~ShaderStageFlags.Geometry));
        // Iterate over all possible shader stages and check if the only stages enabled are Vertex, Fragment, Hull, and Domain
        // Log a message if a stage is enabled or disabled incorrectly.
        for (ShaderStage stage = ShaderStage.FirstStage; stage < ShaderStage.Count; ++stage)
        {
            bool shouldBeEnabled = stage < ShaderStage.GraphicsStageCount && stage != ShaderStage.Geometry;
            if (Utility.IsShaderStageEnabled(stages, stage) != shouldBeEnabled)
                Debug.Log("Unexpected stage " + stage + (shouldBeEnabled ? " not enabled" : " enabled"));
        }
        Debug.Log("Shader stages: " + stages);
    }
}