Graphics Overview:Camera 相机 相机系列1

本文概述Unity中相机的工作原理,包括透视相机如何模拟真实世界的视角,正交相机如何保持物体大小不变,以及相机的剪切平面、背景设置,如使用Skybox呈现无限远处的背景。

Graphics Overview:Camera 相机

本文档主要是对Unity官方手册的个人理解与总结(其实以翻译记录为主:>)
仅作为个人学习使用,不得作为商业用途,欢迎转载,并请注明出处。
文章中涉及到的操作都是基于Unity2018.2版本
参考链接:https://docs.unity3d.com/Manual/CamerasOverview.html

A Unity scene is created by arranging and moving objects in a three-dimensional space. Since the viewer’s screen is two-dimensional, there needs to be a way to capture a view and “flatten” it for display. This is accomplished using Cameras.
一个Unity 场景是通过在三维空间组织和移动物体来创建的。由于观察者的屏幕是二维的,因此需要一种方法来捕获视图并“压平”它以便显示。这个工作是用相机完成的。

A camera is an object that defines a view in scene space. The object’s position defines the viewpoint, while the forward (Z) and upward (Y) axes of the object define the view direction and the top of the screen, respectively. The Camera component also defines the size and shape of the region that falls within the view. With these parameters set up, the camera can display what it currently “sees” to the screen. As the camera object moves and rotates, the displayed view will also move and rotate accordingly.
摄像机是在场景空间中定义视图的对象。对象的位置定义了视点,对象的前(Z)轴和上(Y)轴分别定义了视图的方向和屏幕的顶部。相机组件还定义了属于视图的区域的大小和形状。设置好这些参数后,相机就可以将当前“看到”的内容显示在屏幕上。当摄像机对象移动和旋转时,显示的视图也会相应地移动和旋转。

Perspective and orthographic cameras
The same scene shown in perspective mode (left) and orthographic mode (right)
The same scene shown in perspective mode (left) and orthographic mode (right)
左:透视模式,右:正交模式

A camera in the real world, or indeed a human eye, sees the world in a way that makes objects look smaller the farther they are from the point of view. This well-known perspective effect is widely used in art and computer graphics and is important for creating a realistic scene. Naturally, Unity supports perspective cameras, but for some purposes, you want to render the view without this effect. For example, you might want to create a map or information display that is not supposed to appear exactly like a real-world object. A camera that does not diminish the size of objects with distance is referred to as orthographic and Unity cameras also have an option for this. The perspective and orthographic modes of viewing a scene are known as camera projections. (scene above from BITGEM)
在现实世界中,照相机,或者说是人眼,以一种物体看起来越远越小的方式观察这个世界。这种著名的透视效果在艺术和计算机图形学中得到了广泛的应用,对于创建一个真实的场景非常重要。当然,Unity支持透视相机,但出于某些目的,您希望在不产生这种效果的情况下呈现视图。例如,您可能希望创建一个贴图或信息显示,它不应该完全像真实的对象那样显示。不随距离减小物体大小的相机称为正交投影相机,而Unity相机也有这样的选择。观看场景的透视和正交投影模式称为相机投影。

The shape of the viewed region 观察区的形状

Both perspective and orthographic cameras have a limit on how far they can “see” from their current position. The limit is defined by a plane that is perpendicular to the camera’s forward (Z) direction. This is known as the far clipping plane since objects at a greater distance from the camera are “clipped” (ie, excluded from rendering). There is also a corresponding near clipping plane close to the camera - the viewable range of distance is that between the two planes.
透视和正投影相机都有一个限制,即它们从当前位置“看到”的距离有多远。这个极限是由垂直于相机正(Z)方向的平面定义的。这被称为远剪切平面,因为离摄像机较远的物体是“剪切”的(即不包含渲染)。在相机附近还有一个对应的近裁剪平面,距离的可视范围是两个平面之间的距离。

Without perspective, objects appear the same size regardless of their distance. This means that the viewing volume of an orthographic camera is defined by a rectangular box extending between the two clipping planes.
在没有透视的情况下,物体无论距离大小都是一样的。这意味着正投影相机的视野体是由两个裁剪平面之间的矩形框定义的。

