1. 程式人生 > >Unity攝像機基本功能介紹

Unity攝像機基本功能介紹

相機(Camera)是向玩家捕獲和顯示世界的裝置。通過自定義和操縱攝像機,你可以使你的遊戲表現得真正獨特。您在場景中攝像機的數量不受限制。他們可以以任何順序設定放置在螢幕上的任何地方,或在螢幕的某些部分。

Unity靈活的Camera物件
Unity's flexible Camera object 
Unity靈活的Camera物件

Properties 屬性

  • Clear Flags 清除標識 Determines which parts of the screen will be cleared. This is handy when using multiple Cameras to draw different game elements.
    確定了螢幕哪些部分將被清除。這是為了方便使用多個攝像機畫不同的遊戲元素。
  • Background 背景 Color applied to the remaining screen after all elements in view have been drawn and there is no skybox.
    應用於檢視中的所有元素繪製後,和沒有天空盒的情況下,剩餘螢幕的顏色
  • Culling Mask 消隱遮罩 Include or omit layers of objects to be rendered by the Camera. Assign layers to your objects in the Inspector.
    包含層或忽略層將被相機(Camera)渲染。在檢視視窗向物件分配層。
  • Projection 投影 Toggles the camera's capability to simulate perspective.
    切換相機的能力,以模擬透視。
  •     Perspective 透視 Camera will render objects with perspective intact.
    攝像機(Camera)將使物體和透視完好無損。
  •     Orthographic 正交 Camera will render objects uniformly, with no sense of perspective.
    相機會均勻地渲染物體,沒有透視感。
  • Size 大小
     (當正交被選擇上)
    (when Orthographic is selected)
    The viewport size of the Camera when set to Orthographic.
    當攝像機設定為正交模式,攝影機視口的大小
  • Field of view 視野 Width of the Camera's view angle, measured in degrees along the local Y axis.
    相機的視野,沿著本地Y軸測量的度為單位。
  • Clipping Planes 裁剪面 Distances from the camera to start and stop rendering.
    相機到開始和結束渲染的距離
  •     Near  The closest point relative to the camera that drawing will occur.
    相對於相機,繪製將發生的最近點。
  •     Far  The furthest point relative to the camera that drawing will occur.
    相對於相機,繪製將發生的最遠點。
  • Normalized View Port Rect
    規範化的視口矩形 Four values that indicate where on the screen this camera view will be drawn, in Screen Coordinates (values 0-1).
    標明這臺相機檢視將會在螢幕上繪製的螢幕座標(值0 - 1) 的4個值。
  •     X The beginning horizontal position that the camera view will be drawn.
    將得出相機檢視的開始水平位置。
  •     Y The beginning vertical position that the camera view will be drawn.
    將得出相機檢視的開始垂直位置。
  •     W (Width) 寬度 Width of the camera output on the screen. 攝像機輸出在螢幕上的寬度。
  •     H (Height) 高度 Height of the camera output on the screen. 攝像機輸出在螢幕上的高度。
  • Depth 深度 The camera's position in the draw order. Cameras with a larger value will be drawn on top of cameras with a smaller value.
    相機在渲染順序上的位置。具有較低深度的相機將在較高深度的相機之前渲染。
  • Rendering Path 渲染路徑 Options for defining what rendering methods will be used by the camera.
    定義什麼繪製方法將被用於相機的選項。
  •     Use Player Settings 使用玩家設定 This camera will use whichever Rendering Path is set in the Player Settings.
    在玩家設定(Player Settings.)相機使用哪個渲染路徑。
  •     Vertex Lit 頂點光照 All objects rendered by this camera will be rendered as Vertex-Lit objects.
    所有被這個相機渲染的物體都將渲染成Vertex-Lit物體。
  •     Forward 正向渲染 All objects will be rendered with one pass per material, as was standard in Unity 2.x.
    所有物件每材質渲染只渲染一次,和Unity 2.x中的標準一樣。
  •     Deferred Lighting 延遲照明
        (Unity Pro only) All objects will be drawn once without lighting, then lighting of all objects will be rendered together at the end of the render queue.
    所有物體將在無光照的環境渲染一次,然後在渲染佇列尾部將物體的光照一起渲染出來。
  • Target Texture 目標紋理
    (Unity Pro/Advanced only) Reference to a Render Texture that will contain the output of the Camera view. Making this reference will disable this Camera's capability to render to the screen.
    參見 渲染紋理 (Render Texture),渲染紋理 (Render Texture)包含相機檢視輸出。這會使相機渲染在螢幕上的能力被禁止。

Details 細節

Cameras are essential for displaying your game to the player. They can be customized, scripted, or parented to achieve just about any kind of effect imaginable. For a puzzle game, you might keep the Camera static for a full view of the puzzle. For a first-person shooter, you would parent the Camera to the player character, and place it at the character's eye level. For a racing game, you'd likely want to have the Camera follow your player's vehicle.

相機(Cameras)是顯示你的遊戲玩家必不可少的。他們可以進行定製,可以為之編寫指令碼,或者parented,達到任何所可以想象到的效果。對於一個拼圖遊戲,你可以讓攝像機靜止地看見整個拼圖。對於一個第一人稱射擊遊戲,你會相機作為玩家角色的父物體,把它放在人物的眼睛的高度。對於一個賽車遊戲,你可能更希望把相機跟隨您的玩家的車輛。

You can create multiple Cameras and assign each one to a different Depth. Cameras are drawn from low Depth to high Depth. In other words, a Camera with a Depth of 2 will be drawn on top of a Camera with a depth of 1. You can adjust the values of the Normalized View Port Rectangle property to resize and position the Camera's view onscreen. This can create multiple mini-views like missile cams, map views, rear-view mirrors, etc.

您可以建立多個攝像機(Cameras),每一個分配到不同的深度。相機從低深度到高深度進行繪製。換句話說,深度為2的攝像機將會繪製在深度為1的相機的上面。(深度為2的相機會在深度為1的相機繪製後繪製。)你可以調整規範化視口矩形( Normalized View Port Rectangle)的值來調整相機視口在螢幕上的大小和位置。這可以創造像導彈凸輪,地圖視野​​,後視鏡等多個迷你視野.(mini-views)

Render Path 渲染路徑

Unity supports different Rendering Paths. You should choose which one you use depending on your game content and target platform / hardware. Different rendering paths have different features and performance characteristics that mostly affect Lights and Shadows.
The rendering Path used by your project is chosen in Player Settings. Additionally, you can override it for each Camera.

Unity支援不同的渲染路徑。你應該根據你的遊戲內容和目標的平臺/硬體選擇使用哪一個(渲染路徑)。不同的渲染路徑具有不同的特點和效能特點,主要影響燈光與陰影。您的專案所使用的渲染路徑在玩家設定(Player Settings)裡選擇。此外,您可以每個攝像機中覆蓋它。

For more info on rendering paths, check the rendering paths page.

渲染路徑的詳細資訊,看"渲染路徑"頁面。

Clear Flags 清除標識

Each Camera stores color and depth information when it renders its view. The portions of the screen that are not drawn in are empty, and will display the skybox by default. When you are using multiple Cameras, each one stores its own color and depth information in buffers, accumulating more data as each Camera renders. As any particular Camera in your scene renders its view, you can set the Clear Flags to clear different collections of the buffer information. This is done by choosing one of the four options:

每個攝像機在渲染場景時會儲存顏色和深度的資訊。不繪製在螢幕的部分是空的,並且預設情況下會顯示天空盒。當您使用多臺攝像機,在各自緩衝區儲存它自己的顏色和深度資訊,更多的資料會被各攝像機渲染。由於在你的場景任何特定相機渲染它的視野,你可以設定清除標誌,清除不同的緩衝區資訊。這是通過選擇四個選項之一來完成的:

Skybox 天空盒

