Unity3d 获取屏幕depth与normal

Depth

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

1.

			float2 depth_uv = float2(i.uv_MainTex.x, 1-i.uv_MainTex.y);
			float d = SAMPLE_DEPTH_TEXTURE(_CameraDepthTexture, depth_uv);

Unity3d 获取屏幕depth与normal_第1张图片

2.

				float zx = SAMPLE_DEPTH_TEXTURE_LOD(_CameraDepthTexture, float4(depth_uv, 0, 0));
				zx = Linear01Depth(zx);
Unity3d 获取屏幕depth与normal_第2张图片
3.
		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;
		}


			float d2 = SAMPLE_DEPTH_TEXTURE_PROJ(_CameraDepthTexture, UNITY_PROJ_COORD(i.screen));
			d2 = LinearEyeDepth(d2);
Unity3d 获取屏幕depth与normal_第3张图片


4.

			float3 normalValues;
			float depthValue;
			DecodeDepthNormal(tex2D(_CameraDepthNormalsTexture, i.screen.xy), depthValue, normalValues);

需要在脚本中做如下代码

     camera.depthTextureMode = DepthTextureMode.DepthNormals;


CameraDepthNormalsTexture  可以获取Normals和Depth


Normal

tex2D(_CameraNormalsTexture, i.uv_MainTex);
Unity3d 获取屏幕depth与normal_第4张图片

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


你可能感兴趣的:(Unity3D,Shader,unity3d,shader实战练习,shader,图形学)