I am making a raytracer using GLSL.
I have it working but the zbuffer is not working correctly.
I believe it is because I dont know exaclty what is expected for gl_position.w.

I currently set it to :

----------------------------------------------------
attribute vec4 position;//vertex position into vertex shader
...
gl_position.w = -1.0/position.z;
----------------------------------------------------

What should it be?
I have read several transform tutorials, but they never explain how to calculate gl_position.w directly.
Please help!
thanks