When perspective is used, objects appear to diminish in size as the distance from camera increases. This means that the width and height of the viewable part of the scene grows with increasing distance. The viewing volume of a perspective camera, then, is not a box but a pyramidal shape with the apex at the camera’s position and the base at the far clipping plane. The shape is not exactly a pyramid, however, because the top is cut off by the near clipping plane; this kind of truncated pyramid shape is known as a frustum. Since its height is not constant, the frustum is defined by the ratio of its width to its height (known as the aspect ratio) and the angle between the top and bottom at the apex (known as the field of view of FOV). See the page about understanding the view frustum for a more detailed explanation.
当使用透视法时,随着与相机距离的增加,物体的尺寸似乎变小了。这意味着场景中可视部分的宽度和高度会随着距离的增加而增加。因此,透视相机的观察体积不是一个盒子,而是一个金字塔形状,顶点在相机的位置,底部在远剪切平面。然而,这个形状并不完全是一个金字塔,因为顶部是由近剪切平面切断;这种截断的金字塔形状被称为平截头体。由于高度不是恒定的,平截头体是由宽度与高度之比(称为宽高比)以及顶端与底部之间的夹角(称为FOV的视角场)定义的。有关理解视图视锥体的详细说明,请参阅该页面。

The background to the camera view 相机视图的背景

For indoor scenes, the camera may always be completely inside some object representing the interior of a building, cave or other structure. When the action takes place outdoors, however, there will be many empty areas in between objects that are filled with nothing at all; these background areas typically represent the sky, space or the murky depths of an underwater scene.
对于室内场景,摄像机可能总是完全在某个代表建筑、洞穴或其他结构内部的物体中。然而,当这种行为发生在户外时,在物体之间会有许多空的区域,而这些空间里什么也没有;这些背景区域通常代表天空、空间或水下场景的黑暗深度。

A camera can’t leave the background completely undecided and so it must fill in the empty space with something. The simplest option is to clear the background to a flat color before rendering the scene on top of it. You can set this color using the camera’s Background property, either from the inspector or from a script. A more sophisticated approach that works well with outdoor scenes is to use a Skybox. As its name suggests, a skybox behaves like a “box” lined with images of a sky. The camera is effectively placed at the center of this box and can see the sky from all directions. The camera sees a different area of sky as it rotates but it never moves from the center (so the camera cannot get “closer” to the sky). The skybox is rendered behind all objects in the scene and so it represents a view at infinite distance. The most common usage is to represent the sky in a standard outdoor scene but the box actually surrounds the camera completely, even underneath. This means that you can use a skybox to represent parts of the scene (eg, rolling plains that stretch beyond the horizon) or the all-round view of a scene in space or underwater.
相机需要确定背景,所以它必须用一些东西来填补空白。最简单的选择是在渲染场景之前先将背景清除为一种平坦的颜色。您可以使用相机的背景属性设置此颜色,可以从检查器中设置,也可以从脚本中设置。使用天空盒(Skybox)是一种更常见的方法,可以很好地处理户外场景。正如它的名字所暗示的,天空盒的行为就像一个填充着天空图像的“盒子”。相机被有效地放置在这个盒子的中心,可以从任何方向看到天空。当它旋转时,摄像机可以看到天空的不同区域,但它不能从中心移开(因此摄像机无法“更靠近”天空)。skybox被渲染在场景中所有物体的后面,因此它代表了一个无穷远距离的视图。最常见的用法是在一个标准的户外场景中表现天空,但是盒子实际上完全包围了相机,甚至在下面。这意味着你可以使用一个天空盒来呈现场景的一部分(例如,延伸到地平线之外的起伏的平原),或者空间场景或水下场景的全景。

You can add a skybox to a scene simply by setting the Skybox property in the Lighting window (menu: Window > Rendering > Lighting Settings). See this page for further details on how to create your own skybox.
您可以通过在Lighting 窗口中设置skybox属性,向场景添加一个skybox(menu: Window > Rendering > Lighting Settings)。

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值