This is the default setting. Any empty portions of the screen will display the current Camera's skybox. If the current Camera has no skybox set, it will default to the skybox chosen in the Render Settings (found in Edit->Render Settings). It will then fall back to the Background Color. Alternatively a Skybox component can be added to the camera. If you want to create a new Skybox, you can use this guide.

這是預設設定。螢幕上的任何空的部分將顯示當前相機的天空盒。如果當前的相機沒有設定天空盒,它會預設在渲染設定(Render Settings )選擇天空盒(在 Edit->Render Settings可以找到)。它將會變回背景色。另外天空盒元件可以新增到相機上。如果你想建立一個新的天空盒,您可以使用本指南。(you can use this guide)

Solid Color 純色

Any empty portions of the screen will display the current Camera's Background Color.

任何空部分,螢幕顯示為當前相機的背景色。

Depth Only 僅深度

If you wanted to draw a player's gun without letting it get clipped inside the environment, you would set one Camera at Depth 0 to draw the environment, and another Camera at Depth 1 to draw the weapon alone. The weapon Camera's Clear Flags should be set to to depth only. This will keep the graphical display of the environment on the screen, but discard all information about where each object exists in 3-D space. When the gun is drawn, the opaque parts will completely cover anything drawn, regardless of how close the gun is to the wall.

如果你想繪製一個玩家的槍,又不讓它內部環境被裁剪,你會設定深度為0的相機繪製環境,和另一個深度為1的相機單獨繪製武器。武器相機的清除標誌(Clear Flags )應設定 為depth only。


The gun is drawn last, after clearing the depth buffer of the cameras before it
槍是最後繪製的,清理相機的深度緩衝之後。

Don't Clear 不清除

This mode does not clear either the color or the depth buffer. The result is that each frame is drawn over the next, resulting in a smear-looking effect. This isn't typically used in games, and would likely be best used with a custom shader.

此模式不清除顏色或深度快取。每一幀在下一幀結束後繪製,看上去像是塗抹(smear-looking)的效果。這在遊戲中不常用,最好是在自定義著色器(custom shader)上使用。

Clip Planes 裁剪面

The Near and Far Clip Plane properties determine where the Camera's view begins and ends. The planes are laid out perpendicular to the Camera's direction and are measured from the its position. The Near plane is the closest location that will be rendered, and the Far plane is the furthest.

近裁剪面及遠裁剪面屬性確定相機視野的開始和結束。平面是佈置在與相機的方向垂直的位置,並從它的位置測量。近裁剪面是最近的渲染位置,遠平面是最遠的渲染位置。

The clipping planes also determine how depth buffer precision is distributed over the scene. In general, to get better precision you should move the Near plane as far as possible.

裁剪平面,也決定了深度快取精度如何分佈在場景。在一般情況下,為了獲得更好的精度,你應該把近裁剪面移動到儘可能遠的地方。

Note that the near and far clip planes together with the planes defined by the field of view of the camera describe what is popularly known as the camera frustum. Unity ensures that when rendering your objects those which are completely outside of this frustum are not displayed. This is called Frustum Culling. Frustum Culling happens irrespective of whether you use Occlusion Culling in your game.

請注意,近裁剪面及遠裁剪面和以相機視野所定義的平面一起普遍稱為相機的平截頭體。Unity確保渲染物件時,那些完全超出這個平截頭體的物體不顯示。這就是所謂的平截頭體消隱(Frustum Culling)。不論你的遊戲是否使用遮擋剔除(Occlusion Culling),都會進行平截頭體剔除。

For performance reasons, you might want to cull small objects earlier. For example, small rocks and debris could be made invisible at much smaller distance than large buildings. To do that, put small objects into a separate layer and setup per-layer cull distances using Camera.layerCullDistances script function.

出於效能方面的原因,你可能最先剔除小物件。例如,在遠小於大型建築物的距離,小石塊和碎片可以隱藏掉。

Culling Mask 消隱遮罩

The Culling Mask is used for selectively rendering groups of objects using Layers. More information on using layers can be found here.

