unity中camera怎么生成使用深度图 Camera Depth Texture 实现Image Effect

来源:互联网 发布:手机免费sip软件 编辑:程序博客网 时间:2024/05/22 10:57

看了看景深的源码,然后在文档中找到


DepthTextureMode.Depth

Description

Generate a depth texture.

Will generate a screen-space depth texture as seen from this camera.Texture will be in RenderTextureFormat.Depth format and will be set as_CameraDepthTexture  global  shader property.

See Also: Camera.depthTextureMode.


景深源码DepthOfField34.shader 中有定义和使用:

。。。。

sampler2D _CameraDepthTexture;

。。。。。

float d = UNITY_SAMPLE_DEPTH ( tex2D (_CameraDepthTexturei.uv1.xy) );

。。。。

这个CameraDepthTexture是unity内部隐藏的,当源码DepthOfField34.js中

function OnEnable() {
        camera.depthTextureMode |= DepthTextureMode.Depth;        
    }

那么camera就会生成深度图了。直接用这个内部的就行。

0 0
原创粉丝点击