Unity Graphics (Unity 图形渲染 )
- Everything for Lighting and Rendering in Unity
- 主要涉及到光照与渲染方面的知识
本文档主要是对Unity官方教程的个人理解与总结(其实以翻译记录为主:>)
仅作为个人学习使用,不得作为商业用途,欢迎转载,并请注明出处。
文章中涉及到的操作都是基于 Unity2018.3版本
参考链接:https://unity3d.com/cn/learn/tutorials/s/graphics
下面是将要介绍的章节,黑体是本次内容:
5.Choosing a Color Space
In addition to selecting a rendering path, it’s important to choose a ‘Color Space’ before lighting your project. Color Space determines the maths used by Unity when mixing colors in lighting calculations or reading values from textures. This can have a drastic effect on the realism of your game, but in many cases the decision over which Color Space to use will likely be forced by the hardware limitations of your target platform.
除了选择渲染路径,选择颜色空间在项目光照设计之前也是很重要的。颜色空间决定了Unity在光照计算时颜色混合或从贴图读取数值时的数学计算。这会对游戏真实感产生巨大的影响,但更多时候决定使用哪个颜色空间,取决于你的目标平台硬件的限制。
Linear Color Space
线性颜色空间
The preferred Color Space for realistic rendering is Linear. This can be selected using the ‘Color Space’ property from (Edit>Project Settings>Player).
写实感渲染的颜色空间推荐线性。可以从(【Edit>Project Settings>Player】)上的【Color Space】属性选择。
A significant advantage of using Linear space is that the colors supplied to shaders within your scene will brighten linearly as light intensities increase. With the alternative, ‘Gamma’ Color Space, brightness will quickly begin to turn to white as values go up, which is detrimental to image quality.
用线性空间的重大优势是着色器颜色值随着光照强度提高将线性增强亮度。相反,“Gamma”颜色空间随着值升高则更快地变白色,这不利于图像的质量。
Image comparing objects lit using Linear and Gamma Color Space. Notice how colors quickly turn to white as light intensities increase using the Gamma Color Space.
对象用于线性和Gamma颜色空间的图像比较。注意到随着光照强度提高,Gamma颜色空间的颜色更快地变成白色。
Another main benefit of Linear is that shaders can also sample textures without Gamma (midtone) compensation. This helps to ensure that color values remain consistent throughout their journey through the render pipeline. The result is increased accuracy in color calculations with improved overall realism in the eventual screen output.
另外,线性的主要优势在于着色器也可以没有Gamma(色调)补偿地采样贴图。这有助于确保在整个渲染管道过程中,颜色值始终保持一致。结果是,在最终的屏幕输出中,颜色计算的准确性提高了。
Gamma Color Space
伽马(Gamma )颜色空间
Unfortunately Linear Color Space is not supported by some mobile hardware and even certain games consoles. In these instances, Gamma must be used instead. Linear is currently supported on PC, newer mobile hardware and current generation consoles.
不幸的是线性颜色空间并不被一些移动硬件甚至某些游戏主机支持。这样情况下,只能选择Gamma。线性当前被PC支持,比较新的移动设备和当前一般游戏主机也可以支持。
It’s important to confirm that your target platform supports your selected Color Space before proceeding.
For more information on Color Space please see the documentation here.
如果你选择使用线性颜色空间,你的目标平台是否支持是需要在使用前确认一下的。
更多的颜色空间信息见这里的文档。
6.High Dynamic Range (HDR)
As well as Color Space, the ‘dynamic range’ of your camera needs to be configured. Essentially, this defines how extremely bright or dark colors are captured by scene cameras. HDR can be enabled from the camera component in the Inspector by using the HDR checkbox. Note that HDR is unsupported by some mobile hardware. It is also not supported in Forward Rendering when using techniques such as multi-sample anti-aliasing (MSAA).
像颜色空间一样,相机的动态范围也需要设置。从本质上来说,它定义了场景相机能捕捉到的光亮或黑暗颜色的程度。HDR也可以从属性面板的相机组件勾选。注意在一些手机硬件上HDR并不支持。如果在正向渲染下使用了多重采样抗锯齿(MSAA)等技术,HDR也将不被支持(注:新版本已支持)。
HDR is best used in combination with Linear Color Space in order to preserve accuracy when handling very bright colors.
当处理非常明亮的颜色值时,HDR最好和线性颜色空间相结合以保持精度。
By default, cameras in Unity use a Low Dynamic Range (LDR). Colors are stored using 8-bits per channel - red, green and blue. 8-bits refers to the ‘precision’ and means that color data is stored with 8 values of either 1 or 0, giving 256 possible unique combinations for each color channel. 256 x 256 x 256 colors per channel means that by storing values using 8-bits we are able to uniquely reference over 16 million color variations ranging in intensity from black to white.
默认,Unity的相机使用一个低动态范围(LDR)。颜色用红绿蓝每通道8位的方式存储。8位表示“精度”,并且表示单个通道的颜色值被存储8个1/0值,有256种。单个通道存储了8位,我们从黑到白能单独引用256256256颜色值,1600万颜色组合范围强度。
In reality, colors in the real world extend far outside this 16 million color range. There are infinite permutations of color possibilities, and brightness goes beyond what our eyes can even see. Similarly Unity is capable of handling extremely bright lights which produce colors beyond that which can be displayed on an LDR device such as your computer screen. However, despite this potential limitation in the output device, these extreme light values still remain useful to us in a number of applications.
事实上,颜色在真实世界远远超过1600万种颜色范围。有无限种颜色排列的可能性,并且明亮度也超过人类眼睛能看的范围。类似地,Unity能够处理极端明亮的光照,这些光照可以在LDR设备上显示,比如电脑屏幕。然而,尽管在输出设备上存在潜在的限制,但是这些极端的光值仍然对我们在许多应用程序中有用。
By enabling HDR on your scene camera, colors will be stored with much greater precision (using the floating point representation). Many more unique colors over a much brighter range of luminance can be handled.
在场景相机上开启HDR,颜色将被存储更高的精度(用浮点型表示)。很多更明亮的颜色能够用惟一颜色值表示。
HDR enables us to preserve the great differences in brightness between, say, outdoor lighting in our scenes and shaded areas. We can also create effects like ‘blooms’ or glows by applying effects to these bright colors in your scene. Special effects like these can add realism to particles or other visible light sources. However, these extreme color values also need to be handled somehow to prevent them being ‘clamped’ to white.
HDR可以使我们保持明亮度的更大区分,比如说室外场景和荫蔽的区域。我们还可以创建像“泛光”或辉光通过在场景中应用明亮颜色效果。像这样的特殊效果可以增加粒子或其他可见光源的真实感。然而,这些极端的颜色值也需要被处理,以防止它们被“夹取”到白色。
Tonemapping
色调映射
Using the analogy of photography, if we were to photograph our scene using different exposure settings, then we could start to see these extreme color details which otherwise might have been lost. Light tones in the brightest areas of the image which have been lost to white can be recovered, or dark tones lost to black. This is analogous to ‘tonemapping’ in computer graphics, where we take colors outside of the range reproducible by our target device (computer screen, for example) and shift them mathematically into a range which can be reproduced. The resulting output still makes sense perceptually, because colors remain relative to one another. They are correct in context.
用摄影类推,如果我们用不同的曝光设置来拍摄我们的场景,那么我们就可以看到这些极端的颜色细节,否则可能会丢失。在图像的最明亮区域光的色调白色的丢失能够被恢复,黑色的丢失颜色值也能够被恢复。在计算机图形学中这类似于“色调映射”,把超出我们目标设备可复制的颜色值(比如,计算机屏幕)通过数学计算变换到可显示的区域。输出结果仍然在视觉上是合乎情理的,因为颜色值之间仍保持着相对亮度,所以显示还是正确的。
When using HDR cameras, the Tonemapping Image Effect from Standard Assets (Assets>Import Package>Effects) must be added to the camera. This script provides you control over how very bright color intensities recorded by your camera are converted into colors which can be displayed.
当使用HDR相机时,从标准资产获取的色调映射后期效果一定要加到相机上。脚本可以让你控制相机记录的明亮的颜色强度转换成可显示的颜色。
More information on Tonemapping can be found here.
更多的色调映射信息见这里的文档。