Version: Unity 6.0 (6000.0)
言語 : 日本語
レンダーパイプラインの設定
Unity でのレンダリングパス

アクティブなレンダーパイプラインの変更または検出

このページでは、Unity が現在使用しているレンダーパイプラインを取得して設定する方法に関する情報を取り上げます。Unity が現在使用しているレンダーパイプラインをアクティブなレンダーパイプラインと呼びます。

概要

コンテンツを描画するために、Unity は、ビルトインレンダーパイプラインまたは スクリプタブルレンダーパイプライン (SRP) に基づくレンダーパイプラインのどちらかを使用することができます。スクリプタブルレンダーパイプラインには、ユニバーサルレンダーパイプライン (URP) や HD レンダーパイプライン (HDRP) があります。

Unity が使用するスクリプタブルレンダーパイプラインを指定するには、レンダーパイプラインアセットを使用します。レンダーパイプラインアセットで、どの SRP を使用するか、それをどう設定するかを Unity に指定します。レンダーパイプラインアセットを指定しないと、Unity はビルトインレンダーパイプラインを使用します。

同じレンダーパイプラインを使用するが設定が異なる複数のレンダーパイプラインアセットを作成できます。例えば、ハードウェア品質レベルごとに異なるレンダーパイプラインアセットを使用できます。レンダーパイプラインアセットの概要については、スクリプトレンダーパイプラインの概要 を参照してください。URP のレンダーパイプラインアセットについては、ユニバーサルレンダーパイプラインアセット を、HDRP のレンダーパイプラインアセットについては、HD レンダーパイプラインアセット を参照してください。

Unity エディターでまたはランタイムにアクティブなレンダーパイプラインを変更するとすぐに、Unity は新しいアクティブなレンダーパイプラインを使用してコンテンツを描画します。Unity エディターの場合は、これにゲームビュー、シーンビュー、そして Project パネルや Inspector でのマテリアルのプレビューが含まれます。

アクティブなレンダーパイプラインを変更する場合は、プロジェクトのアセットとコードが新しいレンダーパイプラと互換性があることを確認する必要があります。そうでないと、エラーや意図しないビジュアルエフェクトが発生する可能性があります。

アクティブなレンダーパイプラインの決定

Graphics SettingsQuality Settings の両方の設定によって、アクティブなレンダーパイプラインが決まります。Graphics Settings では、Unity がデフォルトで使用するレンダーパイプラインを設定します。Quality Settings では、特定の品質レベルのデフォルトレンダーパイプラインをオーバーライドできます。

デフォルトのレンダーパイプラインを取得または設定するには、Graphics Settings > Scriptable Render Pipeline Setting (またはこれに相当する API、GraphicsSettings.defaultRenderPipeline) を使用します。特定の品質レベルのデフォルトをオーバーライドするレンダーパイプラインを取得または設定するには、Quality Settings > Render Pipeline (またはこれに相当する API、QualitySettings.renderPipeline) を使用します。

Unity はアクティブなレンダーパイプラインを以下のように決定します。

  • Quality Settings の現在のレベルの Render Pipeline がレンダーパイプラインアセットを参照している場合、Unity はその値を使用します。
  • それ以外の場合:
    • Graphics Settings の Scriptable Render Pipeline Setting がレンダーパイプラインアセットを参照している場合、Unity はその値を使用します。
    • それ以外の場合は、Unity はビルトインレンダーパイプラインを使用します。

エディター UI でアクティブなレンダーパイプラインを取得および設定する方法

アクティブなレンダーパイプラインの取得

エディター UI でアクティブなレンダーパイプラインを取得するには、Graphics Settings ウィンドウと Quality Settings ウィンドウの両方を確認する必要があります。これらの値を使用してアクティブなレンダーパイプラインを決定する方法については、アクティブなレンダーパイプラインの決定 を参照してください。

ビルトインレンダーパイプラインのアクティブ化

アクティブなレンダーパイプラインをビルトインレンダーパイプラインに設定するには、 Graphics Settings と Quality Settings からレンダーパイプラインアセットを削除します。

手順は以下のとおりです。

  1. Edit > Project Settings > Quality を選択します。
  2. 各品質レベルで、レンダーパイプラインアセットが Render Pipeline フィールドに割り当てられている場合は、割り当てを解除します。
  3. Edit > Project Settings > Graphics を選択します。
  4. レンダーパイプラインアセットが Scriptable Render Pipeline Setting フィールドに割り当てられている場合は、割り当てを解除します。

URP、HDRP、または SRP に基づくカスタムレンダーパイプラインのアクティブ化

アクティブなレンダーパイプラインを SRP に基づくレンダーパイプラインに設定するには、デフォルトのアクティブなレンダーパイプラインとして使用するレンダーパイプラインアセットと、オプションで各品質レベルに使用するレンダーパイプラインアセットを Unity に指定します。

