Unity - Scripting API: ShaderUtil
class in UnityEditor
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.
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.
Description
Utility methods to assist with working with shaders from the Editor.
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 Methods
| Method | Description |
|---|---|
| ClearCachedData | Clears all internally-cached data that was generated for the given shader, such as errors and compilation info. |
| ClearShaderMessages | Clear compile time messages for the given shader. |
| CompilePass | Request the Editor to compile the Shader Variant needed for the specific pass of the given Material. |
| CreateComputeShaderAsset | Creates a new ComputeShader object from the provided source code string. You can use this method alongside the ScriptedImporter to create custom compute shader generation tools in the Editor. |
| CreateRayTracingShaderAsset | Creates a new RayTracingShader object from the provided source code string. You can use this method alongside the ScriptedImporter to create custom ray tracing shader generation tools in the Editor. |
| CreateShaderAsset | Creates a new Shader object from the provided source code string. You can use this method alongside the ScriptedImporter to create custom shader generation tools in the Editor. |
| GetAllShaderInfo | Returns an array of ShaderInfo of all available shaders. That includes built-in shaders. |
| GetAnyHitShaderName | Returns the name of a user-defined any hit shader from within a RayTracingShader. |
| GetAnyHitShaderRayPayloadSize | Returns the ray payload size of a user-defined any hit shader from within a RayTracingShader. |
| GetCallableShaderCount | Returns the number of callable shaders defined whitin a given RayTracingShader. |
| GetCallableShaderName | Returns the name of a user-defined callable Shader from within a RayTracingShader. |
| GetCallableShaderParamSize | Returns the parameter size of a user-defined callable shader from within a RayTracingShader. |
| GetClosestHitShaderName | Returns the name of a user-defined closest hit shader from within a RayTracingShader. |
| GetClosestHitShaderRayPayloadSize | Returns the ray payload size of a user-defined closest hit shader from within a RayTracingShader. |
| GetComputeShaderMessageCount | Returns the number of errors and warnings generated by the Unity Shader Compiler for the given ComputeShader. |
| GetComputeShaderMessages | Returns each error and warning generated by the Unity Shader Compiler for the given ComputeShader. |
| GetCurrentCustomEditor | Gets the current custom editor for the shader you pass in.Depending on the render pipeline asset assigned in your Graphics Settings, the custom editor can change if the shader has a different custom editor for one or multiple render pipeline assets. |
| GetCustomEditorForRenderPipeline | Gets the shader's custom editor class name for a specific render pipeline asset type. |
| GetIntersectionShaderName | Returns the name of a user-defined intersection shader from within a RayTracingShader. |
| GetMissShaderCount | Returns the number of miss Shaders defined whitin a given RayTracingShader. |
| GetMissShaderName | Returns the name of a user-defined miss Shader from within a RayTracingShader. |
| GetMissShaderRayPayloadSize | Returns the ray payload size of a user-defined miss Shader from within a RayTracingShader. |
| GetPassKeywords | Gets the local shader keywords that are valid for a Pass within a particular shader. |
| GetRayGenerationShaderCount | Returns the number of ray generation Shaders defined whitin a given RayTracingShader. |
| GetRayGenerationShaderName | Returns the name of a user-defined ray generation Shader from within a RayTracingShader. |
| GetRayTracingShaderMessageCount | Returns the number of errors and warnings generated by the Shader Compiler for the given RayTracingShader. |
| GetRayTracingShaderMessages | Returns each error and warning generated by the Shader Compiler for the given RayTracingShader. |
| GetShaderData | Get the shader data for a specific shader. |
| GetShaderInfo | Gets ShaderInfo for the given shader. |
| GetShaderMessageCount | Returns the number of errors and warnings generated by the Unity Shader Compiler for the given Shader. |
| GetShaderMessages | Returns each error and warning generated by the Unity Shader Compiler for the given Shader. |
| GetShaderPlatformKeywordsForBuildTarget | 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 | Determines whether the specified Shader contains a valid Procedural Instancing variant. |
| IsGraphicsAPISupported | Checks whether the given shader pass supports the provided graphics API. |
| IsPassCompiled | Checks if the Shader variant for the given pass in the Material has already been compiled. |
| PassHasKeyword | Checks whether a local shader keyword is valid for a Pass within a particular shader. |
| RegisterShader | Register a user created shader. |
| RestoreAsyncCompilation | Restores the previous Shader compilation mode in this CommandBuffer scope. |
| SetAsyncCompilation | Adds shader compilation mode command in the CommandBuffer. |
| ShaderHasError | Checks if a shader has any compilation errors. Ignores warnings. |
| ShaderHasWarnings | Checks if a shader has any compilation warnings. Ignores errors. |
| UpdateShaderAsset | Replaces the existing source code in the specified shader with the source code in the supplied string. |