0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Unityで、カメラに投影された部分をプレーンなりキューブなりに貼り付けたい時があると思います(ミニマップやカーレースのライブ映像、監視カメラなどなど)。それを可能にするのがRenderTextureです。

ざっくり以下の手順になります。

  1. Render Textureの作成
  2. カメラにRender Textureを追加
  3. Render Textureを用いたマテリアルを作成
  4. 投影したいオブジェクトにマテリアルをアタッチ

なお、本記事の環境は以下です。

・MacOS Sequoia 15.1.1
・Unity 6000.0.23f1 URP

それでは細かく見ていきます。

手順

  1. Render Textureの作成

    Projectウィンドウ内で右クリック > Create > Rendering > Render Texture

    作成しただけでは真っ暗ですが、この先変わるので問題ないです。

image(1).png
image(2).png

  1. カメラにRender Textureを追加

    テクスチャに描画したいカメラのCameraコンポーネント > Output > Output Textureに1.で作成したRender Textureを追加する。

    すると、1.では真っ暗だったRender Textureにカメラで描画される部分が表示されていると思います。

image(3).png
image(4).png

  1. Render Textureを用いたマテリアルを作成

    一旦シンプルにMaterialを作成(Projectウィンドウ > Create > Material)した後、そのMaterialのInspectorからSurface Inputs > Base Mapに1.で作成したRender Textureを追加する。

image(5).png
image(6).png

  1. 投影したいオブジェクトにマテリアルをアタッチ

    今回はPlaneに投影したいので、HierarchyでPlaneを追加して3.で作成したMaterialをアタッチする。

    以上!これでPlaneにカメラの描画範囲が投影されていると思います。

image(7).png
image(8).png

EX.) Planeに予期せぬものが映り込んでるんですけど?!ってパニクることがありますが、それはPlaneがカメラに映り込んでしまってるだけです。

回避策はカメラ描画範囲に描画したくないもの(今回でいうPlane)を入れないことか、カメラにCulling Maskを設定することです。

Culling Maskの設定は別記事で。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?