消隱遮罩是利用層選擇性地渲染組物件。運用層的更多資訊可以在這裡找到。

Commonly, it is good practice to put your User Interface on a different layer, then render it by itself with a separate Camera set to render the UI layer by itself.

一般情況下,你的使用者介面放在不同的層,然後渲染本身與設定一個單獨的相機渲染UI層。這是很好的做法。

In order for the UI to display on top of the other Camera views, you'll also need to set the Clear Flags to Depth only and make sure that the UI Camera's Depth is higher than the other Cameras.

為了UI(使用者介面)渲染在其他相機的景物渲染之前,你需要設定清除標識( Clear Flags)為只深度(Depth only)確保UI相機的深度高於其他照相機。

Normalized Viewport Rectangle 規範化視口矩形

Normalized Viewport Rectangles are specifically for defining a certain portion of the screen that the current camera view will be drawn upon. You can put a map view in the lower-right hand corner of the screen, or a missile-tip view in the upper-left corner. With a bit of design work, you can use Viewport Rectangle to create some unique behaviors.

規範化視口矩形是專門為定義一個當前照相機將會繪製到的螢幕一個特定部分 。你可以在螢幕右下角的放置地圖檢視,或在左上角放置導彈提示檢視。你可以使用視口矩形創造一些獨特的行為。

It's easy to create a two-player split screen effect using Normalized Viewport Rectangle. After you have created your two cameras, change both camera H value to be 0.5 then set player one's Y value to 0.5, and player two's Y value to 0. This will make player one's camera display from halfway up the screen to the top, and player two's camera will start at the bottom and stop halfway up the screen.

使用規範化視口矩形(Normalized Viewport Rectangle)可以很容易地建立雙玩家(two-player)的分割畫面效果。建立了兩個攝像頭後,改變兩個相機的H值為0.5然後設定玩家1的Y值至0.5,玩家2的Y值設定為0。那麼玩家1的攝像機就會從螢幕的中間到頂部顯示,玩家2的攝像機就會從螢幕底部到螢幕中間顯示(把螢幕按上下分成2半,上半部分是玩家1的,下半部分是玩家2的)


Two-player display created with Normalized Viewport Rectangle
用規範化視口矩形制造 雙玩家 顯示

Orthographic 正交

Marking a Camera as Orthographic removes all perspective from the Camera's view. This is mostly useful for making isometric or 2D games.

標識正交相機模式,從相機的檢視中刪除所有的透視效果,最主要用在等距或2D遊戲中。

Note that fog is rendered uniformly in orthographic camera mode and may therefore not appear as expected. Read more about why in the component reference on Render Settings.

注意霧是在正交相機模式下渲染,因此可能不會如預期般出現。想知道為什麼請看元件手冊裡的渲染設定(component reference on Render Settings.)。


Perspective camera. 透視相機


Orthographic camera. Objects do not get smaller with distance here!
正交相機。在這裡物體不隨距離而變小

Render Texture 渲染紋理

This feature is only available for Unity Advanced licenses . It will place the camera's view onto a Texture that can then be applied to another object. This makes it easy to create sports arena video monitors, surveillance cameras, reflections etc.

此功能僅Unity高階版提供。它將會把一個相機檢視放置在一個將被用在其他物體的紋理(Texture )上。這使得很容易地建立體壇視訊監控,監控攝像機,反射等。


A Render Texture used to create a live arena-cam
用渲染紋理做的競技場攝像機所拍現場

