Unity3d 擷取螢幕depth與normal,unity3ddepth

來源:互聯網
上載者:User

Unity3d 擷取螢幕depth與normal,unity3ddepth
Depth

擷取Depth的幾種方法,分別有不同效果

1.

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


2.

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

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


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


4.

<span style="font-size:14px;">float3 normalValues;float depthValue;DecodeDepthNormal(tex2D(_CameraDepthNormalsTexture, i.screen.xy), depthValue, normalValues);</span>
CameraDepthNormalsTexture沒有顯示,不知道是代碼有問題還是unity有問題,unity4與5都試了,都沒有值。

CameraDepthNormalsTexture  可以擷取Normals和Depth


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


                                      ---- by wolf96 http://blog.csdn.net/wolf96


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.