このページでは、Unity が現在使用しているレンダーパイプラインを取得して設定する方法に関する情報を取り上げます。Unity が現在使用しているレンダーパイプラインをアクティブなレンダーパイプラインと呼びます。
コンテンツを描画するために、Unity は、ビルトインレンダーパイプラインまたは スクリプタブルレンダーパイプライン (SRP) に基づくレンダーパイプラインのどちらかを使用することができます。スクリプタブルレンダーパイプラインには、ユニバーサルレンダーパイプライン (URP) や HD レンダーパイプライン (HDRP) があります。
Unity が使用するスクリプタブルレンダーパイプラインを指定するには、レンダーパイプラインアセットを使用します。レンダーパイプラインアセットで、どの SRP を使用するか、それをどう設定するかを Unity に指定します。レンダーパイプラインアセットを指定しないと、Unity はビルトインレンダーパイプラインを使用します。
同じレンダーパイプラインを使用するが設定が異なる複数のレンダーパイプラインアセットを作成できます。例えば、ハードウェア品質レベルごとに異なるレンダーパイプラインアセットを使用できます。レンダーパイプラインアセットの概要については、スクリプトレンダーパイプラインの概要 を参照してください。URP のレンダーパイプラインアセットについては、ユニバーサルレンダーパイプラインアセット を、HDRP のレンダーパイプラインアセットについては、HD レンダーパイプラインアセット を参照してください。
Unity エディターでまたはランタイムにアクティブなレンダーパイプラインを変更するとすぐに、Unity は新しいアクティブなレンダーパイプラインを使用してコンテンツを描画します。Unity エディターの場合は、これにゲームビュー、シーンビュー、そして Project パネルや Inspector でのマテリアルのプレビューが含まれます。
アクティブなレンダーパイプラインを変更する場合は、プロジェクトのアセットとコードが新しいレンダーパイプラと互換性があることを確認する必要があります。そうでないと、エラーや意図しないビジュアルエフェクトが発生する可能性があります。
Graphics Settings と Quality Settings の両方の設定によって、アクティブなレンダーパイプラインが決まります。Graphics Settings では、Unity がデフォルトで使用するレンダーパイプラインを設定します。Quality Settings では、特定の品質レベルのデフォルトレンダーパイプラインをオーバーライドできます。
デフォルトのレンダーパイプラインを取得または設定するには、Graphics Settings > Scriptable Render Pipeline Setting (またはこれに相当する API、GraphicsSettings.defaultRenderPipeline) を使用します。特定の品質レベルのデフォルトをオーバーライドするレンダーパイプラインを取得または設定するには、Quality Settings > Render Pipeline (またはこれに相当する API、QualitySettings.renderPipeline) を使用します。
Unity はアクティブなレンダーパイプラインを以下のように決定します。
エディター UI でアクティブなレンダーパイプラインを取得するには、Graphics Settings ウィンドウと Quality Settings ウィンドウの両方を確認する必要があります。これらの値を使用してアクティブなレンダーパイプラインを決定する方法については、アクティブなレンダーパイプラインの決定 を参照してください。
アクティブなレンダーパイプラインをビルトインレンダーパイプラインに設定するには、 Graphics Settings と Quality Settings からレンダーパイプラインアセットを削除します。
手順は以下のとおりです。
アクティブなレンダーパイプラインを SRP に基づくレンダーパイプラインに設定するには、デフォルトのアクティブなレンダーパイプラインとして使用するレンダーパイプラインアセットと、オプションで各品質レベルに使用するレンダーパイプラインアセットを Unity に指定します。
手順は以下のとおりです。
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");
}
}
}