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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM