Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


ShaderStage

Represents individual GPU shader stages.
Read time 2 minutesLast updated 5 days ago

Definition

public enum ShaderStage

Remarks

This enum is used in various APIs that need to specify a single GPU shader stage. APIs that allow specifying multiple shader stages simultaneously use the ShaderStageFlags enum instead.
The traditional graphics shader stages used in rasterization are represented by the following enum values:
The compute shader stage and the ray tracing shader stage are represented as ShaderStage.Compute and ShaderStage.RayTracing, respectively.
You can also use ShaderStage.FirstStage, ShaderStage.GraphicsStageCount, and ShaderStage.Count to iterate over shader stages.
Use IsShaderStageEnabled to check if the ShaderStageFlags value has the given stage enabled. Use Utility.ShaderStageToFlags to convert an individual shader stage to ShaderStageFlags.
Additional Resources: ShaderStageFlags, Utility.

Examples

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

Fields

Value

Description

ComputeRepresents the compute shader stage.
CountRepresents the total number of shader stages recognized by Unity.
DomainRepresents the domain shader stage.
FirstStageRepresents the first shader stage for iteration.
FragmentRepresents the fragment shader stage.
GeometryRepresents the geometry shader stage.
GraphicsStageCountRepresents the number of shader stages in rasterization graphics.
HullRepresents the hull shader stage.
RayTracingRepresents the raytracing shader stage.
VertexRepresents the vertex shader stage.