Hints 提示

  • Cameras can be instantiated, parented, and scripted just like any other GameObject. 
    相機可以被定製,可以作為父節點,和為之編寫指令碼,就像GameObject一樣。
  • To increase the sense of speed in a racing game, use a high Field of View. 
    要增加一個賽車遊戲的速度感,使用了高視野(Field of View)。
  • Cameras can be used in physics simulation if you add a Rigidbody Component. 
    如果你新增剛體(Rigidbody )元件,相機可用於物理模擬。
  • There is no limit to the number of Cameras you can have in your scenes. 
    在你的場景中,相機的數目不受限制。
  • Orthographic cameras are great for making 3D user interfaces 
    正交相機是能很好的製作3D使用者介面
  • If you are experiencing depth artifacts (surfaces close to each other flickering), try setting Near Plane to as large as possible. 
    如果你遇到深入的構件(表面互相緊密會產生閃爍現象),近裁剪面儘可能設定大點。
  • Cameras cannot render to the Game Screen and a Render Texture at the same time, only one or the other. 
    相機無法同時渲染遊戲畫面和渲染紋理,只能是其中一個。
  • Pro license holders have the option of rendering a Camera's view to a texture, called Render-to-Texture, for even more unique effects. 
    Unity專業版有渲染攝像機檢視到紋理的選項,叫做渲染到紋理(Render-to-Texture),可以做出更多更好的獨特效果。
  • Unity comes with pre-installed Camera scripts, found in Components->Camera Control. Experiment with them to get a taste of what's possible. 
    Unity伴隨著預先安裝的攝像機指令碼,在Components->Camera Control能找到。試用一下它們,看看能做什麼。

相關推薦

Unity攝像機基本功能介紹

相機(Camera)是向玩家捕獲和顯示世界的裝置。通過自定義和操縱攝像機,你可以使你的遊戲表現得真正獨特。您在場景中攝像機的數量不受限制。他們可以以任何順序設定放置在螢幕上的任何地方,或在螢幕的某些部分。 Unity's flexible Camera object  U

名位元組點(NameNode)基本功能介紹