手順は以下のとおりです。

  1. Project フォルダーで、使用するレンダーパイプラインアセットを見つけます。
  2. 一定の品質レベルに対してオーバーライドがない場合に Unity が使用する、デフォルトのレンダーパイプラインを設定します。これを設定しないと、オーバーライドが適用されないときに Unity はビルトインレンダーパイプラインを使用します。
    1. Edit > Project Settings > Graphics を選択します。
    2. レンダーパイプラインアセットを Scriptable Render Pipeline Setting フィールドにドラッグします。
  3. 任意: オーバーライドレンダーパイプラインアセットをさまざまな品質レベルに設定します。
    1. Edit > Project Settings > Quality を選択します。
    2. レンダーパイプラインアセットを Render Pipeline フィールドにドラッグします。

C# スクリプトでアクティブなレンダーパイプラインを取得および設定する方法

C# スクリプトでは、アクティブなレンダーパイプラインを取得および設定し、アクティブなレンダーパイプラインが変更されたときにコールバックを受け取ることができます。これは、Unity エディターの編集モードや再生モード、またはアプリケーションのランタイムに実行できます。

これを行うには、以下の API を使用します。

以下のサンプルコードは、これらの API の使用方法を示しています。

using UnityEngine;
using UnityEngine.Rendering;
 
public class ActiveRenderPipelineExample : MonoBehaviour
{
    // In the Inspector, assign a Render Pipeline Asset to each of these fields
    public RenderPipelineAsset defaultRenderPipelineAsset;
    public RenderPipelineAsset overrideRenderPipelineAsset;
 
    void Start()
    {
        GraphicsSettings.defaultRenderPipeline = defaultRenderPipelineAsset;
        QualitySettings.renderPipeline = overrideRenderPipelineAsset;

        DisplayCurrentRenderPipeline();
    }

    void Update()
    {
        // When the user presses the left shift key, switch the default render pipeline
        if (Input.GetKeyDown(KeyCode.LeftShift)) {
            SwitchDefaultRenderPipeline();
            DisplayCurrentRenderPipeline();
        }
        // When the user presses the right shift key, switch the override render pipeline
        else if (Input.GetKeyDown(KeyCode.RightShift)) {
            SwitchOverrideRenderPipeline();
            DisplayCurrentRenderPipeline();
        }
    }

    // Switch the default render pipeline between null,
    // and the render pipeline defined in defaultRenderPipelineAsset
    void SwitchDefaultRenderPipeline()
    {
        if (GraphicsSettings.defaultRenderPipeline == defaultRenderPipelineAsset)
        {
            GraphicsSettings.defaultRenderPipeline = null;
        }
        else
        {
            GraphicsSettings.defaultRenderPipeline = defaultRenderPipelineAsset;
        }
    }

    // Switch the override render pipeline between null,
    // and the render pipeline defined in overrideRenderPipelineAsset
    void SwitchOverrideRenderPipeline()
    {
        if (QualitySettings.renderPipeline == overrideRenderPipelineAsset)
        {
            QualitySettings.renderPipeline = null;
        }
        else
        {
           QualitySettings.renderPipeline = overrideRenderPipelineAsset;
        }
    }

    // Print the current render pipeline information to the console
    void DisplayCurrentRenderPipeline()
    {
        // GraphicsSettings.defaultRenderPipeline determines the default render pipeline
        // If it is null, the default is the Built-in Render Pipeline
        if (GraphicsSettings.defaultRenderPipeline != null)
        {
            Debug.Log("The default render pipeline is defined by " + GraphicsSettings.defaultRenderPipeline.name);
        }
        else
        {
            Debug.Log("The default render pipeline is the Built-in Render Pipeline");
        }

        // QualitySettings.renderPipeline determines the override render pipeline for the current quality level
        // If it is null, no override exists for the current quality level
        if (QualitySettings.renderPipeline != null)
        {
            Debug.Log("The override render pipeline for the current quality level is defined by " + QualitySettings.renderPipeline.name);
        }
        else
        {
            Debug.Log("No override render pipeline exists for the current quality level");
        }

        // If an override render pipeline is defined, Unity uses that
        // Otherwise, it falls back to the default value
        if (QualitySettings.renderPipeline != null)
        {
            Debug.Log("The active render pipeline is the override render pipeline");
        }
        else
        {
            Debug.Log("The active render pipeline is the default render pipeline");
        }

        // To get a reference to the Render Pipeline Asset that defines the active render pipeline,
        // without knowing if it is the default or an override, use GraphicsSettings.currentRenderPipeline
        if (GraphicsSettings.currentRenderPipeline != null)
        {
            Debug.Log("The active render pipeline is defined by " +GraphicsSettings.currentRenderPipeline.name);
        }
        else
        {
            Debug.Log("The active render pipeline is the Built-in Render Pipeline");
        }
    }
}
レンダーパイプラインの設定
Unity でのレンダリングパス