ShaderLab でシェーダーオブジェクトを定義するには、Shader
ブロックを使用します。このページでは、Shader
ブロックの使用に関する情報を掲載しています。
シェーダーオブジェクトの仕組みや、シェーダーオブジェクト、サブシェーダー、パスの関係については、シェーダーオブジェクトの基礎 を参照してください。
シェーダーオブジェクトは Unity 固有の概念で、シェーダープログラムやその他の情報のラッパーです。同一ファイル内に複数のシェーダープログラムを定義し、それらをどのように使用するかを Unity に伝えることができます。
シェーダーオブジェクトはネスト構造になっており、サブシェーダーやパスと呼ばれる構造に情報を整理します。
機能名 | ビルトインレンダーパイプライン | ユニバーサルレンダーパイプライン (URP) | HD レンダーパイプライン (HDRP) | カスタム SRP |
---|---|---|---|---|
ShaderLab: シェーダーブロック | 可 | 可 | 可 | 可 |
Shader
ブロック内で、以下を行うことができます。
Properties
ブロックを使って、マテリアルのプロパティを定義します。ShaderLab: マテリアルプロパティの定義 を参照してください。SubShader
ブロックを使用して、1 つまたは複数のサブシェーダーを定義します。ShaderLab: SubShader の定義 を参照してください。Fallback
ブロックを使用して、フォールバックのシェーダーオブジェクトを割り当てます。ShaderLab: フォールバックの割り当て を参照してください。署名 | 機能 |
---|---|
Shader "<name>" { <optional: Material properties> <One or more SubShader definitions> <optional: custom editor> <optional: fallback> }
|
指定された名前のシェーダーオブジェクトを定義します。 |
このサンプルコードは、シェーダーオブジェクトの基本的な構文と構造を示しています。この例のシェーダーオブジェクトは、1 つのパスを含む 1 つの SubShader を持っています。そのシェーダーオブジェクトは、Material プロパティ、CustomEditor、Fallbackを定義します。
Shader "Examples/ShaderSyntax"
{
CustomEditor = "ExampleCustomEditor"
Properties
{
// Material プロパティの宣言はここに記述
}
SubShader
{
// 残りの SubShader の定義はここに記述
Pass
{
// Pass 定義のコードはここに記述
}
}
Fallback "ExampleFallbackShader"
}
異なるレンダーパイプラインに対応するカスタムシェーダーの例については、カスタムシェーダーの例 を参照してください。
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.