I was using DepthPyramidTexture to get the scene depth in Unity 2019.2 and this texture is no longer recognized by the new HDRP and Unity.
Is there a way to get the depth without using the shadergraph libraries, since i do not need them besides only the depth texture.
Also is there still the DepthPyramidTexture or was removed ?
Thanks
nasos_333:
I was using DepthPyramidTexture to get the scene depth in Unity 2019.2 and this texture is no longer recognized by the new HDRP and Unity.
Is there a way to get the depth without using the shadergraph libraries, since i do not need them besides only the depth texture.
Also is there still the DepthPyramidTexture or was removed ?
Thanks
Hello,
Thanks unity, they just remove “sampler2D _CameraDepthTexture” and “sampler2D DepthPyramidTexture” and right now it’s should be declared as arrays. And it doesn’t say anywhere =/
For old language CG you need use this code right now.
UNITY_DECLARE_TEX2DARRAY(_CameraDepthTexture);
float4 _DepthPyramidScale;
UNITY_DECLARE_TEX2DARRAY(_ColorPyramidTexture);
//vertex
o.projPos = ComputeScreenPos(o.vertex);
o.projPos.xy *= _DepthPyramidScale.xy;
COMPUTE_EYEDEPTH(o.projPos.z);
o.uvgrab = ComputeGrabScreenPos(o.vertex);
//frag
float sceneZ = LinearEyeDepth(UNITY_SAMPLE_TEX2DARRAY_LOD(_CameraDepthTexture, float4(i.projPos.xy / i.projPos.w, 0, 0), 0));
half4 grabColor = UNITY_SAMPLE_TEX2DARRAY_LOD(_ColorPyramidTexture, float4(i.uvgrab.xy / i.uvgrab.w, 0, 0), 0);
2 Likes
kripto289:
Hello,
Thanks unity, they just remove “sampler2D _CameraDepthTexture” and “sampler2D DepthPyramidTexture” and right now it’s should be declared as arrays. And it doesn’t say anywhere =/
For old language CG you need use this code right now.
UNITY_DECLARE_TEX2DARRAY(_CameraDepthTexture);
float4 _DepthPyramidScale;
UNITY_DECLARE_TEX2DARRAY(_ColorPyramidTexture);
//vertex
o.projPos = ComputeScreenPos(o.vertex);
o.projPos.xy *= _DepthPyramidScale.xy;
COMPUTE_EYEDEPTH(o.projPos.z);
o.uvgrab = ComputeGrabScreenPos(o.vertex);
//frag
float sceneZ = LinearEyeDepth(UNITY_SAMPLE_TEX2DARRAY_LOD(_CameraDepthTexture, float4(i.projPos.xy / i.projPos.w, 0, 0), 0));
half4 grabColor = UNITY_SAMPLE_TEX2DARRAY_LOD(_ColorPyramidTexture, float4(i.uvgrab.xy / i.uvgrab.w, 0, 0), 0);
Thanks a lot for the insight !!!
I will start working with those and see if can get the same result as in 2019.2.
kripto289:
Hello,
Thanks unity, they just remove “sampler2D _CameraDepthTexture” and “sampler2D DepthPyramidTexture” and right now it’s should be declared as arrays. And it doesn’t say anywhere =/
For old language CG you need use this code right now.
UNITY_DECLARE_TEX2DARRAY(_CameraDepthTexture);
float4 _DepthPyramidScale;
UNITY_DECLARE_TEX2DARRAY(_ColorPyramidTexture);
//vertex
o.projPos = ComputeScreenPos(o.vertex);
o.projPos.xy *= _DepthPyramidScale.xy;
COMPUTE_EYEDEPTH(o.projPos.z);
o.uvgrab = ComputeGrabScreenPos(o.vertex);
//frag
float sceneZ = LinearEyeDepth(UNITY_SAMPLE_TEX2DARRAY_LOD(_CameraDepthTexture, float4(i.projPos.xy / i.projPos.w, 0, 0), 0));
half4 grabColor = UNITY_SAMPLE_TEX2DARRAY_LOD(_ColorPyramidTexture, float4(i.uvgrab.xy / i.uvgrab.w, 0, 0), 0);
Thank you for this. It took me 3 days but im finally sampling depth in HDRP, i still got one problem though. this does not seem to sample it per pixel, once the camera looks into the sky the screen is completely white and if it looks at the edge of something the screen is a dark gray(depending on the distance obviously).