ドキュメント

Unity Engine


Unity Engine


Introduction to writing shaders in code

Learn about ShaderLab, Surface Shaders, and High Level Shader Language (HLSL), and which languages and approaches to use for each render pipeline.
読み終わるまでの所要時間 3 分最終更新 1ヶ月前

重要
The Built-In Render Pipeline is deprecated and will be made obsolete in a future release.
It remains supported, including bug fixes and maintenance, through the full Unity 6.7 LTS lifecycle.
How you write custom shaders in Unity depends on the render pipeline you use:

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.
注
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.

ShaderLab

ShaderLab is a declarative language that you use in shader source files. It uses a nested-braces syntax to describe a Shader object.
There are many things that you can define in ShaderLab, but the most common are:
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.

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.