# ShaderUtil

> Utility methods to assist with working with shaders from the Editor.

## Definition

* **Type:** Class
* **Namespace:** [UnityEditor](/engine/6000.6/script-reference/unityeditor.md)
* **Assembly:** UnityEditor.CoreModule

```csharp
public sealed class ShaderUtil
```

## Remarks

This class contains methods you can use to do the following:

* Manage shader compilation. Refer to [ShaderUtil.CompilePass](/engine/6000.6/script-reference/unityeditor/shaderutil/compilepass.md).
* Create shader assets. Refer to [ShaderUtil.CreateShaderAsset](/engine/6000.6/script-reference/unityeditor/shaderutil/createshaderasset.md).
* Access common shader information. Refer to [ShaderUtil.GetShaderData](/engine/6000.6/script-reference/unityeditor/shaderutil/getshaderdata.md).

Additional Resources: [Shader](/engine/6000.6/script-reference/unityengine/shader.md), [ComputeShader](/engine/6000.6/script-reference/unityengine/computeshader.md), [RayTracingShader](/engine/6000.6/script-reference/unityengine/rendering/raytracingshader.md), [ShaderData](/engine/6000.6/script-reference/unityeditor/shaderdata.md).

## Examples

```csharp
using UnityEditor;
using UnityEngine;
using UnityEngine.Rendering;

// Adds a new Editor menu item called Example. Select a shader
// asset in the Project window, then select
// Example > PrintLightModeTagExample from the Editor menu. The value of all
// "LightMode" tags present in any pass of the shader will be printed to
// the console.
public class PrintLightModeTagExample
{
    [MenuItem("Example/PrintLightModeTagExample")]
    static void MenuCallback()
    {
        // If the selected object is a shader...
        if (Selection.activeObject is Shader selectedShader)
        {
            // For each subshader...
            ShaderData selectedShaderData = ShaderUtil.GetShaderData(selectedShader);
            for (int subShaderIndex = 0; subShaderIndex < selectedShaderData.SubshaderCount; ++subShaderIndex)
            {
                // For each pass...
                ShaderData.Subshader subShaderData = selectedShaderData.GetSubshader(subShaderIndex);
                for (int passIndex = 0; passIndex < subShaderData.PassCount; ++passIndex)
                {
                    ShaderData.Pass passData = subShaderData.GetPass(passIndex);

                    // If the pass has a "LightMode" tag, print its value
                    ShaderTagId lightModeValue = passData.FindTagValue(new ShaderTagId("LightMode"));
                    if (lightModeValue != ShaderTagId.none)
                    {
                        Debug.Log($"Pass '{passData.Name}' in SubShader {subShaderIndex} of "
                            + $"Shader '{selectedShader.name}' has LightMode '{lightModeValue.name}'.");
                    }
                }
            }
        }
    }
}
```

## Static Properties

| Property                                                                                                                         | Description                                                                           |
| -------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- |
| [allowAsyncCompilation](/engine/6000.6/script-reference/unityeditor/shaderutil/allowasynccompilation.md)                         | When true, asynchronous Shader compilation is allowed at the current call site.       |
| [anythingCompiling](/engine/6000.6/script-reference/unityeditor/shaderutil/anythingcompiling.md)                                 | When true, the Editor is compiling some Shaders asynchronously at the point of query. |
| [disableShaderOptimization](/engine/6000.6/script-reference/unityeditor/shaderutil/disableshaderoptimization.md)                 | Disables shader optimization in the Editor.                                           |
| [hardwareSupportsRectRenderTexture](/engine/6000.6/script-reference/unityeditor/shaderutil/hardwaresupportsrectrendertexture.md) | Does the current hardware support render textues.                                     |

## Static Methods

