Greetings:

Question: What is the range of gl_FragCoord.z (frag depth) and which end is closest/farthest from the eye?

Thanks,

Sam

hi sam,

the fragCoord is a strange vec3.

in the x and y it holds the window coords and in the z it holds the depth information from 0 to 1

where 1 is the most distance point in the szene and 0 is just the camera lens surface.

cu

uwi

The limits are as set by glDepthRange(). In the initial state (equivalent to glDepthRange(0,1)), the range is 0 to 1 with 0 at the near plane and 1 at the far plane. glDepthRange() clamps its inputs to the range [0,1], so you will never encounter values outside of that range. However, there’s no requirement that the near-plane value is less than the far-plane value; it is possible to reverse them.

gl_FragCoord.z is the value which is written to the depth buffer (after conversion to fixed point where applicable) if the fragment shader doesn’t write to gl_FragDepth.