Unity3D翻译——Using Depth Textures

Using Depth Textures       使用深度纹理

原文地址:http://unity3d.com/support/documentation/Components/SL-DepthTextures.html

如有翻译不当之处,还请帮忙指出!

 

Desktop 台式机

 

It is possible to create Render Textures where each pixel contains a high precision "depth" value (see RenderTextureFormat.Depth). This is mostly used when some effects need scene's depth to be available (for example, soft particles, screen space ambient occlusion, translucency would all need scene's depth).

可以创建一种渲染纹理,其中每个像素都包含一个高精度的"深度"(见 RenderTextureFormat.Depth)。这主要是用于一些需要场景深度信息的特效制作中(例如软粒子、屏幕空间的环境遮挡,半透明的特效均需要场景的深度信息)。

Pixel values in the depth texture range from 0 to 1 with a nonlinear distribution. Precision is usually 24 or 16 bits, depending on depth buffer used. When reading from depth texture, a high precision value in 0..1 range is returned. If you need to get distance from the camera, or otherwise linear value, you should compute that manually.

深度纹理中每个像素所记录的深度值是从0 1 非线性分布的。精度通常是 24 位或16 位,这主要取决于所使用的深度缓冲区。当读取深度纹理时,我们可以得到一个0-1范围内的高精度值。如果你需要获取到达相机的距离或者其他线性关系的值,那么你需要手动计算它。

Depth textures in Unity are implemented differently on different platforms.

Unity中的深度纹理在不同的平台上所执行的机制也是不尽相同的:

*       On Direct3D 9 (Windows), depth texture is either a native depth buffer, or a single channel 32 bit floating point texture ("R32F" Direct3D format).

*       Direct3D 9 (Windows)中,深度纹理不仅是一个深度缓存,也是一个32位浮点纹理通道("R32F" Direct3D 格式).

·         Graphics card must support either native depth buffer (INTZ format) or floating point render textures in order for them to work.

·         为了让它们正常工作,显卡必须支持深度缓存(INTZ格式)或浮点型的渲染纹理。

·         When rendering into the depth texture, fragment program must output the value needed.

·         当渲染到纹理时,片段程序必须能够输出需要的数值。

·         When reading from depth texture, red component of the color contains the high precision value.

·         当读取深度纹理时,颜色的红色部分包含高精度数值。

*       On OpenGL (Mac OS X), depth texture is the native OpenGL depth texture (see ARB_depth_texture).

