博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用Depth Texture
阅读量:7097 次
发布时间:2019-06-28

本文共 1801 字,大约阅读时间需要 6 分钟。

使用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的范围。

 

转载地址:http://bwoql.baihongyu.com/

你可能感兴趣的文章
195. 安装solr服务器
查看>>
一个完整的 Web 请求到底发生了什么
查看>>
三星8.0系统设备最完美激活xposed框架的方法
查看>>
云计算的未来是自动化
查看>>
科略教育:三个层次说战略
查看>>
nginx 502错误
查看>>
VS2013环境下Boost库配置
查看>>
F5多出口配置
查看>>
Android Studio 第六十二期 - Android框架
查看>>
PCIE hotplug 调试小结
查看>>
我的友情链接
查看>>
对Hibernate完成持久化的认识及总结
查看>>
Windows phone8 基础篇(三)常用控件(一)
查看>>
leetCode 299. Bulls and Cows 哈希
查看>>
编译安装Redis Stable最新版本
查看>>
CnetOS启动流程
查看>>
LVM扩缩--lvm缩小swap,根分区在线扩容
查看>>
C++模板学习
查看>>
我的php学习笔记:php通用采集程序
查看>>
Ruby-数字&字符串
查看>>