Version: 2023.2
言語: 日本語
Lines, trails, and billboards
Trail Renderer コンポーネント

Line Renderer コンポーネント

Line Renderer (ラインレンダラー) コンポーネントは、3D 空間の 2 つ以上の点の配列をとり、それぞれの間に直線を描きます。1 つのラインレンダラーを使用して、単純な直線から複雑な螺旋まで、どんなものでも描画することができます。

線 (ライン) は必ず連続した状態になっています。2 本以上の完全に個別の線を描画したい場合、複数のゲームオブジェクトを使用し、それぞれにラインレンダラーを設定する必要があります。

ラインレンダラーはピクセル単位の幅の線を描画しません。ワールド単位の幅を持つポリゴンを描画します。ラインレンダラーは、 Trail Renderer (トレイルレンダラー) と同じアルゴリズムをラインレンダリングに使用します。

はじめに

ラインレンダラーを作成するには、次の手順に従います。

  1. Unity メニューバーで GameObject > Effects > Line の順に移動します。
  2. Line Renderer ゲームオブジェクトを選択します。
  3. ラインレンダラーの Positions 配列にポイントを追加するには、Inspector ウィンドウで配列の値を直接設定するか、シーン編集モード の Create Points を使用します。
  4. Inspector ウィンドウを使用して、線の色、 幅、その他の表示設定を行います。
ラインレンダラーの設定例
ラインレンダラーの設定例

ラインレンダラーマテリアル

デフォルトでは、ラインレンダラーはビルトインのマテリアルである Default-Line を使用します。このマテリアルを変更せずに、線のカラーグラデーションや幅など、線の外観に多くの変更を加えることができます。

線にテクスチャを適用するなどの他の効果の場合は、異なるマテリアルを使用する必要があります。新しいマテリアル用に独自のシェーダーを作成したくない場合は、Unity のビルトインの スタンダードパーティクルシェーダー がラインレンダラーでうまく機能します。

詳細は マテリアルの作成と使用 を参照してください。

ラインレンダラーのシーン編集モード

ラインレンダラーのインスペクターを使用してシーン編集モードを変更できます。さまざまなシーン編集モードでは、シーンビューとインスペクターを使用してさまざまな方法でラインレンダラーを編集できます。

シーン編集モードには、NoneEdit PointsCreate Points の 3 つがあります。

Scene Editing Mode (シーン編集モード) の設定

ラインレンダラーの Edit Points ボタンと Create Points ボタン
ラインレンダラーの Edit Points ボタンと Create Points ボタン

インスペクターの上部にある Edit Points ボタンと Create Points ボタンを使用して、現在のシーン編集モードを設定します。

Edit Points ボタンをクリックして、Scene Editing Mode を Edit Points に設定します 。もう一度クリックすると、Scene Editing Mode は None に設定されます。

Create Points ボタンをクリックして、Scene Editing Mode を Create Points に設定します 。もう一度クリックすると、Scene Editing Mode は None に設定されます。

Scene Editing Mode: None

Line Renderer Simplify コントロール
Line Renderer Simplify コントロール

シーン編集モードが選択されていない場合は、Positions 配列から不要なポイントを削除する簡略化操作を設定して実行できます。

以下のコントロールがインスペクターに表示されます。

コントロール 説明 
Simplify Preview Simplify Preview を有効にすると、簡略化操作の結果のプレビューを表示できます。
Tolerance 簡略化された線が元の線から逸脱できる度合いを設定します。

値が 0 の場合、偏差は発生しないため、単純化はほとんど、またはまったく行われません。正の値が大きいほど、元の線からの偏差が大きくなり、より簡略化されます。

デフォルト値は 1 です。
Simplify Simplify をクリックして、ラインレンダラーの Positions 配列の要素の数を減らします。

簡略化操作では、Ramer-Douglas-Peucker アルゴリズム を使用して、Tolerance 値に基づいて点の数を減らします。

Scene Editing Mode: Edit Points

Edit Points シーン編集モードのラインレンダラー
Edit Points シーン編集モードのラインレンダラー

Scene Editing Mode が Edit Points に設定されている場合、Unity は Line Renderer の Positions 配列の各点をシーンビューで黄色のスフィアとして表します。移動ツールを使用して、個々の点を移動できます。

以下のコントロールがインスペクターに表示されます。

コントロール 説明 
Show Wireframe 有効にすると、シーンビューでワイヤーフレームを描画し、線を可視化します。
Subdivide Selected このボタンは、隣接する複数の点を選択すると有効になります。このボタンを押すと、選択した隣接する点の間に新しい点が挿入されます。

