Unity3d 获取屏幕depth与normal

Depth

获取Depth的几种方法,分别有不同效果

1.

 
  1. <span style="font-size:14px;">            float2 depth_uv = float2(i.uv_MainTex.x, 1-i.uv_MainTex.y);  
  2.             float d = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, depth_uv);</span>  


2.

 
  1. <span style="font-size:14px;">                float zx = SAMPLE_DEPTH_TEXTURE_LOD(_CameraDepthTexture, float4(depth_uv, 0, 0));  
  2.                 zx = Linear01Depth(zx);</span>  


3.

 
  1. <span style="font-size:14px;">        v2f vert(appdata_full v) {  
  2.             v2f o;  
  3.             o.pos = mul(UNITY_MATRIX_MVP, v.vertex);  
  4.                         o.screen = ComputeScreenPos(o.pos);  
  5.                         COMPUTE_EYEDEPTH(o.screen.z);  
  6.             o.uv_MainTex = TRANSFORM_TEX(v.texcoord, _MainTex);  
  7.             return o;  
  8.         }</span>  



  1. <span style="font-size:14px;">            float d2 = SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.screen));  
  2.             d2 = LinearEyeDepth(d2);</span>  


4.

 
  1. <span style="font-size:14px;">            float3 normalValues;  
  2.             float depthValue;  
  3.             DecodeDepthNormal(tex2D(_CameraDepthNormalsTexture, i.screen.xy), depthValue, normalValues);</span>  

CameraDepthNormalsTexture没有显示,不知道是代码有问题还是unity有问题,unity4与5都试了,都没有值。

CameraDepthNormalsTexture  可以获取Normals和Depth


Normal

 
  1. <span style="font-size:14px;">tex2D(_CameraNormalsTexture, i.uv_MainTex);</span>  



                                      ---- by wolf96

posted @ 2015-06-07 08:01  战狼96  阅读(4280)  评论(0编辑  收藏  举报