I'm looking for a way to get the correct depth value in GLSL. I am rendering a cube and I am stepping inside that cube (it's a volume rendering application).
In the picture below

The blue dots should have a deeper z value than the red one. However, when I am displaying the value of z as a color, I am getting the same color at the blue (on the outside) as the red dot which is in front (meaning I am getting the same depth). I am trying with gl_FragCoord.z (and tried several others too). Does anyone have a suggestion what I could use.
Thanks


















