Quite a while ago, when I started out writing custom shaders for Unity's build-in Physics based renderer, I wrote an article on how to enable to Depth Buffer. I have since them switched over to Unity's Universal Render Pipeline so a refresher in how to enable the depth buffer might be needed, as its disabled by default.

What is the depth buffer?

In modern game development, a renderer sometimes uses a depth buffer (also called a Z-buffer) to store the distance from the camera a certain pixel was rendered. This buffer can be very useful to have when creating custom shader effect for Unity.

Enable the depth buffer in the URP asset.

In Unity's scriptable Render pipelines (URP and HDRP as well as custom implementation), the render pipeline is saved as an asset in your project.

The first step is to find the Pipeline asset used.

In Unity, open Edit -> Project Settings. Select the Graphics options.

The first line will show the Scriptable Render Pipeline Asset.

Click on this asset and it will take you to its location in the project view. Click the asset and it will be displayed in the inspector.

One of the first options is the Depth Buffer, being disabled by default.

Click to enable it and save the asset. Congratulations, you are done!