Version: 2022.3
言語: 日本語
レンダーパイプラインの機能の比較
レンダーパイプラインとライティングソリューションの選択と設定

アクティブなレンダーパイプラインの取得と設定の方法

このページには、Unity が現在使用しているレンダーパイプラインの取得と設定の方法についての情報を掲載しています。Unity が現在使用しているレンダーパイプラインは、アクティブレンダーパイプラインと呼ばれます。

概要

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

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

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

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

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

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

アクティブなレンダーパイプラインは、Graphics 設定 (グラフィックス設定) と Quality 設定 (品質設定) の両方を使用して決定されます。Graphics 設定では、Unity がデフォルトで使用するレンダーパイプラインを設定できます。Quality 設定では、デフォルトのレンダーパイプラインを品質レベルごとにオーバーライドできます。

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

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

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

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

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

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

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

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

これは以下の手順で行えます。

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

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

SRP ベースのレンダーパイプラインをアクティブなレンダーパイプラインとして設定するには、デフォルトのアクティブなレンダーパイプラインとして使用するレンダーパイプラインアセットと、(任意で) 各品質レベルで使用するレンダーパイプラインアセットを指定します。

これは以下の手順で行えます。

  1. Project フォルダー内で、使用したいレンダーパイプラインアセットを見つけます。
  2. デフォルトのレンダーパイプラインを設定します。Unity は、各品質レベルで、オーバーライドがない場合にこれを使用します。これを設定しない場合、Unity は、(オーバーライドがなければ) ビルトインレンダーパイプラインを使用します。
    1. Edit > Project Settings > Graphics を選択します。
    2. Scriptable Render Pipeline Setting フィールドにレンダーパイプラインアセットをドラッグします。
  3. 任意: 個々の品質レベルのレンダーパイプラインアセットのオーバーライドを設定します。
    1. Edit > Project Settings > Quality を選択します。
    2. Render Pipeline Asset フィールドにレンダーパイプラインアセットをドラッグします。

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");
        }
    }
}
レンダーパイプラインの機能の比較
レンダーパイプラインとライティングソリューションの選択と設定