Unity3d 获取屏幕depth与normal
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