Camera's Depth Texture 照相机的深度纹理
原文地址:http://unity3d.com/support/documentation/Components/SL-CameraDepthTexture.html
如有翻译不当之处,还请帮忙指出!
Desktop 台式机
In Unity a Camera can generate a depth or depth+normals texture. This is a minimalistic G-buffer texture that can be used for post-processing effects or to implement custom lighting models (e.g. light pre-pass). Camera actually builds the depth texture using Shader Replacement feature, so it's entirely possible to do that yourself, in case you need a different G-buffer setup.
在Unity中,相机可以生成深度纹理或者深度+法线纹理。这是一个简化的G-buffer纹理,它可以用于一些后处理特效或者执行自定义的光照模式(例如light pre-pass)。照相机实际上使用着色器替换功能来生成深度纹理,因此当你需要一个不同的G-buffer设置时,你完全可以自己生成一个深度纹理。
Camera's depth texture can be turned on using Camera.depthTextureMode variable from script.
相机的深度纹理可以通过在脚本使用 Camera.depthTextureMode 变量来打开。
There are two possible depth texture modes:
目前有两种可能的深度纹理模式:
DepthTextureMode.Depth: a depth texture.
DepthTextureMode.Depth:一个深度纹理。
DepthTextureMode.DepthNormals: depth and view space normals packed into one texture.
DepthTextureMode.DepthNormals:将深度与视空间法线结合在一张纹理中。
DepthTextureMode.Depth texture
This builds a screen-sized depth texture.
这生成一个屏幕尺寸的深度纹理。
DepthTextureMode.DepthNormals texture
This builds a screen-sized 32 bit (8 bit/channel) texture, where view space normals are encoded into R&G channels, and depth is encoded in B&A channels. Normals are encoded using Stereographic projection, and depth is 16 bit value packed into two 8 bit channels.
这生成一个屏幕大小的32 位(8位/通道)纹理,这里视空间的法线记录在红蓝通道中,深度记录在蓝色和半透明通道中。法线使用平射投影,深度为16位数值,并被放进两个8位通道中。
UnityCG.cginc Cg include file has a helper function DecodeDepthNormal to decode depth and normal from the encoded pixel value. Returned depth is in 0..1 range.
UnityCG.cginc Cg包含文件中含有一个帮助函数DecodeDepthNormal,它可以用来从指定像素中编码深度与法线值,得到的深度值在0-1区间。
For examples on how to use the depth and normals texture, please refer to the EdgeDetection image effect in the Shader Replacement example project or SSAO Image Effect.
比如,如何使用深度法线纹理,请参考EdgeDetection着色器替换例子中图像特效或SSAO图像特效。
Tips & Tricks 提示&技巧
When implementing complex shaders or Image Effects, keep Rendering Differences Between Platforms in mind. In particular, using depth texture in an Image Effect often needs special handling on Direct3D + Anti-Aliasing.
当你编写复杂的着色器或图像特效时,要切记不同平台间的渲染差异特性。特别地,在开启反走样特效的Direct3D平台上,如果在图像特效中使用深度纹理需要一些特别的处理。
In some cases, the depth texture might come directly from the native Z buffer. If you see artifacts in your depth texture, make sure that the shaders that use it do not write into the Z buffer (use ZWrite Off).
在某些情况下,深度纹理本身就是Z缓存。如果你在你的深度纹理中看到了一些瑕疵(artifacts),请确保那些使用它的着色器不会重写Z缓存(使用ZWrite Off)
iOS
This feature is not supported for iOS targets.
该特性不支持iOS设备。
Android
This feature is not supported for Android targets.
该特性不支持Android设备。