   World Space to Z-Buffer
  Hi,So, I'm making a GPU raycaster for volume rendering, and I'd like it to output the final depth of the fragment for completely opaque substances.  Given the distance traveled in the world space, I need to convert it to z-buffer space so that it can be added to gl_FragCoord.z and output to gl_FragDepth.What is the conversion formula for converting thus?Help?  Thanks,Ian   
  This might help:http://en.wikipedia.org/wiki/Z-buffering#Mathematics   ;  That link provides exactly what I need--thanks!It's still not working, but I think I know the problem.  The depth is being read from a cubic depthmap.  Right now the shader function is:float cubemap_depthtest(samplerCube cubetex, vec3 center, float near, float far) {    vec3 lightdir = vec4(transform_matrix*vertex).xyz - center;    float distance = length(lightdir);    distance = ((far+near)/(far-near)) + (1.0/distance)*((-2.0*far*near)/(far-near));    distance = (distance+1.0)/2.0;   float shaddepth = textureCube(cubetex,normalize(lightdir)).r;    return distance-shaddepth;}The shader outputs the difference in depths between the actual depth "distance" and the depthmap "shaddepth".  The difference is 0 in the center of each view.  The difference increases further away.  I'm almost certain this is due to lines 2 and 3:vec3 lightdir = vec4(transform_matrix*vertex).xyz - center;float distance = length(lightdir);These lines are wrong because the plane the shadows were rendered to is not a sphere with center "center" = the camera position, but an actual plane.  Thus, the distance measured is actually too much, and so the difference increases.I don't know how to correct for this though.  Help?Thanks,-G   