カメラからの Ray
サイズを大きくまたは小さく見せる

Using an Oblique Frustum

By default, the view frustum is arranged symmetrically around the camera’s center line, but it doesn’t necessarily need to be. You can make the frustum “oblique”, which means that one side is at a smaller angle to the centre line than the opposite side. This makes the perspective on one side of the image seem more condensed, giving the impression that the viewer is very close to the object visible at that edge. An example of how this can be used is a car racing game; if the frustum is flattened at its bottom edge, it appears to the viewer that they are closer to the road, accentuating the feeling of speed.

Although the Camera component does not have functions specifically for setting the obliqueness of the frustum, you can do it by either enabling the camera’s Physical Camera properties and applying a Lens Shift, or by adding a script to alter the camera’s projection matrix.

Setting Frustum Obliqueness with a Lens Shift

Enable a camera’s Physical Camera properties to expose the Lens Shift options. You can use these to offset the camera’s focal center along the X and Y axes in a way that minimizes distortion of the rendered image.

Shifting the lens reduces the frustum angle on the side opposite the direction of the shift. For example, as you shift the lens up, the angle between the bottom of the frustum and the camera’s center line gets smaller.

Normally a camera’s frustum is symmetrical (left), meaning the angles on either side of the center line are equal. Shifting the lens (right) makes the frustum oblique, meaning the angle is smaller on one side than on the other.
Normally a camera’s frustum is symmetrical (left), meaning the angles on either side of the center line are equal. Shifting the lens (right) makes the frustum oblique, meaning the angle is smaller on one side than on the other.

For further information about the Physical Camera options, see documentation on Physical Cameras.

For further information about setting individual Physical Camera properties, see the Camera Component reference.

Setting Frustum Obliqueness Using a Script

The following script example shows how to quickly achieve an oblique frustum by altering the camera’s projection matrix. Note that you can only see the effect of the script while the game is running Play mode.

using UnityEngine;
using System.Collections;

public class ExampleScript : MonoBehaviour {
    void SetObliqueness(float horizObl, float vertObl) {
        Matrix4x4 mat  = Camera.main.projectionMatrix;
        mat[0, 2] = horizObl;
        mat[1, 2] = vertObl;
        Camera.main.projectionMatrix = mat;
    }
}

C# スクリプトの例

function SetObliqueness(horizObl: float, vertObl: float) {
    var mat: Matrix4x4 = camera.projectionMatrix;
    mat[0, 2] = horizObl;
    mat[1, 2] = vertObl;
    camera.projectionMatrix = mat;
}

JS スクリプトの例

うれしいことに、射影行列がどのような仕組みで動作するか知らなくても、活用することはできます。horizObl および vertObl の値は水平および垂直方向の傾斜の値をそれぞれ設定します。値が 0 は傾斜がないことを示します。正の値は視錐台を右または上方向にずらします。これにより左または下方向を平坦にします。負の値により視錐台を左または下方向にずらします。これにより右または上方向を平坦にします。このスクリプトをカメラに追加し、ゲームの実行中にシーンビューに切り替えることで、効果を直接確認することができます。カメラ視錐台のワイヤーフレーム描画は Inspector 上で horizObl および vertObl の値とともに変化します。いずれかの値を 1 あるいは –1 とすると、視錐台の片側が中心線に関して完全に平行となることを示します。これらの値の範囲を超えて設定することは可能ではありますが、実際に必要となることはほとんどありません。


  • 2018–10–05 限られた 編集レビュー で修正されたページ

  • Lens Shift options added in Unity 2018.2

カメラからの Ray
サイズを大きくまたは小さく見せる