使用Depth Textures:
  可以将depth信息渲染到一张texture,有些效果的制作会需要scene depth信息,此时depth texture就可以派上用场了。
  Depth Texture在不同平台上有不同的实现,并且原生的支持也不一样。
  UnityCG.cginc里面定义了一些使用depth texture的帮助宏定义:
    UNITY_TRANSFER_DEPTH(o) 计算eye space的深度值,并写入变量o(float2)。当需要渲染到一张深度贴图时,在vertex shader中使用该函数。在原生就支持depth texture的平台上,该函数啥也不做,因为Z buffer的值会被渲染。
    UNITY_OUTPUT_DEPTH(i) 根据i(float2)返回eye space深度值。当需要渲染到一张深度贴图时,在fragment shader中使用该函数。在原生就支持depth texture的平台上,该函数总是返回0。
    COMPUTE_EYEDEPTH(i) 计算eye space的深度值。在vertex shader中使用,当不渲染到depth texture,而只是获取该值时使用。
    DECODE_EYEDEPTH(i) 从depth texture i中得到高精度的eye space depth。

    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
}
}
}

Camera's Depth Texture:
  Camera能够生成一张depth texture或者depth+normals texture。可以用来实现一些后处理效果或自定义的光照模式等。
  Depth Texture可以直接来自于depth buffer,或者是基于Shader Replacement特性的一个独立的pass来实现,所以也可以自己来做这件事。
  变量:Camera.depthTextureMode
  取值:
    DepthTextureMode.Depth:一张screen-sized的depth贴图。
    DepthTextureMode.DepthNormals:
      screen-sized 32 bit(8 bit/channel)texture,包含depth和view space normals信息。
      noramls存放在R和G通道,depth使用B和A通道。
  [UnityCG.cginc]DecodeDepthNormal(float4 enc, out float depth, out float3 normal)函数可以用来从pixel value中解码出depth和normal值,返回的depth为0..1的范围。

使用Depth Texture的更多相关文章

  1. Camera’s Depth Texture

    [Camera’s Depth Texture] In Unity a Camera can generate a depth or depth+normals texture. This is a ...

  2. depth and distance

    1down votefavorite   I'm implementing ominidirectional shadow mapping for point lights. I want to us ...

  3. Unity3D图像后处理特效——Depth of Field 3.4

    Depth of Field 3.4 is a common postprocessing effect that simulates the properties of a camera lens. ...

  4. A Simple OpenGL Shader Example II

    A Simple OpenGL Shader Example II eryar@163.com Abstract. The OpenGL Shading Language syntax comes f ...

  5. Tutorial - Deferred Rendering Shadow Mapping 转

    http://www.codinglabs.net/tutorial_opengl_deferred_rendering_shadow_mapping.aspx Tutorial - Deferred ...

  6. Shader预处理宏、内置状态变量、多版本编译等

    预定义shader预处理宏: Target platform: SHADER_API_OPENGL - desktop OpenGL SHADER_API_D3D9 - Direct3D SHADER ...

  7. u3d_Shader_effects笔记5 第二章 通过UV,进行纹理移动

    1.前面心情 公司最近打包,像我等小弟闲着,看代码容易困,没事偷着学shader,不过还是要多交流才行. 2.本文参考 这次参考比较多:由texture uv延伸问题多,主要是不明白变量定义: htt ...

  8. UnityShader快速上手指南(四)

    简介 由于其他项目中断了几天更新,继续~~ 这一篇主要是讲光照的(包含漫反射和高光以及多光源的处理) 还是先来看看具体效果(多光源后面单独展示) 有了基本的光照处理之后越来越有立体感了有不有 ╮(╯▽ ...

  9. [ZZ] Shadow Map

    Shadow Map 如何能够高效的产生更接近真实的阴影一直是视频游戏的一个很有挑战的工作,本文介绍目前所为人熟知的两种阴影技术之一的ShadowMap(阴影图)技术.     ShadowMap技术 ...

随机推荐

  1. 《Linux内核分析》期中总结

    两个月Linux内核的学习,让我理解了Linux内核的基本工作原理,包括进程管理.内存管理.设备驱动.文件系统,从分析内核到了解整个系统是如何工作的.如何控制管理资源分配.进程切换并执行.各种策略和结 ...

  2. [转]PowerDesigner设置集锦

    powerdesiner的自增长列,以前都是生成sql语句后,再在自增长列中添加Identity(1,1).找了好久,终于打到了方法. 1.如果dbms是MsSql,则选定表后,database-&g ...

  3. mottoes

    1. You don't kown if you can until a try. 2. Rule youself. 3. It's what you do in the dark that puts ...

  4. Spring Web

    Spring MVC的初始化: WEB容器加载后,通过使用DispatcherServlet拦截器加载IOC容器到WEB容器中,并通过ContextLoderListener将其初始化, 因为Spri ...

  5. idea中maven报错:无效的目标发行版: 1.8

    1.project.pom中修改版本 <maven.compiler.source>1.7</maven.compiler.source><maven.compiler. ...

  6. 强大的swift字符串

    Swift集百家之长,吸收了主流语言java,c,c++等的好的特性,所以它功能十分强大,今天我们就来看看它强大的字符串. 首先,我们带着这样几个问题去了解.理解swift的字符串. 1.swift字 ...

  7. SpringAOP代理报错问题

    public class BaseDataSyncPushJob implements StatefulJob{ /*** 日志 */ private static final Log LOG = L ...

  8. 在chrome下的文本框sendkeys,提示element can't focus--解决方法

    在chrome下的文本框sendkeys,提示element can't focus--解决方法(成都-半步流雲,群友解决) 成都-半步流雲1.升级你的chromedriver,2.降chrome版本 ...

  9. 头部加mead(便于seo优化)

    <meta name="Keywords" content="关键词,关键词" /> <meta name="description ...

  10. Android—LayoutInflater学习笔记

    LayoutInflater的的主要用处:使用LayoutInflater来载入界面,类似于findViewById()在Activity中加载Widget组件一样.区别在于与LayoutInflat ...