You can remove these lines:
float real_depth = texture(DEPTH_TEXTURE, SCREEN_UV).r * 2.0 - 1.0;
real_depth = PROJECTION_MATRIX[3][2] / (real_depth + PROJECTION_MATRIX[2][2]) + VERTEX.z;
// Get the raw linear depth from the depth texture into a [-1, 1] range
float depth = texture(DEPTH_TEXTURE, uv).r * 2.0 - 1.0;
// Recreate linear depth of the intersecting geometry using projection matrix, and subtract the vertex of the sphere
depth = PROJECTION_MATRIX[3][2] / (depth + PROJECTION_MATRIX[2][2]) + VERTEX.z;
Then call it like this:
float real_depth = getDepth(DEPTH_TEXTURE, SCREEN_UV);
float depth = getDepth(DEPTH_TEXTURE, uv);
z near and far are camera properties, you can define them at the top:
float z_near = 0.05;
float z_far = 100.0;
Those are the defaults for a Godot camera. If you didn't alter the camera, then you can leave them, it shouldn't matter much since they will be normalized.