Scene Editing Mode: Create Points

Create Points シーン編集モードのラインレンダラー
Create Points シーン編集モードのラインレンダラー

シーン編集モードが Create Points に設定されている場合は、シーンビューの内側をクリックすると、ラインレンダラーの Positions 配列の最後に新しいポイントを追加できます。

以下のコントロールがインスペクターに表示されます。

コントロール 説明 
Input 点の作成に使用する入力方法を設定します。
Mouse position シーンビューのマウスの位置に基づいて点を作成します。
Physics Raycast シーンへの レイキャスト に基づいてポイントを作成します。Unity はレイキャストが当たる位置に点を作成します。
Layer Mask レイキャストを実行するときに使用するレイヤーマスク。このプロパティは、InputPhysics Raycast に設定されている場合にのみ表示されます。
Min Vertex Distance シーンビューでマウスをドラッグして点を作成するときに、最後のポイントからこの距離を超えると、ラインレンダラーが新しい点を作成します。
Offset 作成された点に適用されるオフセット。InputMouse Position に設定されている場合、ラインレンダラーはシーンカメラからのオフセットを適用します。Input が Physics Raycast に設定されている場合、Line Renderer はレイキャスト法線からのオフセットを適用します。

Line Renderer Inspector のリファレンス

このセクションには、以下のサブセクションがあります。

ライン設定

プロパティ 機能
Loop これを有効にすると、最初と最後の線の位置を接続し、閉じたループを作成します。
Positions 接続する Vector3 の点の配列を設定します。
Width 幅とカーブの値を決め、線のさまざまな位置で線の幅を制御します。

カーブは各頂点でサンプリングされます。そのため、その正確さは線に存在する頂点数によって制限されます。線全体の幅は Width 値によって制御されます。
Color (色) グラデーションを定義して、線のさまざまな位置で色をコントロールします。

Unity は各頂点でカラーグラデーションから色をサンプリングします。Unity は、各頂点間で色に線形補間を適用します。線により多く頂点を追加すると、より詳細なグラデーションがより近似されます。
Corner Vertices 線に曲がり角を描画するとき、追加の頂点をいくつ使用するかを制御します。この値を増やすと、線の曲がり角がより丸く表示されます。
End Cap Vertices 線にエンドキャップを描画するとき、追加の頂点をいくつ使用するかを制御します。この値を増やすと、線のキャップがより丸く表示されます。
Alignment 線の向きを設定します。
View 線はカメラに正面を向けます。
TransformZ 線は Transform コンポーネントの Z 軸に正面を向けます。
Texture Mode テクスチャを線に適用する方法を制御します。
Stretch 線の全長に沿ってテクスチャを 1 回マッピングします。
Tile ワールド単位の長さに基づいて、線に沿ってテクスチャを繰り返します。タイリング率を設定するには、Material.SetTextureScale を使用します。
DistributePerSegment 線の全長に沿ってテクスチャを 1 回マッピングします。すべての頂点間隔は均等であると仮定します。
RepeatPerSegment 線に沿ってテクスチャを繰り返します。線のセグメント (1 区分) ごとに 1 回の割合で繰り返します。タイリングレートを調整するには、Material.SetTextureScale を使用します。
Shadow Bias Set the amount to move shadows away from the Light to remove shadowing artifacts caused by approximating a volume with billboarded geometry.
Generate Lighting Data これを有効にすると、Unity は法線と接線を含むラインジオメトリを構築します。これにより、シーンライティングを使用するマテリアルを使用できます。
Use World Space これを有効にすると、点はワールド空間座標で考えられます。無効にすると、このコンポーネントがアタッチされているゲームオブジェクトの Transform に対してローカルになります。

Materials

Materials セクションには、このコンポーネントが使用するすべての マテリアル が列挙されています。

プロパティ 説明
Size The number of elements in the material list.

If you decrease the number of elements, Unity deletes the elements at the end of the list. If you increase the number of elements, Unity adds new elements to the end of the list. Unity populates new elements with the same material that the element at the end of the list uses.
Element The materials in the list. You can assign a material asset to each element.

By default, Unity orders the list alphabetically based on the name of the materials. This list is reorderable, and Unity updates the number of the elements automatically as you change their order.

Lighting

Lighting セクションには、ライティングに関連するプロパティを含まれています。

プロパティ 説明
Cast Shadows Specify if and how this Renderer casts shadows when a suitable Light shines on it.

This property corresponds to the Renderer.shadowCastingMode API.
On This Renderer casts a shadow when a shadow-casting Light shines on it.
Off This Renderer does not cast shadows.
Two-sided This Renderer casts two-sided shadows. This means that single-sided objects like a plane or a quad can cast shadows, even if the light source is behind the mesh.

