Version: 2020.3
Writing shaders
ShaderLab

Writing shaders overview

Languages

When you write shaders for Unity, you use the following languages:

  • A programming language called HLSL. Use this to write the shader programs themselves. For more information on HLSL, see HLSL in Unity.
  • A Unity-specific language called ShaderLab. Use this to define a Shader object, which acts as a container for your shader programs. For more information on ShaderLab, see ShaderLab.

You do not need to use different languages for different platforms; Unity compiles your HLSL and ShaderLab code into different languages for different graphics APIs. For more information, see Shader compilation.

Note: You can also directly write your shader programs in GLSL and Metal if you want. This is not recommended or needed as part of a normal workflow. For more information on using GLSL, see GLSL in Unity.

Different ways of writing shaders

There are different ways of writing shaders:

  • The most common way is to write vertex and fragment shaders in HLSL. For more information, see Writing vertex and fragment shaders.
  • In the Built-in Render Pipeline, you can also write Surface Shaders. They are a simplified way of writing shaders that interact with lighting. For more information, see Surface Shaders.
  • For backwards compatibility reasons, Unity also supports “fixed function style” ShaderLab commands. These let you write shaders in ShaderLab, without using HLSL. This is no longer recommended, but it is documented on the page ShaderLab legacy functionality.

Writing shaders for different graphics APIs

In some cases, you must write your shader code differently depending on the graphics API that you are targeting. For information on this, see Writing shaders for different graphics APIs.

Writing shaders
ShaderLab
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961