Depth Texture has completely confused me

Godot Version

v4.2.1.stable.official [b09f793f5]

Question

I just need help understanding what is happening with the depth texture. I’ve been crawling the internet and looking at every resource I can find for literally 5 days and am no less lost than when I started. This post might get long. The big questions:

  1. The whole reason I started learning about depth texture is just because I want to detect the edges of an object to create ripples in the water. Is there any other way to do this?

  2. When you get the depth texture of a fragment, what is it even returning? Is it a float? A vec3? What kind of range can this value have?

  3. What are the uses of the depth texture besides making things disappear as they go deeper underwater?

  4. From what I understand, the depth texture gives you the distance from the camera to the fragment. How do the water shaders instead get the distance between the first fragment and the fragment behind it instead?

  5. in the tutorial below there’s a line:
    float depth = PROJECTION_MATRIX[3][2] / (depth_texture + PROJECTION_MATRIX[2][2]);

How am I supposed to know what to put in those square brackets after PROJECTION_MATRIX? What does any of that mean?

  1. If you have any tutorials or reading which will help me wrap my mind around this I will really appreciate it.

Details of my journey so far (I’m not sure if it’s important but here it is):

I’ve spent most of my time with this tutorial: https://www.youtube.com/watch?v=7L6ZUYj1hs8

Which I can’t get working after following the tutorial and double checking my work. On godotshaders.com i found the shader from the tutorial Water Shader - Godot Shaders but this also didnt work when I pasted it into my scene.

I also watched this video which kind of made sense https://www.youtube.com/watch?v=x1dIJdz8Uj8 , but again this video is trying to get camera to fragment, but what about the distance between a fragment and a fragment behind it?

I watched another video explaining about matrixs and stuff but that didnt help me at all, it confused me more than anything and didnt seem to have too much to do with using the actual depth_texture.

Anyway thanks for reading this far. I hope I can get pointed in the right direction.

Cant resolve your confusion at once, but i guess one
source of it, is your assumption number 4, where you
relate the depth texture to the distance of the vertex
interpreted by the current fragment, to the camera.

That is wrong: the depth texture (after linearisation)
relates/expresses the distance between the current
shader fragment to the next (mesh)-obstacle underneath it, if there is one,
in the extension of the direct line (VIEW) from
the camera plane.

so it more relates to what is underneath what the camera
sees, than what is the distance to your camera.

I think the camera distance from currently processed fragment
(as obtained in fragment shader) is abs(VIEW.z) or something like that.