For Baked Global Illumination or Enlighten Realtime Global Illumination to support two-sided shadows, the material must support Double Sided Global Illumination.
Shadows Only This Renderer casts shadows, but the Renderer itself isn’t visible.
Receive Shadows Specify if Unity displays shadows cast onto this Renderer.

This property only has an effect if you enable Baked Global Illumination or Enlighten Realtime Global Illumination for this scene.

This property corresponds to the Renderer.receiveShadows API.
Contribute Global Illumination Include this Renderer in global illumination calculations, which take place at bake time.

This property only has an effect if you enable Baked Global Illumination or Enlighten Realtime Global Illumination for this scene.

Enabling this property enables the Contribute GI flag in the GameObject’s Static Editor Flags. It corresponds to the StaticEditorFlags.ContributeGI API.
Receive Global Illumination Whether Unity provides global illumination data to this Renderer from baked lightmaps, or from runtime Light Probes.

This property is only editable if you enable Contribute Global Illumination. It only has an effect if you enable Baked Global Illumination or Enlighten Realtime Global Illumination for this scene.

This property corresponds to the MeshRenderer.receiveGI API.
Lightmaps Unity provides global illumination data to this Renderer from lightmaps.
Light Probes Unity provides global illumination data to this Renderer from Light Probes in the scene.
Prioritize Illumination Enable this property to always include this Renderer in Enlighten Realtime Global Illumination calculations. This ensures that the Renderer is affected by distant emissives, even those which are normally excluded from Global Illumination calculations for performance reasons.

This property is visible only if Contribute GI is enabled in the GameObject’s Static Editor Flags, your project uses the Built-in Render Pipeline, and Enlighten Realtime Global Illumination is enabled in your scene.

Probes

Probes セクションには、ライトプローブリフレクションプローブ に関するプロパティが含まれています。

プロパティ 説明
Light Probes Set how this Renderer receives light from the Light Probes system.

This property corresponds to the Renderer.lightProbeUsage API.
Off The Renderer doesn’t use any interpolated Light Probes.
Blend Probes The Renderer uses one interpolated Light Probe. This is the default value.
Use Proxy Volume The Renderer uses a 3D grid of interpolated Light Probes.
Custom Provided The Renderer extracts Light Probe shader uniform values from the MaterialPropertyBlock.
Proxy Volume Override Set a reference to another GameObject that has a Light Probe Proxy Volume component.

This property is only visible when Light Probes is set to Use Proxy Volume.
Reflection Probes Set how the Renderer receives reflections from the Reflection Probe system.

This property corresponds to the Renderer.probeAnchor API.
Off Disables Reflection Probes. Unity uses a skybox for reflection.
Blend Probes Enables Reflection Probes. Blending occurs only between Reflection Probes. This is useful in indoor environments where the character may transition between areas with different lighting settings.
Blend Probes and Skybox Enables Reflection Probes. Blending occurs between Reflection Probes, or between Reflection Probes and the default reflection. This is useful for outdoor environments.
Simple Enables Reflection Probes, but no blending occurs between Reflection Probes when there are two overlapping volumes.
Anchor Override Set the Transform that Unity uses to determine the interpolation position when using the Light Probe or Reflection Probe systems. By default, this is the centre of the bounding box of the Renderer’s geometry.

This property corresponds to the Renderer.probeAnchor API.

Additional Settings

Additional Settings には付加的なプロパティが含まれています。

Property Description
Motion Vectors Set whether to use motion vectors to track this Renderer’s per-pixel, screen-space motion from one frame to the next. You can use this information to apply post-processing effects such as motion blur.

Note: not all platforms support motion vectors. See SystemInfo.supportsMotionVectors for more information.

This property corresponds to the Renderer.motionVectorGenerationMode API.
Camera Motion Only Use only Camera movement to track motion.
Per Object Motion Use a specific pass to track motion for this Renderer.
Force No Motion Do not track motion.
Dynamic Occlusion When Dynamic Occlusion is enabled, Unity’s occlusion culling system culls this Renderer when it is blocked from a Camera’s view by a Static Occluder. Otherwise, the system does not cull this Renderer when it is blocked from a Camera’s view by a Static Occluder.

Dynamic Occlusion is enabled by default. Disable it for effects such as drawing the outline of a character behind a wall.
Sorting Layer The name of this Renderer’s Sorting Layer.
Order in Layer This Renderer’s order within a Sorting Layer.

LineRenderer

Lines, trails, and billboards
Trail Renderer コンポーネント