| Method                                                                                                                                       | Description                                                                                                                                                                                                                                                                                                                                                           |
| -------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [ClearCachedData](/engine/6000.6/script-reference/unityeditor/shaderutil/clearcacheddata.md)                                                 | Clears all internally-cached data that was generated for the given shader, such as errors and compilation info.                                                                                                                                                                                                                                                       |
| [ClearShaderMessages](/engine/6000.6/script-reference/unityeditor/shaderutil/clearshadermessages.md)                                         | Clear compile time messages for the given shader.                                                                                                                                                                                                                                                                                                                     |
| [CompilePass](/engine/6000.6/script-reference/unityeditor/shaderutil/compilepass.md)                                                         | Request the Editor to compile the Shader Variant needed for the specific pass of the given Material.                                                                                                                                                                                                                                                                  |
| [CreateComputeShaderAsset](/engine/6000.6/script-reference/unityeditor/shaderutil/createcomputeshaderasset.md)                               | Creates a new [ComputeShader](/engine/6000.6/script-reference/unityengine/computeshader.md) object from the provided source code string. You can use this method alongside the [ScriptedImporter](/engine/6000.6/script-reference/unityeditor/assetimporters/scriptedimporter.md) to create custom compute shader generation tools in the Editor.                     |
| [CreateRayTracingShaderAsset](/engine/6000.6/script-reference/unityeditor/shaderutil/createraytracingshaderasset.md)                         | Creates a new [RayTracingShader](/engine/6000.6/script-reference/unityengine/rendering/raytracingshader.md) object from the provided source code string. You can use this method alongside the [ScriptedImporter](/engine/6000.6/script-reference/unityeditor/assetimporters/scriptedimporter.md) to create custom ray tracing shader generation tools in the Editor. |
| [CreateShaderAsset](/engine/6000.6/script-reference/unityeditor/shaderutil/createshaderasset.md)                                             | Creates a new [Shader](/engine/6000.6/script-reference/unityengine/shader.md) object from the provided source code string. You can use this method alongside the [ScriptedImporter](/engine/6000.6/script-reference/unityeditor/assetimporters/scriptedimporter.md) to create custom shader generation tools in the Editor.                                           |
| [GetAllShaderInfo](/engine/6000.6/script-reference/unityeditor/shaderutil/getallshaderinfo.md)                                               | Returns an array of [ShaderInfo](/engine/6000.6/script-reference/unityeditor/shaderinfo.md) of all available shaders. That includes built-in shaders.                                                                                                                                                                                                                 |
| [GetAnyHitShaderName](/engine/6000.6/script-reference/unityeditor/shaderutil/getanyhitshadername.md)                                         | Returns the name of a user-defined any hit shader from within a [RayTracingShader](/engine/6000.6/script-reference/unityengine/rendering/raytracingshader.md).                                                                                                                                                                                                        |
| [GetAnyHitShaderRayPayloadSize](/engine/6000.6/script-reference/unityeditor/shaderutil/getanyhitshaderraypayloadsize.md)                     | Returns the ray payload size of a user-defined any hit shader from within a [RayTracingShader](/engine/6000.6/script-reference/unityengine/rendering/raytracingshader.md).                                                                                                                                                                                            |
| [GetCallableShaderCount](/engine/6000.6/script-reference/unityeditor/shaderutil/getcallableshadercount.md)                                   | Returns the number of callable shaders defined whitin a given [RayTracingShader](/engine/6000.6/script-reference/unityengine/rendering/raytracingshader.md).                                                                                                                                                                                                          |
| [GetCallableShaderName](/engine/6000.6/script-reference/unityeditor/shaderutil/getcallableshadername.md)                                     | Returns the name of a user-defined callable Shader from within a [RayTracingShader](/engine/6000.6/script-reference/unityengine/rendering/raytracingshader.md).                                                                                                                                                                                                       |
| [GetCallableShaderParamSize](/engine/6000.6/script-reference/unityeditor/shaderutil/getcallableshaderparamsize.md)                           | Returns the parameter size of a user-defined callable shader from within a [RayTracingShader](/engine/6000.6/script-reference/unityengine/rendering/raytracingshader.md).                                                                                                                                                                                             |
| [GetClosestHitShaderName](/engine/6000.6/script-reference/unityeditor/shaderutil/getclosesthitshadername.md)                                 | Returns the name of a user-defined closest hit shader from within a [RayTracingShader](/engine/6000.6/script-reference/unityengine/rendering/raytracingshader.md).                                                                                                                                                                                                    |
| [GetClosestHitShaderRayPayloadSize](/engine/6000.6/script-reference/unityeditor/shaderutil/getclosesthitshaderraypayloadsize.md)             | Returns the ray payload size of a user-defined closest hit shader from within a [RayTracingShader](/engine/6000.6/script-reference/unityengine/rendering/raytracingshader.md).                                                                                                                                                                                        |
| [GetComputeShaderMessageCount](/engine/6000.6/script-reference/unityeditor/shaderutil/getcomputeshadermessagecount.md)                       | Returns the number of errors and warnings generated by the Unity Shader Compiler for the given [ComputeShader](/engine/6000.6/script-reference/unityengine/computeshader.md).                                                                                                                                                                                         |
| [GetComputeShaderMessages](/engine/6000.6/script-reference/unityeditor/shaderutil/getcomputeshadermessages.md)                               | Returns each error and warning generated by the Unity Shader Compiler for the given [ComputeShader](/engine/6000.6/script-reference/unityengine/computeshader.md).                                                                                                                                                                                                    |
| [GetCurrentCustomEditor](/engine/6000.6/script-reference/unityeditor/shaderutil/getcurrentcustomeditor.md)                                   | Gets the current custom editor for the shader you pass in.                                                                                                                                                                                                                                                                                                            |
| [GetCustomEditorForRenderPipeline](/engine/6000.6/script-reference/unityeditor/shaderutil/getcustomeditorforrenderpipeline.md)               | Gets the shader's custom editor class name for a specific render pipeline asset type.                                                                                                                                                                                                                                                                                 |
| [GetIntersectionShaderName](/engine/6000.6/script-reference/unityeditor/shaderutil/getintersectionshadername.md)                             | Returns the name of a user-defined intersection shader from within a [RayTracingShader](/engine/6000.6/script-reference/unityengine/rendering/raytracingshader.md).                                                                                                                                                                                                   |
| [GetMissShaderCount](/engine/6000.6/script-reference/unityeditor/shaderutil/getmissshadercount.md)                                           | Returns the number of miss Shaders defined whitin a given [RayTracingShader](/engine/6000.6/script-reference/unityengine/rendering/raytracingshader.md).                                                                                                                                                                                                              |
| [GetMissShaderName](/engine/6000.6/script-reference/unityeditor/shaderutil/getmissshadername.md)                                             | Returns the name of a user-defined miss Shader from within a [RayTracingShader](/engine/6000.6/script-reference/unityengine/rendering/raytracingshader.md).                                                                                                                                                                                                           |
| [GetMissShaderRayPayloadSize](/engine/6000.6/script-reference/unityeditor/shaderutil/getmissshaderraypayloadsize.md)                         | Returns the ray payload size of a user-defined miss Shader from within a [RayTracingShader](/engine/6000.6/script-reference/unityengine/rendering/raytracingshader.md).                                                                                                                                                                                               |
| [GetPassKeywords](/engine/6000.6/script-reference/unityeditor/shaderutil/getpasskeywords.md)                                                 | Gets the local shader keywords that are valid for a Pass within a particular shader.                                                                                                                                                                                                                                                                                  |
| [GetRayGenerationShaderCount](/engine/6000.6/script-reference/unityeditor/shaderutil/getraygenerationshadercount.md)                         | Returns the number of ray generation Shaders defined whitin a given [RayTracingShader](/engine/6000.6/script-reference/unityengine/rendering/raytracingshader.md).                                                                                                                                                                                                    |
| [GetRayGenerationShaderName](/engine/6000.6/script-reference/unityeditor/shaderutil/getraygenerationshadername.md)                           | Returns the name of a user-defined ray generation Shader from within a [RayTracingShader](/engine/6000.6/script-reference/unityengine/rendering/raytracingshader.md).                                                                                                                                                                                                 |
| [GetRayTracingShaderMessageCount](/engine/6000.6/script-reference/unityeditor/shaderutil/getraytracingshadermessagecount.md)                 | Returns the number of errors and warnings generated by the Shader Compiler for the given [RayTracingShader](/engine/6000.6/script-reference/unityengine/rendering/raytracingshader.md).                                                                                                                                                                               |
| [GetRayTracingShaderMessages](/engine/6000.6/script-reference/unityeditor/shaderutil/getraytracingshadermessages.md)                         | Returns each error and warning generated by the Shader Compiler for the given [RayTracingShader](/engine/6000.6/script-reference/unityengine/rendering/raytracingshader.md).                                                                                                                                                                                          |
| [GetShaderData](/engine/6000.6/script-reference/unityeditor/shaderutil/getshaderdata.md)                                                     | Get the shader data for a specific shader.                                                                                                                                                                                                                                                                                                                            |
| [GetShaderInfo](/engine/6000.6/script-reference/unityeditor/shaderutil/getshaderinfo.md)                                                     | Gets [ShaderInfo](/engine/6000.6/script-reference/unityeditor/shaderinfo.md) for the given shader.                                                                                                                                                                                                                                                                    |
| [GetShaderMessageCount](/engine/6000.6/script-reference/unityeditor/shaderutil/getshadermessagecount.md)                                     | Returns the number of errors and warnings generated by the Unity Shader Compiler for the given [Shader](/engine/6000.6/script-reference/unityengine/shader.md).                                                                                                                                                                                                       |
| [GetShaderMessages](/engine/6000.6/script-reference/unityeditor/shaderutil/getshadermessages.md)                                             | Returns each error and warning generated by the Unity Shader Compiler for the given [Shader](/engine/6000.6/script-reference/unityengine/shader.md).                                                                                                                                                                                                                  |
| [GetShaderPlatformKeywordsForBuildTarget](/engine/6000.6/script-reference/unityeditor/shaderutil/getshaderplatformkeywordsforbuildtarget.md) | Gets the platform keywords for a shader, given a shader compiler platform, build target, and optional graphics tier. These platform keywords are necessary to properly compile a shader for a given target.                                                                                                                                                           |
| [HasProceduralInstancing](/engine/6000.6/script-reference/unityeditor/shaderutil/hasproceduralinstancing.md)                                 | Determines whether the specified Shader contains a valid Procedural Instancing variant.                                                                                                                                                                                                                                                                               |
| [IsGraphicsAPISupported](/engine/6000.6/script-reference/unityeditor/shaderutil/isgraphicsapisupported.md)                                   | Checks whether the given compute shader supports the provided graphics API.                                                                                                                                                                                                                                                                                           |
| [IsPassCompiled](/engine/6000.6/script-reference/unityeditor/shaderutil/ispasscompiled.md)                                                   | Checks if the Shader variant for the given pass in the Material has already been compiled.                                                                                                                                                                                                                                                                            |
| [PassHasKeyword](/engine/6000.6/script-reference/unityeditor/shaderutil/passhaskeyword.md)                                                   | Checks whether a local shader keyword is valid for a Pass within a particular shader.                                                                                                                                                                                                                                                                                 |
| [RegisterShader](/engine/6000.6/script-reference/unityeditor/shaderutil/registershader.md)                                                   | Register a user created shader.                                                                                                                                                                                                                                                                                                                                       |
| [RestoreAsyncCompilation](/engine/6000.6/script-reference/unityeditor/shaderutil/restoreasynccompilation.md)                                 | Restores the previous Shader compilation mode in this CommandBuffer scope.                                                                                                                                                                                                                                                                                            |
| [SetAsyncCompilation](/engine/6000.6/script-reference/unityeditor/shaderutil/setasynccompilation.md)                                         | Adds shader compilation mode command in the CommandBuffer.                                                                                                                                                                                                                                                                                                            |
| [ShaderHasError](/engine/6000.6/script-reference/unityeditor/shaderutil/shaderhaserror.md)                                                   | Checks if a shader has any compilation errors. Ignores warnings.                                                                                                                                                                                                                                                                                                      |
| [ShaderHasWarnings](/engine/6000.6/script-reference/unityeditor/shaderutil/shaderhaswarnings.md)                                             | Checks if a shader has any compilation warnings. Ignores errors.                                                                                                                                                                                                                                                                                                      |
| [UpdateShaderAsset](/engine/6000.6/script-reference/unityeditor/shaderutil/updateshaderasset.md)                                             | Replaces the existing source code in the specified shader with the source code in the supplied string.                                                                                                                                                                                                                                                                |