功能圖 下圖為名位元組點基本功能圖,可能會有遺漏,在以後的原始碼研讀中會更新: 基本功能介紹 NameNodeHttpServer:提供Http服務 NameNodeRpcServer:RPC機制實現,名位元組點與其他節點之間遠端呼叫的實現(名位

OpenStack基本功能介紹

一、簡介 什麼是OpenStack?OpenStack是一個開源的雲端計算管理平臺專案,由幾個主要的元件組合起來完成具體工作。OpenStack支援幾乎所有型別的雲環境,專案目標是提供實施簡單、可大規模擴充套件、豐富、標準統一的雲端計算管理平臺。OpenStack通過各種互

Keil MDK使用第1篇---模擬基本功能介紹

用keil也有一段時間了,把軟體模擬大致總結了下,主要是軟體使用技巧; 下邊兩個選項不同: 第一個軟體模擬,與硬體無關 第二個用硬體模擬,STC的IAP可以,STM32需要藉助j-link 開始模擬介面: 功能詳解 1、       Rese

Axure RP 基本功能介紹

一、Axure 介面介紹 二、站點地圖在原型中的作用 在站點地圖中的頁面以主頁為根點,呈樹狀展示,通過站點地圖可以對原型中的不同模組、欄目進行管理,也可幫助我們可以快速開啟專案原型不同模組不同的頁面。 三、部件型別 系統預設部件型別分為:線框圖部件、流程圖部件。 四、母版的特點 可複用:一個母板可以同時新增

西門子PLC基本指令功能介紹

地址 基本 輸出 計數器 在線培訓 bit 行業 基礎 輸入 一、標準觸點 LD、A、O、LDN、AN、ON、 LD,取指令。表示一個與輸入母線相連的常開接點指令,即常開接點邏輯運算起始。 LDN,取反指令。表示一個與輸入母線相連的常閉接點指令,即常閉接點邏輯運算起始。

Kubernets主要功能介紹基本物件以及系統架構和元件功能

Kubernets主要功能 資料卷:     Pod中容器之間共享資料,可以使用資料卷; 應用程式件健康檢查:     容器內服務可能程序堵塞無法處理請求,可以設定監控檢查策略保證應用健壯性; 複製應用程式例項:     控制器維護者Pod副本數量,保證一個Pod或者

Osmdroid覆蓋物新增API功能介紹----基本功能

Osmdroid覆蓋物新增API功能介紹—基本功能 https://github.com/osmdroid/osmdroid 基本應用 Osmdroid通過MapView的getOverlays()方法獲取所有的覆蓋物集合,然後通過add()方法新增到地圖上面。

Unity攝像機緩動功能的實現

  Unity中攝像機的緩動功能是非常容易實現的,主要用到Vector3 Lerp(Vector3 a, Vector3 b, float t); public class MainCameraCtr : MonoBehaviour { public Transform play

RaceWeb介紹(1):基本功能

RaceWeb軟體主要用於對資料進行快速操作及WEB展示。資料庫目前可以使用firebird、sqlite、sqlserver、oracle,未來將設定為支援所有常見資料庫型別。Web伺服器使用A

Unity邏輯程式碼開發介紹_攝像機平滑旋轉並限定角度四元數方式

開發FPS的遊戲時,涉及的相機的平滑旋轉,下面是我採用四元數的方式,並且限定旋轉上下限: public float XSensitivity = 2f; public int MinimumX = -30;   public int MaximumX = 30;

Unity中的指令碼啟動和關閉功能介紹!!!

在unity中所有的gameobject都是擁有狀態的,一種是啟用狀態一種是停用狀態,那麼我們同樣可以通過這個狀態來做不同的事情,腳本里面我們需要這麼寫呢?其實很簡單,只要重寫兩個方法: 1 2 3 4 5 6 7 void OnEnable()

藍芽API介紹基本功能實現

本文已授權微信公眾號fanfan程式媛獨家釋出 ONE,傳統藍芽 BluetoothAdapter:本地藍芽裝置介面卡,用於管理藍芽的開啟/關閉、重新命名、掃描、配對、連線BluetoothClass:藍芽裝置類,用於描述藍芽裝置型別BluetoothDevice:遠端

Unity中國象棋(五)——網路對戰的實現(服務端的基本功能

博主主要是用了socket的方法去實現了伺服器和客戶端之間的通訊,由於樓主對於socket網路程式設計這一方面的基礎相當薄弱,故也是邊學邊學,有些地方的程式碼不夠完善還請大神指正!博主還需學習。 首先,先說說服務端方面:服務端採用的是VS的windows form窗體應用

PyQt4 模擬記事本基本功能(保存,打開文件)

int .sh idt img 問題 top 我們 文件 pyqt 1. 默認【保存】按鈕enable 2. 修改文本的內容後,【enable】 3. 解決字符亂碼問題:utf-8 # -*- coding: utf-8 -*- import sys from PyQt

Kafka 0.11版本新功能介紹 —— 空消費組延時rebalance

次數 新功能 ins 效果 可控 size style soft font   在0.11之前的版本中,多個consumer實例加入到一個空消費組將導致多次的rebalance,這是由於每個consumer instance啟動的時間不可控,很有可能超出coordinato

Spring基本功能詳解

tex factor oid out 負責 sch bsp 初始化 pub 一、SpringIOC   Spring的控制反轉:把對象的創建,初始化,銷毀的過程交給SpringIOC容器來做,由Spring容器控制對象的生命周期。   1.1 啟動Spring容器的方式:

redis3.0 cluster功能介紹

jpeg 標識符 rms 代理 更新數據 bitmap 查詢 c51 想要 edis從3.0開始支持集群功能。redis集群采用無中心節點方式實現,無需proxy代理,客戶端直接與redis集群的每個節點連接,根據同樣的hash算法計算出key對應的slot,然後直接在sl

shell-3.bash的基本功能

cnblogs image ash com .com 基本功 分享 bsp ima shell-3.bash的基本功能

JavaWeb網上圖書商城完整項目--day03-1.圖書模塊功能介紹及相關類創建

class default package ren 書籍 logs main java getc 1 前兩天我們學習了user用戶模塊和圖書的分類模塊,接下來我們學習圖書模塊 圖書模塊的功能主要是下面的功能: 2 接下來我們創建對應的包 我們來看看對應的數據庫表t_bo