*       OpenGL (Mac OS X)中,深度纹理是一个OpenGL深度纹理(见ARB_depth_texture

·         Graphics card must support OpenGL 1.4 or ARB_depth_texture extension.

·         显卡必须支持OpenGL 1.4或者ARB_depth_texture扩展包。

·         Depth texture corresponds to Z buffer contents that are rendered, it does not use the result from the fragment program.

·         深度纹理对应于Z缓冲区所渲染的内容,它并不使用片段程序所输出的结果。

 

Using depth texture helper macros    使用深度纹理帮助宏

Most of the time depth textures are used to render depth from the camera. UnityCG.cginc helper include file contains some macros to deal with the above complexity in this case:

大部分时间里,深度纹理都是用来渲染到达照相机的深度值。在此情况下,UnityCG.cginc 帮助器中的文件包含一些宏来应付上述情况:

*       UNITY_TRANSFER_DEPTH(o): computes eye space depth of the vertex and outputs it in o (which must be a float2). Use it in a vertex program when

          rendering into a depth texture. On OpenGL this macro does nothing at all, because Z buffer value is rendered implicitly.

          UNITY_TRANSFER_DEPTH(o)计算顶点在眼空间的深度,并输出到o(这必须是 float2类型)。当渲染到深度纹理时,在顶点程序中使用它。在

          OpenGL中,该宏不会起任何作用,因为Z 缓冲区的值是隐式地渲染出来的。

*       UNITY_OUTPUT_DEPTH(i): returns eye space depth from i (which must be a float2). Use it in a fragment program when rendering into a depth texture.

          On OpenGL this macro always returns zero, because Z buffer value is rendered implicitly.

*       UNITY_OUTPUT_DEPTH(i)返回在i中的眼空间深度(这必须是 float2类型)。当渲染到深度纹理时,在片段程序中使用它。在OpenGL中,该宏始终返回

         0,因为Z 缓冲区的值是隐式地渲染出来的。

*       COMPUTE_EYEDEPTH(i): computes eye space depth of the vertex and outputs it in o. Use it in a vertex program when not rendering into a depth

         texture.

*       COMPUTE_EYEDEPTH(i)计算顶点在眼空间的深度,并输出到o中。当不渲染到深度纹理时,在顶点程序中使用它。

*       DECODE_EYEDEPTH(i): given high precision value from depth texture i, returns corresponding eye space depth. This macro just returns i*FarPlane on

         Direct3D. On OpenGL it linearizes and expands the value to match camera's range.

*       DECODE_EYEDEPTH(i)对于深度纹理i中的高精度值,返回其相应的眼空间深度。该宏在Direct3D中仅仅返回i*FarPlane。在OpenGL,它线性化并扩展

         该值来匹配相机的范围。

For example, this shader would render depth of its objects:

举个例子,这个着色器将渲染物体的深度值:

 

Shader "Render Depth" {

SubShader {

    Tags { "RenderType"="Opaque" }

    Pass {

        Fog { Mode Off }

CGPROGRAM

#pragma vertex vert

#pragma fragment frag

#include "UnityCG.cginc"
struct v2f {

    float4 pos : SV_POSITION;

    float2 depth : TEXCOORD0;

};

 
v2f vert (appdata_base v) {

    v2f o;

    o.pos = mul (UNITY_MATRIX_MVP, v.vertex);

    UNITY_TRANSFER_DEPTH(o.depth);

    return o;

}


half4 frag(v2f i) : COLOR {

    UNITY_OUTPUT_DEPTH(i.depth);

}

ENDCG

    }

}

}


iOS

 

This feature is not supported for iOS targets.

该功能暂不支持iOS设备。

 

Android

 

This feature is not supported for Android targets.

该功能暂不支持Android设备。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
当学习Unity3D时,以下是一些重要的笔记: 1. Unity3D基础知识: - 游戏对象(Game Objects)和组件(Components):了解游戏对象的层次结构和组件的作用。 - 场景(Scenes)和摄像机(Cameras):学会如何创建场景并设置摄像机视角。 - 材质(Materials)和纹理(Textures):掌握如何创建和应用材质和纹理。 - 动画(Animations):学习如何创建和控制游戏对象的动画。 2. 脚本编程: - C#语言基础:了解C#语言的基本语法和面向对象编程概念。 - Unity脚本编写:学习如何编写脚本来控制游戏对象的行为和交互。 - 常见组件和功能:掌握常见的Unity组件和功能,如碰撞器(Colliders)、刚体(Rigidbodies)、触发器(Triggers)等。 3. 游戏开发流程: - 设计游戏关卡:了解如何设计游戏场景和关卡,包括布局、道具、敌人等。 - 游戏逻辑实现:将游戏规则和玩家交互转化为代码实现。 - UI界面设计:学习如何设计游戏中的用户界面,包括菜单、计分板等。 - 游戏优化和调试:优化游戏性能,解决常见的错误和问题。 4. 学习资源: - Unity官方文档和教程:官方提供了大量的文档和教程,逐步引导你学习Unity3D。 - 在线教程和视频教程:网上有很多免费和付费的Unity教程和视频教程,可根据自己的需求选择学习。 - 社区论坛和博客:加入Unity开发者社区,与其他开发者交流并获取帮助。 通过系统地学习这些内容,你将能够掌握Unity3D的基础知识并开始开发自己的游戏项目。记得不断实践和尝试,不断提升自己的技能!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值