查看: 4312|回复: 0
打印 上一主题 下一主题

[Unity 组件参考手册]着色器参考之高级ShaderLab主题:摄像机的深度纹理

[复制链接]
.    

3797

主题

11

听众

5万

积分

首席设计师

Rank: 8Rank: 8

纳金币
32328
精华
41

活跃会员 优秀版主 荣誉管理 论坛元老

跳转到指定楼层
楼主
发表于 2013-2-26 17:34:59 |只看该作者 |倒序浏览
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 textureThis builds a screen-sized depth texture.这是生成一个屏幕尺寸的深度纹理。
DepthTextureMode.DepthNormals textureThis 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)
Under the hood 在底层Depth texture can come directly from the actual depth buffer, or be rendered in a separate pass, depending on the rendering path used and the hardware. When the depth texture is rendered in a separate pass, this is done through Shader Replacement. Hence it is important to have correct "RenderType" tag in your shaders.深度纹理可以直接从深度缓冲器或在单独通道被渲染,取决于使用的渲染路径和硬件。当深度纹理在单独的通道渲染,是通过着色器替换来完成。因此,重要的是着色器有正确的“RenderType”标签。 【来源:互联网】
更多精彩教程,尽在web3D纳金网http://www.narkii.com/college/
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

手机版|纳金网 ( 闽ICP备2021016425号-2/3

GMT+8, 2024-11-18 19:59 , Processed in 0.118086 second(s), 33 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部